Jump to content
  • Advertisement

Archived

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

Pointed

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.

If you intended to correct an error in the post then please contact us.

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 this post


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

const float DEGTORAD = 0.0174532925199432957692369076848f;

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])
{
xpos -= sinf(yrot*DEGTORAD) * 0.05f;
zpos -= cosf(yrot*DEGTORAD) * 0.05f;
}

if(keyboard_state[DIK_DOWN])
{
xpos += sinf(yrot*DEGTORAD) * 0.05f;
zpos += cosf(yrot*DEGTORAD) * 0.05f;
}

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

Share this post


Link to post
Share on other sites

  • 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!