4

So i have an object which is getting rotated then translated and rotated again. I am storing a matrix of these translations as an object member. Now when i come to object picking i need to know the 3D world coords of this object.

Currently i have been able to get the position of the object like so

coords[0] = finalMatrix[12];

coords[1] = finalMatrix[13];

coords[2] = finalMatrix[14];

This is giving me the correct positions of the objects but i want to take the rotations into account as well.

Any help would be great...

Stoff81
  • 597
  • 4
  • 15
  • There was a OpenGL picking (and selection) tutorial for version 1.2 or so. They recommended special render mode in which every object received it's unique color - which was interpreted as an object identificator. Following this approach you wouldn't need to know the rotations whatsoever. – Rekin Jan 25 '11 at 09:29
  • thx Rekin.. i know what im doing is not the most optimal way of doing stuff. Im just using this oportunity to learn more about matrices and rotation etc. do you have a link for this picking tut? im using opengl es so ive had to do work arounds for things which arnt available in standard GL. thx – Stoff81 Jan 25 '11 at 10:02
  • I thought it won't be of many help for You - that's why I didn't post it as an answer - just a hint. And the link is: http://www.lighthouse3d.com/opengl/picking/ – Rekin Jan 26 '11 at 09:56
  • yeah that wont work on es i dont think but thanks anyway! – Stoff81 Jan 26 '11 at 10:46

3 Answers3

2

The matrix is a 4x4 matrix, but as you've just got a single dimensional matrix it appears that the elements are arranged as follows:

[0]  [4]  [8]   [12]
[1]  [5]  [9]   [13]
[2]  [6]  [10]  [14]
[3]  [7]  [11]  [15]

The rotation part is the top left 3x3 matrix see here, so in your case it would be elements [0]-[2], [4]-[6] and [8]-[10]

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • @Stoff81 - I'm not sure I understand your question. What are you actually trying to achieve? – ChrisF Jan 25 '11 at 10:02
  • I want coords to be the 3D coords of this object. I have done all the translations of the object and have saved the matrix in finalMatrix. So i want to get the position of the object out of finalMatrix. I dont know how to be any clearer. thx – Stoff81 Jan 25 '11 at 10:10
  • @Stoff81 - the values `[12]-[14]` give you the position - as you identified in your question - how does getting the rotation change things? – ChrisF Jan 25 '11 at 10:12
  • hmm uve confused me lol... its just when i start rotating/moving my objects, then the picking doesnt work anymore, so i started to think that i needed to take rotations into account. – Stoff81 Jan 25 '11 at 10:17
  • @Stoff81 - I understand now. Yes you do need to take the rotations into account - however, my explanatory powers are failing me. I can only suggest that you read the page I linked to and search for other tutorials. They should (hopefully) make it clearer. – ChrisF Jan 25 '11 at 10:21
  • thx again Chris. another thing that i have tried is using a transform_point(GLfloat outVector[4], const Matrix3D m, const GLfloat inVector[4] method, should this work? it is doing the samething as the bottom of the link u posted, just for multiplying a 4x4 and a 1x4 – Stoff81 Jan 25 '11 at 10:24
  • @Stoff81 - it looks like it - though you might need the inverse of the matrix. I could never remember ;) – ChrisF Jan 25 '11 at 10:26
2

http://www.euclideanspace.com/maths/geometry/affine/matrix4x4/index.htm - here is the explanation how the 4x4 matrices work. The first minor 3x3 - is a rotation matrix. The last column except last element is a translation vector. And element[4, 4] is a scale factor. Read more about this at the link

Andrew
  • 24,218
  • 13
  • 61
  • 90
2

So I am an idiot... i had it correct in the first place. All i needed was the position data in [12][13][14]. I had a couple stupid bugs in my code, one of which was not having enough iterations on my ray intersection...All sorted now lol im kicking myself..haha thanks anyway guys!!

Stoff81
  • 597
  • 4
  • 15