Calculating Positions based upon glRotatef

i have the following code:

{
DoTranslateRotate();
glBegin(GL_POINTS);
glVertex3f(x,y,z);
glEnd();
UndoTranslateRotate();
}

void DoTranslateRotate()
{
//Perform XYZ Translation
glTranslatef(COrigin.x,COrigin.y,COrigin.z);

//Perform XYZ rotations
glRotatef(COrigin.xAngle, 1.0f,0.0f,0.0f);
glRotatef(COrigin.yAngle, 0.0f,1.0f,0.0f);
glRotatef(COrigin.zAngle, 0.0f,0.0f,1.0f);

}

void UnDoTranslateRotate()
{
//Undo XYZ rotations
glRotatef(-COrigin.zAngle, 0.0f,0.0f,1.0f);
glRotatef(-COrigin.yAngle, 0.0f,1.0f,0.0f);
glRotatef(-COrigin.xAngle, 1.0f,0.0f,0.0f);
//Undo XYZ Translation
glTranslatef(-COrigin.x,-COrigin.y,-COrigin.z);
}

i want to know where the point (x,y,z) will be drawn, and i do know the Data in COrigin

is there some way i can use the OGL matrix and just multiply the matrix by my {X Y Z} values to obtain the new X, Y, Z that the point will appear at (relative to the world)

say if i had the point (1,0,0) and i rotated my y - axis 180 degrees, the point is now at (-1,0,0) correct? given the XYZ, and the rotations i want to find the new XYZ location.

When you call glrotatef(alpha,x,y,z) you give angle alpha, & amount to rotate on x,y&z axis. So everything else is pure math (sin,cos)
But you can use modelview matrix, as 1st row will include all x coord trans, y all y trans and so on (or maybe not, I forgot that as I had a lot of work to be done at uni) take a look at matrix multiplication defs.

im using the perspective matrix so that wont work exactly. i need openGLs calculation

unless a better way of figuring it out can be done

what im trying to do is to see if a user has clicked on a square which can be viewed from any angle. so this is affected by the matrix that openGL is using.

See gluUnproject and/or gluProject.

[This message has been edited by DFrey (edited 01-08-2003).]

You do understand the order in which you call the translate and rotate has a big effect on the location of the object.

Also the the last command before drawing the object is the one effecting the object first.

In the order you have it:

glRotate
glTranslate

Draw_object();

What happens is the object is translated from its origin to some location, then rotate about the openGL’s axis of 0,0,0.

So if say you translate the object 5 units out on the X axis and then rotate 20 degrees. The object will be moved along the openGL origin in a 20 degree arc along the axis of rotation with a radius 5 units.

Now if you do the following:

glTranslate
glRotate

Draw_object()

The object is rotated on the openGL 0,0,0 axis and then moved out to the location.

{
DoTranslateRotate();
glBegin(GL_POINTS);
glVertex3f(x,y,z);
glEnd();
UndoTranslateRotate();
}

void DoTranslateRotate()
{
//Perform XYZ Translation
glTranslatef(COrigin.x,COrigin.y,COrigin.z);

//Perform XYZ rotations
glRotatef(COrigin.xAngle, 1.0f,0.0f,0.0f);
glRotatef(COrigin.yAngle, 0.0f,1.0f,0.0f);
glRotatef(COrigin.zAngle, 0.0f,0.0f,1.0f);

}

void UnDoTranslateRotate()
{
//Undo XYZ rotations
glRotatef(-COrigin.zAngle, 0.0f,0.0f,1.0f);
glRotatef(-COrigin.yAngle, 0.0f,1.0f,0.0f);
glRotatef(-COrigin.xAngle, 1.0f,0.0f,0.0f);
//Undo XYZ Translation
glTranslatef(-COrigin.x,-COrigin.y,-COrigin.z);
}

i want to know where the point (x,y,z) will be drawn, and i do know the Data in COrigin

is there some way i can use the OGL matrix and just multiply the matrix by my {X Y Z} values to obtain the new X, Y, Z that the point will appear at (relative to the world)

say if i had the point (1,0,0) and i rotated my y - axis 180 degrees, the point is now at (-1,0,0) correct? given the XYZ, and the rotations i want to find the new XYZ location.[/b]<HR></BLOCKQUOTE>

[This message has been edited by nexusone (edited 01-09-2003).]

Yeah, i get all that.

but i need the X,Y position in terms of pixels from the top left of the window given the 3d co-ord for my model.

my model code works fine, it draws it textures, but i cant obtain the xy position of a given xyz position after it has been drawn and rotated and viewport transformed.

Like DFrey said, use gluProject. It does exactly what you need. For more advanced picking try gluPickMatrix and glRenderMode(GL_SELECT).

-Ilkka