PDA

View Full Version : Help setting up the view



ThomasHarte
05-11-2001, 12:52 AM
In order to define the view in my application, I have the four corners of the view plane and vectors which run from these corners such that they define the corners of the view window (always rectangular). I know on which side of the view plane the vectors meet, and that they do, but not exactly where.

How do I communicate this to OpenGL in order to define the correct view? And should I put this information on projection or modelview?

E.g. if the viewer were at the origin, looking along z I might have the view plane constructed between position vectors (-1, -1, 1), (1, -1, 1), (1, 1, 1) and (-1, 1, 1), with exactly the same vectors used at each point to define the corners of the display. Am I even making sense?

ffish
05-11-2001, 02:28 AM
Here's a typical view setup function:




void ResizeScene(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum((GLdouble)-1.0, (GLdouble)1.0,
(GLdouble)-1.0, (GLdouble)1.0,
(GLdouble)1.0, (GLdouble)1000.0);
glMatrixMode(GL_MODELVIEW);
}

glFrustum sets up your viewing volume. Parameters are left, right, bottom, top, zNear, zFar i.e. the coordinates of the clipping planes of your view volume. You will have your point of view at the origin so in your drawing function, you need to start probably like this:



glLoadIdentity();
GLfloat Z_Offset(-1.0f);
// This will offset your "camera" to +1.0f along the z axis (out of screen).
glTranslatef(0.0f, 0.0f, Z_Offset);
...
DrawObjects();


Hope that helps.