Skip to the matrix at a point

Hello to all the community

Since 3 days I am trying to determine the position x, y, z of a point.

To achieve this I have a table in the matrix.

I would like to pass the matrix to a point x, y, z corresponding to the original matrix.

Matrix [16] -> x, y, z

Could you help me thank you very much!

The matrix (M) multiplies a point § to generate a scaled/rotate/translate/etc new point (P’).

P’ = M * P

Are you saying that you have only a matrix M and want to know the point P before the matrix transformation? The answer to that is

P = inverse(M)*P’

Ok I say the second thing:

P = inverse(M)*P’

But I don’t have P’.
P’ = glLoadIdentity();

But I do not understand too because for me M is equal to 16 values.

If I do so with your formula P ‘= 0 but p’ is different from 0.

Could you give me a specific example or formula.

P and P’ are vectors containing x,y,z,w coordinates (4 elements in C array). And M is a 4x4 matrix (16 elements in C array).

M does not store any information about the point. M only transforms a point P to P’.

glLoadIdentity specifies the Matrix M, not the point P or P’.

So Say you have the code


	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity(); // MV = Identity 4x4 matrix
        glTranslate(...); // MV = I*T (T is 4x4 matrix)
        glRotate(...);    // MV = I*T*R (R is 4x4 MAtrix)
        glScale(...);     // MV = I*T*R*S (S is 4x4 matrix)
        glMultMatrixf(Q); // MV = I*T*R*S*Q (Q is genral 4x4 matrix)
        // Notice nowhere has a point been transformed yet
        // to do that openGL must draw a set of vertices ie 
        glVertex4f(x,y,z,w); // P'=MV*P where P=(x,y,z,w)
        // and MV has not changed by calling glVertex
        // hence MV does not store any info about either P or P'     

In other words you can only get the transformed point P’=(x’,y’,z’,w’) knowing both the MOVDELVIEW matrix (MV) AND the original vector/point P.

The inverse operation also requires two pieces of information the inverse(MV) matrix AND the final transformed vector/point P’ to determine the original point P. The problem is ill-defined if you only know just the matrix and not P’ ie it is impossible to know the original point if you only know the matrix M alone.

Ok for begin thank for your answer.

However I know that you tell:

I just want a formula as:

Objet.X = Matrix[4]+matrix[11];
Objet.Y = Matrix[5]+matrix[12];
Objet.Z = Matrix[6]+matrix[13];

It’s a exemple.
I would know a formula for calculate.
Not a mathematical formula as P '= P * M.

Again Thank.

see here to do matrix-vector multiplication (last equation before code sample at end of document). The P’=M*P would map into:


|  	1  	2  	3  	4  	| | 	X 	| | 	 1X+ 2Y+ 3Z+ 4W 	|
| 	5 	6 	7 	8 	|x| 	Y 	|=| 	 5X+ 6Y+ 7Z+ 8W 	|
| 	9 	10 	11 	12 	| | 	Z 	| | 	 9X+10Y+11Z+12W 	|
| 	13 	14 	15 	16 	| | 	W 	| | 	13X+14Y+15Z+16W 	|

so

| 	X' 	| | 	 1X+ 2Y+ 3Z+ 4W 	|
| 	Y' 	|=| 	 5X+ 6Y+ 7Z+ 8W 	|
| 	Z' 	| | 	 9X+10Y+11Z+12W 	|
| 	W' 	| | 	13X+14Y+15Z+16W 	|

see 4x4 matrix inverse. Inverse(A) = A^-1.

Ok good.
I know how inverse matrix.
I know how multiplication matrix.

But I don’t know how find the position of my objet who is place by my matrix MatrixObjet.

It’s my question ?

Ps: I have test and read your link and it’s don’t work.

Thank for your search and your knowledge.

Concerning “Ps: I have test and read your link and it’s don’t work.” Which link doesn’t work? The difference may be due to the layout of the matrix in C – There is a concept of Matrix layout – column major or row major. The link on matrix multiplication above was correct but assumed a different layout than openGL/C uses – take a look at this link instead here.

SO in openGL array layout


|  	0  	4  	8  	12  	| | 	X 	| | 	 0X+ 4Y+ 8Z+ 12W 	|
| 	1 	5 	9 	13 	|x| 	Y 	|=| 	 1X+ 5Y+ 9Z+ 13W 	|
| 	2 	6 	10 	14 	| | 	Z 	| | 	 2X+ 6Y+10Z+14W 	|
| 	3 	7 	11 	15 	| | 	W 	| | 	 3X+ 7Y+11Z+15W 	|

so

| 	X' 	| | 	 0X+ 4Y+ 8Z+12W 	|
| 	Y' 	|=| 	 1X+ 5Y+ 9Z+13W 	|
| 	Z' 	| | 	 2X+ 6Y+10Z+14W 	|
| 	W' 	| | 	 3X+ 7Y+11Z+15W 	|


A little background can be found at “9.005 Are OpenGL matrices column-major or row-major?”.

I like the first link with the background green.

However when I write for my camera to follow the objet at position 0,0,0 as your site thus x -> matrix[12] y -> matrix[13] and z-> matrix[14].

Citation of website:

(0,0,0)  --->  ( 0, 0, 0 ) + ( m[12], m[13], m[14] )

And this don’t work.

Have you a idea ?

ps: I have rotation left and right but it’s regist in matrix.

Is the object you are following with your camera defined with its center at the origin ie when the MV matrix is identity will you see the object at the center (0,0,0)?

Are you using gluLookAt?

Yes I have dev a loader 3ds in Opengl/c#.

My objet is place at 0,0,0 at begin and after is load at the place of matrix:

Gl.glPushMatrix();
            Gl.glLoadMatrixd(objectTransformationMatrix);
            
            Gl.glBegin(Gl.GL_TRIANGLES);
            for (int face = 0; face < nbFaces; face++)
            {
                for (int i = 0; i < 3; i++)
                    Gl.glVertex3f(
                        faces[face].point[i].x,
                        faces[face].point[i].z,
                        faces[face].point[i].y);
            }

            Gl.glEnd();
Gl.glPopMatrix();

I use glLookat, I don’t want use rotated and translated for my camera because I think its heavy.

Thus my object is placed at the location of the matrix.

Founding x,y,z with my matrix i will found the objet in my 3d world.

Can you show your exact gluLookAT line? I would think that you could simply set the center cooridinates (4th,5th,6th parameters of gluLookAt) to m[12],m[13],m[14].

i have test with:

Glu.gluLookAt(0, //eye X
                    0, //eye Y
                    0, //eye Z
                    -(Mesh.objectTransformationMatrix[12]), //center X
                    0, //center Y
                    -(Mesh.objectTransformationMatrix[14]), //center Z
                    0.0f, // upvect X
                    1, // upvect Y
                    0.0f); // upvect Z

And:

Glu.gluLookAt(0, //eye X
                    0, //eye Y
                    0, //eye Z
                    -(Mesh.objectTransformationMatrix[0] * Mesh.objectTransformationMatrix[12] +Mesh.objectTransformationMatrix[12]), //center X
                    0, //center Y
                    -(Mesh.objectTransformationMatrix[10] * Mesh.objectTransformationMatrix[14] +Mesh.objectTransformationMatrix[14]), //center Z
                    0.0f, // upvect X
                    1, // upvect Y
                    0.0f); // upvect Z

It’s don’t work.

I have not translated y thus I leave y =0;

Thank for your support.

Why the minus signs? Try instead


Glu.gluLookAt(0, //eye X
                    0, //eye Y
                    0, //eye Z
                    Mesh.objectTransformationMatrix[12], //center X
                    Mesh.objectTransformationMatrix[13], //center Y
                    Mesh.objectTransformationMatrix[14], //center Z
                    0.0f, // upvect X
                    1, // upvect Y
                    0.0f); // upvect Z

Note this will fail if your eye (0,0,0) is the same as center (Mesh.objectTransformationMatrix[12],Mesh.objectTransformationMatrix[13],Mesh.objectTransformationMatrix[14]). In general you want to place the eye at some offset of center ie eye = offset + center to avoid the problem.

yes i have the minus signs because without the camera go in the opposite direction to the object after a rotation.

It’s don’t work.

I seeking a formula to follow the object for begining.

But I don’t found.

Are you applying any other matrix operations beside gluLookAt and Mesh.objectTransformationMatrix?

Since you are using glLoadMatrixf you are overwriting anything you do with gluLookAt before – I think you effectively are not using gluLookAt. Or does the Mesh.objectTransformationMatrix contain the gluLookAt transformation itself? If that is the case then you cannot interpret the m[12 to 14] values as the location of the mesh origin anynore.

You may want to study the source code at"Points of View". I think if you see this it may help you out in the long run working with the gluLookAt camera.

No any other matrix operations.

I think that matrix[12] is not the only operations for find the position x.

But i don’t know what other ?

Have you ever develop a game 3d adventure where the camera follows the character?

If yes how did you do?

Yes, but a better example is the “points of View” link given above.

Your link is a exemple of that I can’t do.

Because when i have a translation, rotation and translation, the camera will do translation, rotation but the second translation will go on the first direction.

And not the direction of the rotation.

I know there a formula that would allow me to find the position of the object from the arrays, but I think not.

Exemple of my matrix after transformation with Debug:

0.9
0
-0.42
0
0
1
0
0
0.422
0
0.9
0
-8.43
0
-21.53
1

If it’s can give help.

That doesn’t really help. I am concerned how you get that matrix in the first place. If you leave the object at fixed location and orientation but change the parameters to gluLookAt only what are the matrix debug values before and after that change? If they change by simply changing gluLookAt parameters then that would be the cause of the confusion in my opinion. The whole idea of using m[12],m[13],m[14] directly assumes that the transformation matrix does not include the gluLookAt transformation.

Can you draw something that is always located at m[12],m[13],m[14] – If what I think is going on I suspect that you will always see it in the center of your view no matter how you change gluLookAt.

I am thinking that the fix may come from using glMultMatrixf instead of glLoadMatrixf. But that depends somewhat on the answers to the above questions.