🔒 Locked
moving problem
Advertisement
Original Post
i want the player to move forward at the current angle and i could think of how to do it. i want to know how would i move it up the right amout on the y and the x i have no idea how to do this.
note that in JUNC''s posting angle MUST be in radians...if angle is in degrees:
x'' = x + cos( angle *PI/180) * speed
y'' = y + sin( angle *PI/180) * speed
(dont forget to define PI)
x'' = x + cos( angle *PI/180) * speed
y'' = y + sin( angle *PI/180) * speed
(dont forget to define PI)
do you save your camera as position & angles
or a matrix ?
or a matrix ?
My fps-style camera has a vector center, "head" direction basis (three orthogonal vectors) and three Euler angles representing orientation relative to "head" direction (strafe vs look). I used quaternion for orientation at some point, but Euler angles are easier to constrain, since in FPS you don''t really have 6 DOF.
i save it as position and angle also this equation doesn''t work properly
x'' = x + cos( angle *PI/180) * speed
y'' = y + sin( angle *PI/180) * speed
if i hold down up and spin the camera it just goes up and down the y axis.
x'' = x + cos( angle *PI/180) * speed
y'' = y + sin( angle *PI/180) * speed
if i hold down up and spin the camera it just goes up and down the y axis.
but i want to translate camera?
//declare these variables
float rot=0; //angle
float px=0.0; //player x
float pz=0.0; //player z
double R=3.141593/180.0f; //radians to degrees
//before drawing each frame, do this:
glLoadIdentity();
glRotatef(rot,0.0f,1.0f,0.0f);
glTranslatef(px,-5.0f,pz);
//when checking for input
if(key[VK_LEFT]==true) {rot=rot-10;
if(rot<0) rot=rot+360;}
if(key[VK_RIGHT]==true) {rot=rot+10;
if(rot>3600) rot=rot-360;}
if(key[VK_UP]==true) {
px=px-sin(rot*R)*1.0); //1.0=speed
pz=pz+cos(rot*R)*1.0);
if(key[VK_DOWN]==true) {
px=px-sin(rot*R)*-1.0); //-1.0=speed
pz=pz+cos(rot*R)*-1.0);
float rot=0; //angle
float px=0.0; //player x
float pz=0.0; //player z
double R=3.141593/180.0f; //radians to degrees
//before drawing each frame, do this:
glLoadIdentity();
glRotatef(rot,0.0f,1.0f,0.0f);
glTranslatef(px,-5.0f,pz);
//when checking for input
if(key[VK_LEFT]==true) {rot=rot-10;
if(rot<0) rot=rot+360;}
if(key[VK_RIGHT]==true) {rot=rot+10;
if(rot>3600) rot=rot-360;}
if(key[VK_UP]==true) {
px=px-sin(rot*R)*1.0); //1.0=speed
pz=pz+cos(rot*R)*1.0);
if(key[VK_DOWN]==true) {
px=px-sin(rot*R)*-1.0); //-1.0=speed
pz=pz+cos(rot*R)*-1.0);
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement