Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I understand that a 4x4 matrix holds rotation and position data.

The rotation data is held in the 3x3 sub-matrix at the top left of the matrix.

The position data is held in the last column of the matrix.


glm::vec3 vParentPos(

My question is - am I accessing the parent matrix correctly in the example above? I know that opengl uses a different matrix ordering that directx, (row order instead of column order or something), so, should the mParent be accessed as follows instead?

glm::vec3 vParentPos(


share|improve this question

1 Answer 1

up vote 5 down vote accepted

Your first method is the correct one. According to the OpenGL FAQ:

The translation components occupy the 13th, 14th, and 15th elements of the 16-element matrix

It can also be seen in the glm source code (from matrix_transform.inl):

inline detail::tmat4x4<T> translate
    detail::tmat4x4<T> Result(m);
    Result[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3];
    return Result;

You can see only Result[3] is affected. This is called column-major storage, but note that OpenGL can be set up in order to use row-major instead (see the OpenGL FAQ on this).

share|improve this answer
Also be aware that D3D can be set up to use column major too (in fact this is no longer such a religious issue as it was in the fixed pipeline days) - in other words you can't actually rely on anything! –  Jimmy Shelter Nov 27 '11 at 3:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.