Thanks all for the responses.
I did exactly what you said Bob partly from other sites and partly from just figuring it out myself from my knowledge of vector operations.
Big problem. It seems that Euler orientations are not unique. In other words if my spaceship is point at a planet and my yaw and pitch are 0.0f and 0.0f that orientation is not unique. It is possible to yaw and pitch all over the place and point back at the planet...and the yaw and pitch are not 0.0f 0.0f. But the formula I'm using always calculates the yaw and pitch to be 0.0f.
Here is what I'm doing:
Code:
void CCamera::RotateTo(D3DXVECTOR3 vecTarget)
{
//vecTarget must share origin with camera vector
D3DXVECTOR3 toTarget=vecTarget-Pos;
D3DXVec3Normalize(&toTarget,&toTarget);
//Normalize camera look
D3DXVECTOR3 nLook;
D3DXVec3Normalize(&nLook,&Look);
//Cross product is axis of rotation
D3DXVec3Cross(&m_vecAxis,&toTarget,&nLook);
//Dot product is cos of angle of rotation
m_fAxisAngle=D3DXVec3Dot(&toTarget,&nLook);
//Construct axis angle rotation matrix
D3DXMATRIX T;
D3DXMatrixRotationAxis(&T,&m_vecAxis,m_fAxisAngle);
//Now extract yaw, pitch, roll from T and rotate
YPRFromRotMatrix(T,m_vecTargYPR.x,m_vecTargYPR.y,m_vecTargYPR.z);
//Find difference between current YPR and new YPR to face object
D3DXVECTOR3 diff;
diff.x=m_vecTargYPR.x-m_fYaw;
diff.y=m_vecTargYPR.y-m_fPitch;
diff.z=0.0f;
m_vecRotInc=diff;
//Test code to 'snap' to new orientation
//Yaw(m_vecTargYPR.x-m_fYaw);
//Pitch(m_vecTargYPR.y-m_fPitch);
}
So you see I'm doing exactly what everyone has shown. My problem is this. How do I transform my up,look, and right vectors to represent the new rotation? If the up, right, and look vectors are not altered in my camera class there is no rotation. I can create a matrix to do the rotation but I'm not sure what to do then?
Code:
D3DXVec3TransformCoord(&Up,&Up,&NewMatrix);
D3DXVec3TransformCoord(&Look,&Look,&NewMatrix);
D3DXVec3TransformCoord(&Right,&Right,&NewMatrix);
Since I'm not sure this works what I did was create the new axis-angle rotation matrix and then proceed to extract the yaw and pitch from the matrix. Roll is pretty much a moot point in this so I don't use it.
Using this the spacecraft does not always point at the same place. So when I want to turn to 0.0f,0.0f,0.0f it should be the same exact spot on the skysphere. It's not and often times it's way off.