# 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.

## 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 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 tofloat rotationAngle = (yAngle - 90.0f);//this may be wrong (depends on your needs)xPos += (secondsPassed * speed * (dcos(rotationAngle)));zPos += (secondsPassed * speed * (dsin(rotationAngle)));

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632595
• Total Posts
3007266

×