# glRotatef Coords?

This topic is 4231 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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).

##### Share on other sites
How can I translate my self?
Is there a formula for glRotatef?

##### Share on other sites
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.

##### Share on other sites
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!

##### Share on other sites
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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634113
• Total Posts
3015570
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!