Given a 4x4 homogeneous matrix, how can i get 3D world coords?

Stoff81 picture Stoff81 · Jan 25, 2011 · Viewed 8.2k times · Source

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...

Answer

ChrisF picture ChrisF · Jan 25, 2011

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]