# Getting an object's matrix

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?

have you tried multiplying it on the left side?

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

cb

Multiplying by the inverse of the camera matrix should work. Remember, the order is important.

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
objectMatrix.Mul(modelViewMatrix);

// take the inverse of the object's
objectMatrix.Inverse();

// take my cutplane matrix and multiply by object's matrix
drawPlaneMatrix = objectMatrix;
drawPlaneMatrix.Mul(gCutPlane.m_Matrix);
``````

.
.
.
(later on)
glBegin();
multiply points by drawPlaneMatrix
glVertex3f…
glEnd();

Thanks, I really appreciate any help I can get!

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?

Thanks

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.

Yes, my matrix order is column major order just like opengl.