views:

365

answers:

2

Hi

I just don't seem to be able to figure this out in my head. I'm trying to move an object in 3D space.

If I have a point at 5,15,5 and use opengl functions to change the model view....

glTranslatef( 10.0f, 4.0f, 4.0f );
glRotatef( 33.0f, 1.0f, 0.0f, 0.0f );
glTranslatef( 10.0f, 4.0f, 4.0f );

Is there a way I can find out where that point ends up (in world / global coordinates)? Can I do some kind of matrix calculations that will give me back 20,26,23 (or what every the new coordinate position is)?

Please help, I've been stuck on this for so long!

+4  A: 

Try the following:

1) Push the current matrix into stack; 2) Load identity and apply your transformations; 3) Get the resulting transformation matrix into some temp variable. glGet or something like that will help; 4) Pop the matrix from the stack;

Now you have your transformation matrix. Multiply your point by this matrix to predict the point's coordinates after the transformation.

SadSido
I think I get it now :) something along these lines...http://www.gamedev.net/reference/articles/article877.asp
michael
A: 

Definitely: check out http://research.cs.queensu.ca/~jstewart/454/notes/pipeline/

In short, all of these calls reduce to a single matrix, which is multiplied onto the point.

SadSido's method will definitely get you the resultant matrix, but it may not hurt to actually understand what's going on behind the scenes. The calculations above will result in a linear algebra equation of the following:

pOut = [mTranslate] * [mRotate] * [mTranslate] * pIn

where mTranslate = the translation calls (matrix for translation), and mRotate = rotate call (matrix for rotation about an arbitrary axis). Calculate that, and you're good to go!

MBillock
Thankyou for your answer, when I get a little more comfortable with all of this I think I'll delve deeper into matrix maths
michael