Jump to content
  • Advertisement
Sign in to follow this  
Axesor

Changing NeHe's camera function to a gluLookAt function.

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

As the title says, how do you change the way NeHe madehis camera to a gluLookAt function? Every timer I try this, it comes out wrong. :/ Can some one help? ~Thanks in advanced.

Share this post


Link to post
Share on other sites
Advertisement
.............

This is the NeHe section right?

................. .. ...... .....

*sigh*

float rotx = 360.0f - cam.view.x;
float roty = 360.0f - cam.view.y;
glRotatef(rotx, 1,0,0);
glRotatef(roty, 0,1,0);
glTranslatef(-cam.pos.x, -cam.pos.y-crouch, -cam.pos.z);


Whereas the pos is define as

(UP):
cam.last_pos.x = cam.pos.x;
cam.last_pos.z = cam.pos.z;
cam.pos.x -= sinef(cam.view.y);
cam.pos.z -= cosf(cam.view.y);

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
My solution would be to replace all that code with the following line, but I'm not sure if this is right or not, I did not test this:



gluLookAt(
cam.pos.x, cam.pos.y + crouch, cam.pos.z,
cam.pos.x, cam.pos.y + crouch, cam.pos.z + 1, /* Look in the positive Z axis */
0, 1.0, 0);



That would take care of translation. The other part is created by modifying the up vector, which I usually just rotate after using a LookAt, but if you want, you can calculate it out as a combination of trig functions and a lot of math.

Hope this helps.

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!