Advertisement

gluUnProject and gluLookAt

Started by February 08, 2000 08:04 PM
1 comment, last by acw83 25 years, 1 month ago
Ok, I am having some problems with these functions. The reason I am using them is to implement a camera into my engine. I was directed to gluLookAt, but realized you needed a reference point in world space to have your camera face. Then I noticed gluUnProject and thought I''d use gluUnproject to get the world coordinates of the window cooridinates (250, 250, 0) as that is the center of my 500x500 window. then I would take the results from UnProject and use them to face my camera at the center of the screen. So I set up the required arrays to get passed into gluUnProject, and everything works. That is until I actually call gluUnProject--at which point an Illegal Op is performed. Anyway am I making this to hard? Is there an easy way to do cameras in OpenGL? Are there any documents out there specifically about camera systems in OpenGL??? Thanks in advance!!!
quote:
Original post by acw83

Is there an easy way to do cameras in OpenGL? Are there any documents out there specifically about camera systems in OpenGL??? Thanks in advance!!!


I''m having a hard time understanding how a 3D app WITHOUT a camera would even be possible. Having a camera (or eye or whatever what to call it) is critical to the scene, so if you have anything on the screen at all, you already have a camera, it''s just set to the default, which is at the origin, looking down the z-axis, with the positive y axis as up.

gluLookAt just sets the orientation of the scene. You don''t need to think about what specific point you are looking at in the scene, because all you are really doing is setting the direction you are looking. So for a lot of cases, you can just use the default, since looking down the z-axis is as good as anything.

For a better idea of how gluLookAt works, have a look at Nate Robin''s OpenGL tutors.
Advertisement
Using gluUnProject to get the center point for gluLookAt is to go in circles, since you need to send the matrix computed by gluLookAt to gluUnProject.

gluUnProject should be used to get the direction of a ray from the camera through a point on the screen, e.g. mouse position. But you probably already knew that.

As Rhino said Center point sent to gluLookAt doesn''t need to be a specific point, any point on the line going in the direction of the camera will do.

The center point could be computed like this

Center[0] = cos(pitch)*sin(yaw)
Center[1] = sin(pitch)
Center[2] = cos(pitch)*cos(yaw)

This topic is closed to new replies.

Advertisement