I'm kind of confused about how opengl matrices work. Say i have a rotation around the Z axis. _mij are sequential in memory, that is _m12 follows immediately after _m11 and _m21 follows just after _m14.
If i load this with glLoadMatrixfv i obtain the same results as when calling glRotatef(30,0,0,1).When calling glGetFloatf with GL_MODELVIEW_MATRIX i obtain the same results with both methods(glLoadMatrixf and glRotatef). But if i want to correctly transform a column vector and obtain the same results as when opengl transforms it with this matrix i have to post multiply with the my matrix, like this:
but opengl Premultiplies a vector with a matrix like this:
Why is this difference? Does OpenGL store my matrix inverted in memory? What about retriveal of the matrix from OpenGL?
Code:
_m11 = cosAngle; _m12 = sinAngle; _m13 = 0.0f; _m14 = 0.0f;
_m21 = -sinAngle; _m22 = cosAngle; _m23 = 0.0f; _m24 = 0.0f;
_m31 = 0.0f; _m32 = 0.0f; _m33 = 1.0f; _m34 = 0.0f;
_m41 = 0.0f; _m42 = 0.0f; _m43 = 0.0f; _m44 = 1.0f;
If i load this with glLoadMatrixfv i obtain the same results as when calling glRotatef(30,0,0,1).When calling glGetFloatf with GL_MODELVIEW_MATRIX i obtain the same results with both methods(glLoadMatrixf and glRotatef). But if i want to correctly transform a column vector and obtain the same results as when opengl transforms it with this matrix i have to post multiply with the my matrix, like this:
Code:
transformedVertex = Transpose(Transpose(transformedVertex) * myMatrix).
but opengl Premultiplies a vector with a matrix like this:
Code:
transformedVertex = myMatrix * transformedVertex.
Why is this difference? Does OpenGL store my matrix inverted in memory? What about retriveal of the matrix from OpenGL?