# vector transformation

Hi,
I want to find the corrdinates of a normal vector (not radius vector) in a coordinate system that is translated and rotated in accordane with the basic system. To clarify I give the folloing example:

int vecOrigCoord; // contains the coordinates of the vector in the system of origin A
Then I tanslate and rotate the current view with glRotatef() and glTranslatef() functions to obtain coordinate in transformated system B and I want to know what should be the coordinates of this vector in coordinate system B. I know if I use the matrix of transformations I can find easily the coordinates of the position vector, and they are the same for those of the normal vectors in systems where only rotation is performed on transformation.

Is there anyone who can help me, please?

Let me see if I understand. Do you want to find the coordinates of a vector in a system B related to the system A or do you want to find the coordinates of your vector related do the system B?

For the first question, I see that you know the answer, just get the OpenGL model view matrix and apply it to you original vector.

In the case of normals, you will need the inverse of 3x3 block of the model view matrix.

I want to find the system B’s coordinates of a vector V through coordinates given in system A. i.e I have the coordinates of V in system A and I want to find the coordinates of the same vector V in system B.
System A - system of origin
System B - related to A

Should I use the invert of model view matrix? How is the best way to calculate it from the model view matrix? Maybe using straight forward matematical approaches?

I have the coordinates of V in system A and I want to find the coordinates of the same vector V in system B.

So multiply the vector by the matrix that transforms from coordinate system A to coordinate system B. You told OpenGL to build this matrix by using the glTranslate and glRotate functions. If those are the only transformations currently on the matrix stack, you could just get the modelview matrix. Otherwise, you’ll have to implement the equivalent of glTranslate/glRotate yourself (or use GLM). Then just multiply the vector by the matrix.

If it’s a directional vector, then set the fourth coordinate to zero. If it’s a positional vector, set it to one.

This is operation which transforms from coordinates in some of the derivative coordinate systems to the coordinates in the system of origin, right? I want the inverse thing.

P.S. Is there faster way to invert 3x3 matrix than this one:
http://www.wikihow.com/Inverse-a-3X3-Matrix

If you know that the matrix is orthogonal, then just transpose it to get the inverse:

http://en.wikipedia.org/wiki/Orthogonal_matrix

Basically this means that the matrix is comprised of 3 vectors that are mutually perpendicular. For the typical case of only rotations and translations in the MODELVIEW matrix, this is the case for the upper-left 3x3. In fact that matrix is not only orthogonal but orthonormal because all the unit vectors have length 1.

This is operation which transforms from coordinates in some of the derivative coordinate systems to the coordinates in the system of origin, right? I want the inverse thing.

You seem to have changed your terminology here, and now I’m confused.

You said, “I have the coordinates of V in system A and I want to find the coordinates of the same vector V in system B.”

There is a transformation, expressed as a matrix, that transforms vectors from the space A to the space B. You computed that transformation matrix using the various GL matrix functions.

The discussion has gotten bogged down in terminology. Best thing is to post a simplified, cleaned up version of your code. Don’t just post the one routine where you think you need help. Post a working version that I can compile and run. Then state in the simplest terms possible what you want the code to do.

That’s the code that do the vector transformation that I asked about in the begining of this topic. At the top of main.cpp file is the explanation of the main function of the program.

So my question is:
Is there any better and faster way for calculation of the inverse of modelview matrix than the one that I propose in my code in the links above?

Any help will be appreciated, please.

If you know that the matrix is orthogonal, then just transpose it to get the inverse:

http://en.wikipedia.org/wiki/Orthogonal_matrix

Basically this means that the matrix is comprised of 3 vectors that are mutually perpendicular. For the typical case of only rotations and translations in the MODELVIEW matrix, this is the case for the upper-left 3x3. In fact that matrix is not only orthogonal but orthonormal because all the unit vectors have length 1.
[/QUOTE]

Actually this completly solve my problem. Sorry but somehow I’ve skiped this useful post of Dark Photon. Thank you a lot for helping me.