View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# screwed up movement angles

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1ic0de  Members

Posted 14 September 2012 - 07:49 PM

I've been using the standard way of moving a first person camera for a while but I'm getting a slight error that I either never noticed before or has just appeared. Here is my code:

float yrotrad = (ry / 180 * PI);

if(to.z != 0)
{
}
ry is the rotation captured from mouse input in degrees
vel is a 3d vector that gets sent to my physics engine, it is the camera's velocity
to is another vector telling the camera which way to move in object space, -1 is backwards and +1 is forwards
PI is obviously equal to 3.14159

The trouble I'm getting is that my object is moving about 45 degrees right of the direction its supposed to be going. Any ideas why?
Currently working on new DOS game, Chuck Jones: Space Cop of the Future, Check out my Dev Blog

you know you program too much when you start ending sentences with semicolons;

### #2DishSoap  Members

Posted 15 September 2012 - 10:57 AM

How exactly are you calculating ry? I don't really see anything wrong with your math so I'm not quite sure what is causing the 45 degree discrepancy, so it may be that. I use this quick method to calculate the direction of my camera.

[source lang="cpp"] horizontalAngle += mouseSpeed * float(ScreenWidth / 2 - xpos ); verticalAngle += mouseSpeed * float(ScreenHeight / 2 - ypos ); [/source]

Where mouseSpeed is some small floating point number(something like .005f) and xpos and ypos is your mouses x and y coordinates (Note: In this example my X axis is right to left and my Y axis is up and down. Judging from your vel.x and vel.z calculations your Z axis appears to be up and down while your Y is right to left). Then to calculate direction just use your found angles to convert from spherical coordinates to Cartesian as you do.

[source lang="cpp"]vec3 direction( cos(verticalAngle) * sin(horizontalAngle), // X-Axis left to right sin(verticalAngle), // Y-Axis up and down cos(verticalAngle) * cos(horizontalAngle) // Z-Axis in and out of screen);[/source]

You can restrict any look directions as you see fit.

Then when moving the camera you can just use position += direction*deltatime*speed and position -= direction*deltatime*speed or something similar to move forward and backward. So when you make your view matrix you can just add your direction vector to your position vector to find your "look at" vector. I hope that helped!

### #3ic0de  Members

Posted 15 September 2012 - 05:50 PM

Thanks for the reply I actually sat down after posting with some graph paper and a protractor and couldn't find any error with the math. ry is 0.8 times the number of pixels the mouse moved in one frame. This discrepancy must be coming from the physics engine (bullet) or my calculation of ry.
Currently working on new DOS game, Chuck Jones: Space Cop of the Future, Check out my Dev Blog

you know you program too much when you start ending sentences with semicolons;

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.