Sign in to follow this  
matthughson

Dot Product - Craps Out At 0 and 180 Degrees

Recommended Posts

Hey Gang, The project I'm working on uses a mouse cursor's position to determine the direction to fire a bullet. Think FPS controls in a 2D game. Here's the problem. I want my projectiles to rotate to face the direction they are being shot in. I'm doing this by getting the Dot Product between the missle's direction and the missle's direction with no rotation. I've already realized that radians do not account for rotation over 180 degrees, but I was able to get passed that by checking the direction of the missle, and flipping it if needed. That all seems to work fine, except when the angle of the missle approaches 0 and 180 degrees. It seems to have a sort of 'dead-zone' where it stops incrementing the angle between the vectors. Here are the macro functions I'm using to convert between radians and degrees (incase the problem is there):
#define DEG2RAD(x) (x * (D3DX_PI / 180.0f)) // Converts degrees to radians
#define RAD2DEG(x) (x * (180.0f / D3DX_PI)) // Converts radians to degrees
Has anyone run into this, or have a possible solution for me? Thanks again all! Matt Hughson

Share this post


Link to post
Share on other sites
Quote:
Original post by matthughson
I've already realized that radians do not account for rotation over 180 degrees


Radians are just an alternate measurement scale for angles. There is no limit to the angle representable in radians.

Your problem is most likely due to a CrossProduct operation in your code. The cross product of two parallel vectors is (0,0,0). Your vectors will be parallel when the angle between them is either 0 or 180.

My guess is that you are trying to normalise the cross product of two parallel vectors thus causing a divide by zero error.

Share this post


Link to post
Share on other sites
Whats wrong with 2pi radians? that equals 360 degrees. Radians are not capped.

The dot product of orthogonal, or parallel vectors, will be 0. You must watch out for this.

Share this post


Link to post
Share on other sites
Quote:
Original post by davidx9
The dot product of orthogonal, or parallel vectors, will be 0. You must watch out for this.


That's not the problem. Its not that it suddenly jumps back to a rotation of 0 when the vectors are parallel. Its that for about 20 degrees surrounding straight up and straight down the angle stops getting larger or smaller. It just seems to lock.

Matt Hughson

Share this post


Link to post
Share on other sites
The Dot Product is not your angle - it's the cosine of your angle. That's why it only handles 180 degrees before wrapping. If you take the arcosine and take sidedness into account you can get the angle. If that's working, then look at your rotation code.

Hope that helps.

Tom

Share this post


Link to post
Share on other sites
There is another way where you have a castian (?) cordinate ( x, y, z ) and you can simply convert that into sphereical cordinates and maybe make a quaternion from that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Axiverse
There is another way where you have a castian (?) cordinate ( x, y, z ) and you can simply convert that into sphereical cordinates and maybe make a quaternion from that.

cartesian coordinate

Share this post


Link to post
Share on other sites
Quote:
Original post by ParadigmShift
The Dot Product is not your angle - it's the cosine of your angle. That's why it only handles 180 degrees before wrapping. If you take the arcosine and take sidedness into account you can get the angle. If that's working, then look at your rotation code.

Hope that helps.

Tom


Awesome dude! Thanks for the help dude. I'll give that a try in the morning.

Matt Hughson

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this