Jump to content
  • Advertisement

Archived

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

Bruno

quake movement

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

Hello I have a problem I'' tryng to implement a movement similar to quake, half-life and family, but i need help. In this case, when the player press forward or back, i make a translation of 10 or -10 while the key is pressed, and it''s all fine. When i press the left or right key to rotate, the camera also rotates in the direction that i wan''t, but she rotates as if the camera was still in the origin(0,0,0). typedef struct{ float x; float y; float z; float xrot; float yrot; float zrot; }camera; camera look; when i press forward, i add the look.x 10 units when i press back i subtract look.x 10 units when i press left, i add the angle +10; when i press right i subtract the angle -10; glLoadIdentity(); glTranslatef(look.x,look.y,look.z); glRotatef(angle,0,look.yrot,0); If i make the translation first and then the rotation, the rotation works fine, but only if i still hadn''t pressed the forward button If i press the forward button first, and then the left or right, the rotation is not correct, he rotates as if the rotation was being made at the origin. Please advice Thanks Bruno

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Care to share your solution with us??

Protozone

Share this post


Link to post
Share on other sites
Check the directx/opengl forum, here in gamedev.net.
I''ve posted the same question there...

Bruno

Share this post


Link to post
Share on other sites
Here''s how I implemented it in my program.


// rotate the camera in conjunction with the mouse movement
if(mouse_state.lY)
xrot -= (float)mouse_state.lY*0.025;

// rotate the camera in conjunction with the mouse movement
if(mouse_state.lX)
yrot -= (float)mouse_state.lX*0.025;

// if the LEFT or RIGHT key is pressed rotate the camera accordingly
if(keyboard_state[DIK_LEFT])
yrot += 0.5f;
if(keyboard_state[DIK_RIGHT])
yrot -= 0.5;

// if the A or Z key is pressed rotate the camera accordingly
if(keyboard_state[DIK_A])
xrot += 0.5f;
if(keyboard_state[DIK_Z])
xrot -= 0.5f;

// if key UP translate all objects in the direction the cameras facing
if(keyboard_state[DIK_UP])
{
xpos += (float)sin(yrot*degreesToRadians)*0.05f;
zpos += (float)cos(yrot*degreesToRadians)*0.05f;
}

// if key DOWN translate all objects in the direction the cameras facing
if(keyboard_state[DIK_DOWN])
{
xpos -= (float)sin(yrot*degreesToRadians)*0.05f;
zpos -= (float)cos(yrot*degreesToRadians)*0.05f;
}

// rotate all the objects
glRotatef(-xrot,1.0f,0.0f,0.0f);
glRotatef(-yrot,0.0f,1.0f,0.0f);

// translate all the objects
glTranslatef(xpos,-1.0f,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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!