Jump to content
  • Advertisement
Sign in to follow this  
muye

How can I move my camera

This topic is 2852 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

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?

Share this post


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

Share this post


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

// build projection matrix
gluPerspective(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 stuff
glPushMatrix();
// Translate/Rotate by the object position etc
// Draw object
glCallList(m_cameraDisplist);
glPopMatrix();

Share this post


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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!