PDA

View Full Version : the position of point



tigeryhong
01-31-2003, 04:17 AM
Could you please give me some idea about following codes:

Find the position of the points displayed in window coordinates with
the origin at the bottom left corner, and rounded to the nearest pixel.

void display ()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-2.5, 2.5, -2.5, 2.5, 4.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glBegin(GL_POINTS);
glVertex3f( 1.0, 0.0, 0.0 );
glEnd();
glRotatef(90.0, 0.0, 0.0, 1.0);
glBegin(GL_POINTS);
glVertex3f( 1.0, 0.0, 0.0 );
glEnd();
glFlush();
}
void main (int argc, char **argv)
{

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(500,500);
...
// GLUT general initialization
glutDisplayFunc(display);
glutMainLoop();
}

Deiussum
01-31-2003, 05:10 AM
Ok, I started actually working through some of the calculations for you until I realized... You didn't provide enough information. You need to know what's passed to glViewport for the final steps of converting to window coordinates.

But, anyway, to at least attempt to help you out a bit...

Check the back of the Red book for the formula to calculate what the Projection matrix looks like after glFrustum. Appendix G (http://fly.cc.fer.hr/~unreal/theredbook/appendixg.html) has what you need.

For the Modelview matrix, that particular gluLookAt call is essentially equivalent to glTranslate(0, 0, -5), so you can also consult Appendix G to see what the modelview matrix looks like.

After you know what your Modelview and Projection matrices look like, you can go to the OpenGL 1.4 specification (http://www.opengl.org/developers/documentation/version1_4/glspec14.pdf) to find the formulas for calculating object coordinates to eye coordinates to normalized device coordinates to window coordinates. Section 2.10 is what you want. (OpenGL operation->Coordinate transformations)

Edit: If you're not sure of the matrix multiplication operations Google (http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=Matrix+multiplication) is your friend.



[This message has been edited by Deiussum (edited 01-31-2003).]

tigeryhong
01-31-2003, 08:25 AM
Hi, buddy: I apprecite your help. I will try depending on your direction.