Jump to content
  • Advertisement
Sign in to follow this  

Using glRotate and glTranslate

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

Hi, I've been modifying my books application so that I now can move along the x and z axis with the a, d, s and w keys. I want to be aible to rotate around the y axis as well with left and right arrow. This is what I've done: glRotatef(yAngle, 0.0f, 1.0f, 0.0f); glTranslatef(xPos, 0.0f, zPos); and it works in a way, except for one important thing. When I use glRotate, the axises does not follow the rotation (that's what I want). So that if I rotate 30 degrees to the left (forexample) the x-axis will still be to the left/right side of the camera. And of course the negative z-axis in front and positive in the back. I want this so that when I move using the glTranslate it will always move to the right/left or ahead/back of the camera. I hope you understand my question ;)

Share this post

Link to post
Share on other sites
Easy enough to do.

//general things that help:
#define RADIANS 57.295779513082320876798154814105f
//convert to radians
#define toRads(degs) ((degs) / RADIANS)
//degree functions:
#define dsin(degs) sin(toRads(degs))
#define dcos(degs) cos(toRads(degs))
#define dtan(degs) tan(toRads(degs))

//when you're updating your position:
float secondsPassed;//you'll need to set this yourself (should be positive)
float speed = 1.0f;//change this if you need to
float rotationAngle = (yAngle - 90.0f);//this may be wrong (depends on your needs)
xPos += (secondsPassed * speed * (dcos(rotationAngle)));
zPos += (secondsPassed * speed * (dsin(rotationAngle)));

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!