glRotatef Coords?

Started by
4 comments, last by Lord_Evil 16 years, 10 months ago
Hello all. I got a question: After I Rotate something how can I know its new coords? Like if it 1,3,1 what are the new? how can I know? Thanks in advance
Advertisement
I assume you mean how can you get the rotated poosition of a point when rotating with glRotatef?

You can get the rotated position by transforming the point yourself. AFAIK you can retreive the modelview matrix from OpenGL but not the transformed vertices (unless you use some shader tricks or so).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
How can I translate my self?
Is there a formula for glRotatef?

Thanks in advance
Transforming a point is a matter of standard matrix math.
All you need is a matrix that represents your rotation and/or translation and then multiply it with your point. Try google on some matrix math tutorials.

For the OpenGL matrices you might look here.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
Mmm, I suppose the simplest, least math-heavy way, would be to create a pure translation matrix with the coordinates of the source vector. Something like...

1 0 0 1
0 1 0 3
0 0 1 1
0 0 0 1

then load that onto openGL's matrix stack and apply the glRotate function to it. You could then grab the new matrix from the stack and examine the 4th row elements from it.

It's been a while since i've used OpenGL, so apologies if this is pish, but i think the code would be something like..

float m[16];//// Clear Matrixfor(int i = 0; i < 16; i++)    m = 0.0f;//// Set up identity bitm[0] = 1.0f;m[5] = 1.0f;m[10] = 1.0f;m[15] = 1.0f;//// Setup translationm[3] = 1.0f;m[7] = 3.0f;m[11] = 1.0f;//// Save current MatrixglPushMatrix();glMatrixMode(GL_MODELVIEW);glLoadMatrixf(m);//// Apply Rotation to the MatrixglRotatef(angle, x_axis, y_axis, z_axis);//// Grab Matrix from stack and get result coordsglGetFloatv(GL_MODELVIEW_MATRIX, m);//// Get new coordsnewCoordsX = m[3];newCoordsY = m[7];newCoordsZ = m[11];//// Tidy up! :)glPopMatrix();


There are more math-heavy ways, but i think they involve creating a quaternion for the axis/angle yourself, then converting it to a rotation matrix and applying that manually to your source vector.

Oh, as a slight shortcut, if your rotation is against a world axis plane (as in around a world x/y or z axis), then you can ignore the relative element in the original vector and use sin/cos on the others to quickly find the new coords, however since your using glRotate i don't think thats the case.

Anyways, hope that helps!

MattWhite06 is right. The least math-heavy way is by readig back the OpenGL matrices from the stack and then using them to do your own transformations.

Building rotation matrices from quaternions isn't necessary, you could build the matrices from a bunch of sin/cos calculations.

3D graphics, however, involves matrix and vector math in many aspects so I'd recommend learning those.
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

This topic is closed to new replies.

Advertisement