Original Post
So I'm trying to code a part of a 3d program that will eventually rotate the camera kinda of like any First Person Shooter would. I.E. you move the mouse up and the head moves up, you move the mouse down and the head moves down looking at the ground, you move the mouse left and the head turns to the left. Anyway you get the picture, I have the left and right movements perfected, and up and down work to an extent, but I've messed up some detail in the math and I can't quite figure out what the hell I've done wrong. For some reason when the player is looking up or down the head moves the opposite direction after spinning (turning left or right) about 90 degrees either direction from the start. Not sure what I messed up but here's the code:
The first call to rotate works without flaw, it's the second one that something has gone wrong in. Player.getRotX() get's the player's degrees of rotation about the Y axis (yes Y, because essentially they have rotated left or right), PIOVER180 is a constant that is essentially PI / 180. player.getHeadTilt() is the degrees of rotation about the X axis (so how far they have moved the head up or down). And obviously Math.abs is the absolute value function, Math.cos is the cosine function and Math.sin is the sine function. Can anyone point out the flaw, or possibly tell me why I should just trash that line and go with something else? Thanks
// Rotate the world in the opposite direction of player
glRotatef(-(player.getRotX() - 180), 0f, 1f, 0f);
glRotatef((player.getHeadTilt()), 1f - (float) Math.abs((Math.sin(player.getRotX() * PIOVER180))),
0f, 1f - (float) Math.abs((Math.cos(player.getRotX() * PIOVER180))));The first call to rotate works without flaw, it's the second one that something has gone wrong in. Player.getRotX() get's the player's degrees of rotation about the Y axis (yes Y, because essentially they have rotated left or right), PIOVER180 is a constant that is essentially PI / 180. player.getHeadTilt() is the degrees of rotation about the X axis (so how far they have moved the head up or down). And obviously Math.abs is the absolute value function, Math.cos is the cosine function and Math.sin is the sine function. Can anyone point out the flaw, or possibly tell me why I should just trash that line and go with something else? Thanks