# Orientation: Getting there, but....

This topic is 2386 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

 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); } 

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
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
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
 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); } 

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
OK Now thanks guys
I changed the line from
 world = world * mat; 
to
 world = mat * world; 
and it seems to be working.
Thanks
Jack