Hey all.
I'm starting a small test app to test out atan2 to rotate object's facing directions. I normaly use the dotproduct and the cross to get a signed angle
to pass to a direct X rotateY axis, This works fine.
But I can not figure out how to do the same with atan2, I've tryed in the passed and just gave up and used the above method.
This time I googled all I could and tryed a number of post methods but am still unable to rotate the object to the correct direction.
Going by this link Wiki atan2.
For any real number (e.g., floating point) arguments x and y not both equal to zero, atan2(y, x) is the angle in radians between the positive x-axis of a plane and the point given by the coordinates (x, y) on it. The angle is positive for counter-clockwise angles (upper half-plane, y > 0), and negative for clockwise angles (lower half-plane, y < 0).
Using the following I was able to map out the quadrant.
.
Angle = atan2(y, x);
if(Angle < 0.0)
{
--side;
}
else
{
++side;
}
That looks like this.
Going by that above. I have a object that starts at 3d(0,0,0) and it has 4 way points to move to
waypoint[0](-400,0,400)
waypoint[1](400,0,400)
waypoint[2](400,0,-400)
waypoint[3](-400,0,-400)
The tank has this facing direction.
.
Now the field is mapped out on the X, Z plane with Y+ up.
Depending on the direction if its post - target or target - pos as well as the params passed to atan2() Z,X, or X,Z
I get the following atan2 mapping.
.
.
.
.
.
Ive tryed adding 90° and - 90°, in fact Ive tryed all the ways the numerous post on the net have it layed out.
So what do I need to map my Z+ facing tank to atan2.
the following works but I would like to do the same as this with atan2.
.
D3DXVECTOR3 objfacing= D3DXVECTOR3(0.0, 0.0, 1.0);
D3DXVECTOR3 currentdir = m_vHeading;//current travel heading
FLOAT dot = D3DXVec3Dot(¤tdir, &objfacing);
double Angle = acos(dot);
if(dot < 0.0)
Angle*=-1;
D3DXMatrixRotationY(&Rotation, Angle);