I want my animated meshs head to follow a postion,this is the code I have but it dosent seem to be working as expected
can anyone help?
// Start by transforming to local space
D3DXMATRIX Local;
D3DXMatrixInverse(&Local, NULL, &m_pHeadBone->CombinedTransformationMatrix);
static float PosZ = 5.0f; PosZ += 10.1f;
D3DXVECTOR3 Pos(0.0f,0.0f,PosZ);
//angle we want to look at
D3DXVECTOR3 boneVec3;
D3DXVECTOR3 boneSrc(Local._41,Local._42,Local._43);
D3DXVec3TransformCoord(&boneVec3,&boneSrc,&m_pHeadBone->CombinedTransformationMatrix);
D3DXVECTOR3 LookVec = Pos - boneVec3;
D3DXVec3Normalize(&LookVec,&LookVec);
D3DXMatrixRotationX(&Yaw,atan2(LookVec.x,LookVec.z));
m_pHeadBone->CombinedTransformationMatrix = Yaw * m_pHeadBone->CombinedTransformationMatrix;