# Mapping object coordinates

Hi people!

I’m making a 3D game engine, and I have a problem.

I want to map objects coordinates to world coordinates, it is, get the position of each informed vertex.

For example:

glTranslatef(3.0f, 0.0f, 0.0f);
glRotatef(30.0f, 0.0f, 1.0f, 0.0f);

/* Here! I want to get the position where all the 4 points will be drawn (in X, Y, and Z). I can’t preknown this because I informed a rotation before. */
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);

glEnd();

In this example, If i didn’t have informed the glRotatef(30.0f, 0.0f, 1.0f, 0.0f), It would be easy to discover the four points. All we should do is subtract each vertice informed in glVertex3f with the actual translation:

For example:

glTranslatef(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 1.0f, 0.0f);
glVertex3f(1.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glEnd();

In this case, we know that the first glVertex3f will be draw at X = 1.0f, Y = 1.0f and Z = 0.0f in relation to the WORLD.

We arrived to this, by adding the values passed to glTranslatef and glVertex3f.

So, this is my problem!! I would like to know how to get the objects coordinates in World coordinates, but I don’t know a way to do this.

Sorry for the long text guys, I hope someone knows how to do this!

If you didn’t understand what I asked, please, post a message telling this! Because I don’t know if I explained correctly what I want to do, and my english is not very good too…

If you don’t want to post the code here, send it to my e-mail: fernandohu@bol.com.br
I’ll be very greatefull!

Thank you a lot!
Fernando

You’re going to need to learn matrix math. Do a search for multiplying matrices and also do a search on just matrices.

The best way I can describe a 4x4 matrix is that it contains numbers that make up the x, y and z axis, the position and scew. A 3x3 matrix, as far as I know, only contains the x, y and z axis.

The cool thing is that a matrix can be rotated just like a vector because what you’re doing is rotating the x, y and z axis. When you multiply a vertex by the matrix it will move acoording to the position of the x, y and z axis, position and scew.

Nifty! [This message has been edited by WhatEver (edited 06-02-2002).]

edited: bob caught some mistakes One other thing about matrices. One of the hardest things to understand is what an identity matrix is. An identity matrix is a matrix whos x, y and z axis are the length of 1.0f, position xyz is 0.0f, and scew xyz is 0.0f.

[This message has been edited by WhatEver (edited 06-02-2002).]

An identity matrix is a matrix whos x, y and z axis are the length of 1.0f, position is 0.0f, and scew is 0.0f.

In that case a rotation matrix is also an identity matrix. A rotation matrix also has no skew, no translation, and an orthonormalized vector basis, just like the indetity matrix you described. Knowing my matrix math, I know that a rotation matrix is not an identity matrix.

Also, what does “position is 0.0” mean? Did you perhaps mean (0.0, 0.0, 0.0), since we are probably talking about three dimensional positions?

Anyways, an identity matrix is a square matrix N by N, where all elements are zero but the main diagonal (element (i, j), where i = j and 0 < i < N-1) whose elements are one.

Thank you for your posting guys!

I already know something about matrices! I’m creating my 3D engine using pure MATRIX operations and QUATERNION to store the rotations…

I know how to use them, but I don’t know how they can describe a final object.

I imagine that doing some calculus with the first 3 elements (3x3) of the matrix, will give the results I want, but i don’t know how to do them.

Thank you guys!!
Fernando

Hmmmm, how could I explain the identity matrix better. The xyz axis are planar in the identity…so you’re right about me not axplaining it well in my first explanation because the rotation matrices xyz axis will always be a length of 1.0f :/.

I think this is row major…

This is the numerical representaion of the identity matrix:
 // xyz vector for x axis
 // xyz vector for y axis
 // xyz vector for z axis
 // position

This is the variable representation of the identity matrix:
[x][y][z][x] // x axis with scew in the last column
[x][y][z][y] // y axis with scew in the last column
[x][y][z][z] // z axis with scew in the last column
[x][y][z] // position

Does that seem clear?

All you have to do to get the world position of a vertex is this:

1. Push the matrix
2. Translate, Rotate…etc.
3. Retrieve the current matrix
4. Multiply the object vertices by the retrieved matrix

The result of the vertex after multiplying it with the retrieved matrix is the world position.

Is that what you wanted?

[This message has been edited by WhatEver (edited 06-02-2002).]

Huuumm

Thank you WathEver

But, to tell the truth, I didn’t understand what you wanted to explain!

Can you post some code?

Thank you!
Fernando

Maybe someone else will before me…I havn’t forgotten…it’s just we have company and I don’t have time to show you a sample…tomorrow for sure…possibly tonight…

late!

Well whataya know, they left.

What you need to do is perform your matrix operations like you normally do for your objects, then retrieve the matrix from OpenGL before you pop it off the stack. It goes sumfin’ like this.

glPushMatrix();
glTranslatef(Player.X, Player.Y, Player.Z);
glTranslatef(Player.Yaw, Player.Pitch, Player.Role);
//draw the model like you always do…
Player.Draw();
//now this is where you obtain the current matrix…the one you’ll use to transform your vertices to world space
glGetFloatv(GL_MODELVIEW_MATRIX, Matrix);
//now pop the matrix as you usually would at this point
glPopMatrix();

Now multiply the vertices inside Player by Matrix. You will have then transformed your Player vertices to world space.

There ya have it…I hope that’s what you were looking for. I’m pretty sure it is [This message has been edited by WhatEver (edited 06-02-2002).]