I'm trying to point a camera to a plane I have with a texture. I'm using gluPerspective and glLookAt and this only happens when a variable is set to 1. When the variable is set to 1 I change my view:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.0, GLdouble(600)/GLdouble(600), 1.0, 200.0);
gluLookAt(100.0, 50.0 + 0, 0+0, 150, 50, 0, 0.0, 1.0, 0.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
The Plane is positioned in x=500.0 , y=50.0, z=0.0
gluLookAtis the call you would use to do what you're asking. Before we get to that answer, however, there's are another problem to sort out first.You initially put OpenGL into
GL_PROJECTIONmode, and correctly multiply a perspective matrix not the stack with your call togluPerspective. Next you apply the matrix generated fromgluLookAtalso to the projection matrix stack. You don't want to do that, generally speaking. SincegluLookAtgenerates a viewing matrix, it really should go on the model-view matrix stack. Here's a more correct sequence of code:Now, to your question:
gluLookAttake three "sets" of parameters:So, you need to choose the point on your plane that you want camera pointed toward, which you say is at (500, 50, 0), and so you'd pass those as the middle three parameters to
gluLookAt. The larger question may be where you want to position the camera. If you wanted something like a "wingman view", where you're simulating flying next to the plane, you'd choose a suitable offset, say something like 20 units off the port side of the plane, and 10 units behind, flying in the same plane (geometric plane, and not airplane). You'd then set you camera position to be (500 - 20, 50 + 10, 0 + 0), and pass those three values as the first three parameters. Finally, you set the y-axis to point up, and pass those as the last parameters, as you originally did.gluLookAtwill take care of generating the matrix, and applying it to the model-view matrix stack.