PDA

View Full Version : glRotate help



malancha
04-04-2004, 10:09 PM
I have a question about glRotate: if I have a fixed point with known coordinates and I call a glRotate, how can I find the coordinates of the fixed point in terms of the new rotated axes?

Thanks in advance.

04-05-2004, 11:08 AM
Don't know of an OpenGL call. However, you can perform the matrix multiplication yourself.

See any graphics book (e.g. Real-time Rendering, Computer Graphics: Principles and Practice, ...), or the comp.graphics.algorithms newsgroup, or the 'Math & Algorithms' forum.

nexusone
04-05-2004, 12:40 PM
There are ways to find it out, but if you explain what you are trying to do maybe an easier way to handle it.


Originally posted by malancha:
I have a question about glRotate: if I have a fixed point with known coordinates and I call a glRotate, how can I find the coordinates of the fixed point in terms of the new rotated axes?

Thanks in advance.

ce110ut
04-05-2004, 03:52 PM
you can use glGet [google it] and pass in the appropriate parameters. an example would be:


// AFTER you do your rotation...

float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);

// manipulate matrix to get what the values you need/wanti hope that helps

-=[ regards ]=-

seed
04-05-2004, 04:02 PM
i would do the following:

glPushMatrix();
glLoadIdentity();
glRotate(...);
float ffMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, ffMatrix);
glPopMatrix();

Then you can find out the coordinates of the rotation from ffMatrix[2], ffMatrix[6], ffMatrix[10] for the x, y, and z coordinates respectively.

To find out where you rotated point is, scale your point's coordinates for the x, y and z coordinates from above. ie.

point.x *= ffMatrix[2]
point.y *= ffMatrix[6]
point.z *= ffMatrix[10]

Hope that helps

malancha
04-05-2004, 07:27 PM
Thanks for answering, people. Maybe I didn't express myself clearly enough -- what most of you have said will apply if I want to find the new viewport coordinates of a point that's been rotated using glRotate. What I'm trying to do is to find the viewport coordinates in terms of the new axes, assuming that the point has remained unmoved.
Turns out that the solution's fairly simple: all I have to do is project the x,y,z vectors of my point onto the new axes.