Hi all,
I am trying to get a camera to rotate around an object. I have used the base camera class from UltimateGamesProgramming.com
It works okay in a limited context, but if the camera moves to the right(while still looking at one object) the up direction of (0,1,0) is no longer valid.
Instead of the camera going over the object, it goes sideways and skewy.
The code I have is to try and get the up key to rotate over the object no matter what the orientation is.
When the key is press I do this to get the 'up' vector.
dir = Microsoft.DirectX.Vector3.Cross(new Microsoft.DirectX.Vector3(0,1,0),this.m_VecCamPos);
RotateCamAroundPoint(1f,dir)
and the actual rotation method RotateCamAroundPoint is
private void RotateCamAroundPoint(float Angle, Microsoft.DirectX.Vector3 Direction)
{
Microsoft.DirectX.Quaternion qRotation = new Microsoft.DirectX.Quaternion(0,0,0,0);
qRotation.RotateAxis(Direction,Microsoft.DirectX.Direct3D.Geometry.DegreeToRadian(Angle));
Microsoft.DirectX.Quaternion qView = new Microsoft.DirectX.Quaternion();
qView.X = this.m_VecCamPos.X - this.m_VecCamLook.X;
qView.Y = this.m_VecCamPos.Y - this.m_VecCamLook.Y;
qView.Z = this.m_VecCamPos.Z - this.m_VecCamLook.Z;
qView.W = 0;
Microsoft.DirectX.Quaternion qNewView = new Microsoft.DirectX.Quaternion();
Microsoft.DirectX.Quaternion qTmp = new Microsoft.DirectX.Quaternion();
qTmp = Microsoft.DirectX.Quaternion.Multiply(qRotation, qView);
qNewView = Microsoft.DirectX.Quaternion.Multiply(qTmp,Microsoft.DirectX.Quaternion.Conjugate(qRotation));
Microsoft.DirectX.Vector3 tmp = this.m_VecCamPos;
this.m_VecCamPos.X = this.m_VecCamLook.X + qNewView.X;
this.m_VecCamPos.Y = this.m_VecCamLook.Y + qNewView.Y;
this.m_VecCamPos.Z = this.m_VecCamLook.Z + qNewView.Z;
}
This works well until the camera is parallel to (0,1,0)
I just can't work out what I need to do.
Ideally I would like the dir vector to represent a vector that is perpendicular to the looking vector. That way the angle between the two will always be 90 degrees and the camera will never become parallel.
phew, I hope i've explained it ok.
Any pointers would be much appreciated.
Cheers
DRB2k2