# Orientation: Getting there, but....

## Recommended Posts

lucky6969b    1330
[code]
D3DXMATRIX mat;
if (m_Path.size() >1)
{
float angle2 = atan2(m_Path[m_count+1].z-m_Path[m_count].z, -(m_Path[m_count+1].x-m_Path[m_count].x)) + D3DX_PI * 0.5f;

D3DXMatrixRotationY(&mat, angle2);
}
[/code]

Most of the times it is correct, but sometimes it is going reverse! Anyone sheds some lights on this!
Thanks in advance and thanks many of you for your continued help...
Jack

##### Share on other sites
Six222    453
Forgive me if i'm wrong but, all trig functions output results between -1 and 1 so you need to check when your value gets < 0 you need to inverse the rotation?

EDIT: fail... *all trig functions

##### Share on other sites
lucky6969b    1330
Hi Six222,
Thanks for your response, you are correct I think. But I still come across a problem
I added 4 lines to the source code
[code]
D3DXMATRIX mat;
if (m_Path.size() > 1)
{
float angle2 = atan2(m_Path[m_count+1].z-m_Path[m_count].z, -(m_Path[m_count+1].x-m_Path[m_count].x)) + D3DX_PI * 0.5f;

if (angle2 < 0.0f)
{
angle2 += 2 * D3DX_PI;
}

D3DXMatrixRotationY(&mat, angle2);
}

[/code]

some of the stuff just still going in reverse or sometimes sideways. You may assume the pathfinder is heading the objects forward.
As I observed so far, It happens only when the object is moving from the bottom right to the upper left.
It doesn't happen in other directions. Let's say +ve Z points into (up) the screen, and -ve down (out of) the screen
The error probably lies in the 2nd quadrant of the rotation.
Thanks
Jack

##### Share on other sites
lucky6969b    1330
OK Now thanks guys
I changed the line from
[code]
world = world * mat;
[/code]
to
[code]
world = mat * world;
[/code]
and it seems to be working.
Thanks
Jack