How can I move my camera

Started by
4 comments, last by TTK-Bandit 13 years, 6 months ago
Hello, everyone!
I currently have to implement a program--I put the object at somewhere such as (x0,y0,z0), and I have a camera whose position is (x1,y1,z1) relative to the position (x0,y0,z0) and the camera is pointing at negative z, now I need to point the camera directly to object, how can I do to achieve that?
Advertisement
You can use for example gluLookAt.
Quote:Original post by Erik Rufelt
You can use for example gluLookAt.


I do use the function like follows:
glPushMatrix();
gluLookAt(0,0,0,-curcamera.x,-curcamera.y,-curcamera.z,0,1,0);
glTranslatef(curcamera.x,curcamera.y,curcamera.z);
glCallList(m_cameraDisplist);
glPopMatrix();

But it seems that the code doesn't work
"code doesn't work" doesn't mean anything for us...
if your going to use gluLookAt you dont need to use glTranslatef

eyeX, eyeY, eyeZ
Specifies the position of the eye point.
centerX, centerY, centerZ
Specifies the position of the reference point.
upX, upY, upZ
Specifies the direction of the up vector.

eye is position (translation)
center is camera lookat point
up is up (usually x=0, y=1, z=0)

try something like this:
// Setup cameraglMatrixMode( GL_PROJECTION );glLoadIdentity();// build projection matrixgluPerspective(mFieldOfView, mAspectRatio, mNearPlane, mFarPlane);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(mPosition.x,mPosition.y, mPosition.z,	  mLookAt.x, mLookAt.y, mLookAt.z,	  mUp.x, mUp.y, mUp.z);// Draw stuffglPushMatrix();// Translate/Rotate by the object position etc// Draw objectglCallList(m_cameraDisplist);glPopMatrix();
Quote:Original post by muyeBut it seems that the code doesn't work


do some research on glpush/popmatrix. all gluLookAt does is change the current matrix. if you undo that shortly after using popmatrix, then you won't get the result you aimed for.

This topic is closed to new replies.

Advertisement