Advertisement

quake movement

Started by May 17, 2000 09:50 AM
3 comments, last by Bruno 24 years, 6 months ago
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
i have solved my problem
thanks anyway
Advertisement
Care to share your solution with us??

Protozone
Check the directx/opengl forum, here in gamedev.net.
I''ve posted the same question there...

Bruno
Here''s how I implemented it in my program.

// rotate the camera in conjunction with the mouse movementif(mouse_state.lY)	xrot -= (float)mouse_state.lY*0.025;// rotate the camera in conjunction with the mouse movementif(mouse_state.lX)	yrot -= (float)mouse_state.lX*0.025;// if the LEFT or RIGHT key is pressed rotate the camera accordinglyif(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 accordinglyif(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 facingif(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 facingif(keyboard_state[DIK_DOWN]){			xpos -= (float)sin(yrot*degreesToRadians)*0.05f;	zpos -= (float)cos(yrot*degreesToRadians)*0.05f;}// rotate all the objectsglRotatef(-xrot,1.0f,0.0f,0.0f);glRotatef(-yrot,0.0f,1.0f,0.0f);	// translate all the objectsglTranslatef(xpos,-1.0f,zpos);    
"I have realised that maths can explain everything. How it can is unimportant, I want to know why." -Me

This topic is closed to new replies.

Advertisement