PDA

View Full Version : Centering a Polygon



dmats
03-18-2009, 02:27 PM
Help Please! I am a beginner with OpenGL and I am quite happy with what I've been able to accomplish so far. However, there is one simple problem that has me stumped!

I have a polygon with 3 vertices (could be anywhere, not necessarily centered at the origin). I know the coordinates of the 3 vertices and the surface normal.

Question: How do I center the polygon in the middle of the screen with the surface normal pointing towards the user?

I've tried gluLookAt, but I can't seem to get it right. Can anyone tell me what calls I need to make and in what order? I have a feeling I'm very close but I'm just missing some small piece.

Thank you in advance!

Capagris
03-18-2009, 03:31 PM
Try the following code:

glPushMatrix();
gluLookAt (0, 0, 10, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
// glTranslatef( 0, 0, -12 ); It is the same effect

float size = 1.0;
glBegin(GL_POLYGON);
glVertex3f(-size, -size, 0.0);
glVertex3f( size, -size, 0.0);
glVertex3f( size, size, 0.0);
glEnd();
glPopMatrix();

It should be so easy as I have written. Try to understand better gluLookAt looking this link
http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/lookat.html