Quaver

07-19-2013, 09:16 AM

I have this code to move my player:

const float DEGREE_RADIAN_MULTIPLIER = M_PI / 180;

const float RADIAN_RIGHT_ANGLE = M_PI / 2;

if(leftHeld) {

player.x += sin((player.xRotation * DEGREE_RADIAN_MULTIPLIER) - RADIAN_RIGHT_ANGLE) * MOVEMENT_AMP;

player.z += -cos((player.xRotation * DEGREE_RADIAN_MULTIPLIER) - RADIAN_RIGHT_ANGLE) * MOVEMENT_AMP;

}

if(rightHeld) {

player.x += sin((player.xRotation * DEGREE_RADIAN_MULTIPLIER) + RADIAN_RIGHT_ANGLE) * MOVEMENT_AMP;

player.z += -cos((player.xRotation * DEGREE_RADIAN_MULTIPLIER) + RADIAN_RIGHT_ANGLE) * MOVEMENT_AMP;

}

if(upHeld) {

player.x += sin(player.xRotation * DEGREE_RADIAN_MULTIPLIER) * MOVEMENT_AMP;

player.z += -cos(player.xRotation * DEGREE_RADIAN_MULTIPLIER) * MOVEMENT_AMP;

}

if(downHeld) {

player.x -= sin(player.xRotation * DEGREE_RADIAN_MULTIPLIER) * MOVEMENT_AMP;

player.z -= -cos(player.xRotation * DEGREE_RADIAN_MULTIPLIER) * MOVEMENT_AMP;

}

And it works, however for some odd reason my player seems to move faster when going right or left than when going straight or backwards.

There is no other code that changes my player's position so I figure that it must be to do with my perspective or camera or something, so here is the relevant code to that:

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 1024.0f);

gluLookAt(player.x, PLAYER_HEIGHT, player.z, (player.x + sin(player.xRotation * DEGREE_RADIAN_MULTIPLIER)), PLAYER_HEIGHT, (player.z + -cos(player.xRotation * DEGREE_RADIAN_MULTIPLIER)), 0.0f, 1.0f, 0.0f);

Any ideas as to what is causing this effect?

const float DEGREE_RADIAN_MULTIPLIER = M_PI / 180;

const float RADIAN_RIGHT_ANGLE = M_PI / 2;

if(leftHeld) {

player.x += sin((player.xRotation * DEGREE_RADIAN_MULTIPLIER) - RADIAN_RIGHT_ANGLE) * MOVEMENT_AMP;

player.z += -cos((player.xRotation * DEGREE_RADIAN_MULTIPLIER) - RADIAN_RIGHT_ANGLE) * MOVEMENT_AMP;

}

if(rightHeld) {

player.x += sin((player.xRotation * DEGREE_RADIAN_MULTIPLIER) + RADIAN_RIGHT_ANGLE) * MOVEMENT_AMP;

player.z += -cos((player.xRotation * DEGREE_RADIAN_MULTIPLIER) + RADIAN_RIGHT_ANGLE) * MOVEMENT_AMP;

}

if(upHeld) {

player.x += sin(player.xRotation * DEGREE_RADIAN_MULTIPLIER) * MOVEMENT_AMP;

player.z += -cos(player.xRotation * DEGREE_RADIAN_MULTIPLIER) * MOVEMENT_AMP;

}

if(downHeld) {

player.x -= sin(player.xRotation * DEGREE_RADIAN_MULTIPLIER) * MOVEMENT_AMP;

player.z -= -cos(player.xRotation * DEGREE_RADIAN_MULTIPLIER) * MOVEMENT_AMP;

}

And it works, however for some odd reason my player seems to move faster when going right or left than when going straight or backwards.

There is no other code that changes my player's position so I figure that it must be to do with my perspective or camera or something, so here is the relevant code to that:

glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 1024.0f);

gluLookAt(player.x, PLAYER_HEIGHT, player.z, (player.x + sin(player.xRotation * DEGREE_RADIAN_MULTIPLIER)), PLAYER_HEIGHT, (player.z + -cos(player.xRotation * DEGREE_RADIAN_MULTIPLIER)), 0.0f, 1.0f, 0.0f);

Any ideas as to what is causing this effect?