Setting the camera without glulookat?

Started by
3 comments, last by GameDev.net 24 years, 5 months ago
I'm not one hundred percent sure of this, but I believe it goes something like this. At the beginning of your frame, clear out your modelview matrix. Then scale and translate that matrix by the inverse(i.e. negative) values of where your camera is. So if it's located at (5, 10, -5) and looking down the x axis in the positive direction(90, 0, 0), you'd just do this:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslate(-5, -10, 5);
glRotate(-90, 0, 0, 1);

And then do all your drawing. That should do the trick I might have the translate and rotate backwards though...

Jonathan

Advertisement
I usually do my camera settings that way

void display() // at this point GL_MATRIXMODE is set
{
...//Clear buffers...
glPushMatrix();
glTranslatef(-playerXpos,-playerYpos,-playerZpos);
glRotatef(LookUpDownAngle,-1,0,0);
glRotatef(LookLeftRightAngle,0,0,-1);
// Draw all objects in cameraview
glPopMatrix();

...
}

player_pos is the actual position of your cam in world coordinates. LookUpDownAngle and LookLeftRight is the direction your cam is looking at. When you know how to use a matrix you can use the OpenGL function:
void glMultMatrixd(
const GLdouble *m
);
m is the 4x4 Matrix (double in this case)

Thanks for that
In opengl, How do I set the camera without using glulookat???
Sorry, I made a mistake in the code above.
I hope it is ok now ;-).

void display() // at this point GL_MATRIXMODE is set
{
...
//Clear buffers...
glPushMatrix();
glRotatef(LookUpDownAngle,-1,0,0);
glRotatef(LookLeftRightAngle,0,0,-1); glTranslatef(-playerXpos,-playerYpos,-playerZpos);

// Draw all objects in cameraview
glPopMatrix();

...
}

This topic is closed to new replies.

Advertisement