View Full Version : Getting an object's matrix

12-06-2002, 01:44 PM
I want to get an object's matrix when I am about to draw it, but I don't want the camera transform in it. I only want the object's matrix. I thought multiplying by the camera inverse matrix would give me just the object's matrix. I guess not because that didn't work. :-)

Any suggestions?

12-07-2002, 12:23 AM
have you tried multiplying it on the left side?

ModelViewMat = CamMat * WhateverMat
-> CamMat^-1 * ModelViewMat = WhateverMat


12-07-2002, 06:41 PM
Multiplying by the inverse of the camera matrix should work. Remember, the order is important.

12-08-2002, 07:46 AM
Can you please tell me if this is the correct way? What I am trying to do is cancel out the object part of the transformation so that when opengl's modelview matrix is applied I just get the camera transform and plane transform. (I have to do it this way because I am auto generating texture coordinates and opengl wants the real transform of the object when it receives the vertices. But the plane that I am drawing the texture on is not part of the object.)

// get the modelview matrix
BMatrix modelViewMatrix;
glGetFloatv(GL_MODELVIEW_MATRIX, modelViewMatrix.Mtx);

// get inverse camera matrix
BMatrix objectMatrix;
objectMatrix = gCamera.Matrix; // actually contains inverse camera matrix

// take the camera out of the matrix by
// multiplying inverse camera matrix by modelViewMatrix

// take the inverse of the object's

// take my cutplane matrix and multiply by object's matrix
drawPlaneMatrix = objectMatrix;
(later on)
multiply points by drawPlaneMatrix

Thanks, I really appreciate any help I can get!

12-09-2002, 12:07 PM
I just can't seem to make this work...

glGetFloatv(GL_MODELVIEW, modelViewMatrix);
objectMatrixOnly = myInverseCameraMatrix * modelViewMatrix;

Can someone please point me to a web page or tutorial on how to extract the object's matrix from the current opengl matrix?


12-09-2002, 03:31 PM
Well that seems correct, are you ordering your rows/columns correctly?

Opengl uses column major ordering:
|0 4 8 12|
|1 5 9 13|
|2 6 10 14|
|3 7 11 15|

It gave me some weird results in the beginning.

12-10-2002, 04:42 AM
Yes, my matrix order is column major order just like opengl.