• 9
• 9
• 9
• 10
• 10

# Getting the Direction using Slerp

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

## Recommended Posts

Hello guys
Firstly,
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.
Trying it for a couple of hours without success....
Thanks
Jack

float startDir = m_cpf_path.at(pathIndex).dir;
float endDir = m_cpf_path.at(pathIndex + 1).dir;
D3DXQUATERNION startQuat;
D3DXQUATERNION endQuat;
D3DXQuaternionRotationAxis(&startQuat, &D3DXVECTOR3(0, 1, 0), startDir);
D3DXQuaternionRotationAxis(&endQuat, &D3DXVECTOR3(0, 1, 0), endDir);
D3DXQUATERNION instantQuat;
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 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

D3DXVec3TransformCoord(&m_LookAt,&D3DXVECTOR3(0,0,1),&m_RotationMatrix);



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

This method has always worked for me.