Jump to content
  • Advertisement
Sign in to follow this  

Getting the Direction using Slerp

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys
The model I am using has the front facing the positive x,
with the local and world axis aligned which are also pointing positively to +x
For the code snippet below,
the direction obtained from the cpf_path is correct only when
I don't use spherical interpolation for the Quaternions
Say on reaching the goal, the agent is facing 1.57 in DirectX convention.
When I did the following, the agent is sliding sideways.
So the dirs are correct even though the code snippet below isn't.
Please help me fixing this code...
Trying it for a couple of hours without success....


float startDir = m_cpf_path.at(pathIndex).dir;
float endDir = m_cpf_path.at(pathIndex + 1).dir;
D3DXQuaternionRotationAxis(&startQuat, &D3DXVECTOR3(0, 1, 0), startDir);
D3DXQuaternionRotationAxis(&endQuat, &D3DXVECTOR3(0, 1, 0), endDir);
D3DXQuaternionSlerp(&instantQuat, &startQuat, &endQuat, m_fS);
D3DXMATRIX instantMat;
D3DXMatrixRotationQuaternion(&instantMat, &instantQuat);                        
D3DXVECTOR3 instantVec = GetLookVector(instantMat);                        
xRot = instantVec.x;
D3DXVECTOR3 GetLookVector(const D3DXMATRIX& matWorld) // Also called Forward vector or Direction vector, this is the vector from the object's world matrix
    return D3DXVECTOR3(matWorld._13, matWorld._23, matWorld._33);
Edited by lucky6969b

Share this post

Link to post
Share on other sites

I am assuming you are doing some kind of flight...... I rotate using a quaternion and then get the look-at using:

	D3DXQuaternionNormalize(&rotQuat, &rotQuat);
    D3DXMatrixRotationQuaternion(&m_viewMatrix, &rotQuat);
    m_viewMatrix(3,0) =0;
    m_viewMatrix(3,1) =0;
    m_viewMatrix(3,2) =0;
	D3DXMatrixInverse(&m_RotationMatrix,0,&m_viewMatrix);//for space flight 


As you can see, I use z+ as my origin direction......


This method has always worked for me.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!