• Advertisement

Archived

This topic is now archived and is closed to further replies.

Guest Anonymous Poster

Setting the camera without glulookat?

This topic is 6632 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Thanks for that

Share this post


Link to post
Share on other sites
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();

...
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
In opengl, How do I set the camera without using glulookat???

Share this post


Link to post
Share on other sites

  • Advertisement