Sign in to follow this  
lucky6969b

Orientation: Getting there, but....

Recommended Posts

[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 this post


Link to post
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 this post


Link to post
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
[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 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