#### Archived

This topic is now archived and is closed to further replies.

# OpenGL OpenGL Rotation Question

This topic is 6667 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 learning OpenGL from the Red Book. I''ve been making simple 3-d worlds, however I can''t work out how to turn left or right. The only way I came change direction is by rotating the entire world around the y-axis. However when I do this, the entire world rotates around (0,0,0) and hence when the player is far away from the entire of the map, the ground moves from under the player''s feet because the player is just rotating around (0,0,0) at a constant radius. What''s the easiest method of rotating the view from any particular position on the map?? Thanks, Pointed (aka Evan Clark)

##### Share on other sites
Rotate around the y-axis in the opposite direction then translate in the opposite direction. Here''s how I implemented movement in one of my programs:

// camera definitions
float xrot = 0.0f;
float yrot = -135.0f;
float zrot = 0.0f;

float xpos = 1.5f;
float ypos = 1.0f;
float zpos = 6.0f;

if(keyboard_state[DIK_RIGHT])
yrot -= 0.5f;
if(keyboard_state[DIK_LEFT])
yrot += 0.5f;

if(keyboard_state[DIK_Z])
xrot -= 0.5f;
if(keyboard_state[DIK_A])
xrot += 0.5f;

if(keyboard_state[DIK_UP])
{
}

if(keyboard_state[DIK_DOWN])
{
}

glRotatef(-xrot, 1.0f, 0.0f, 0.0f);
glRotatef(-yrot, 0.0f, 1.0f, 0.0f);
glTranslatef(-xpos, -ypos, -zpos);

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

• 33
• 13
• 10
• 10
• 12
• ### Forum Statistics

• Total Topics
632568
• Total Posts
3007119

×