I was experiencing gimbal lock with using RotateX*RotateY*RotateZ, so i switched to quaternion's and i'm still having the same problem when i'm trying to rotate my mesh.
here is my code:
Quaternion rotquaternion = EulerToQuaternion(Geometry.DegreeToRadian(m_YAngle),
Geometry.DegreeToRadian(m_XAngle),Geometry.DegreeToRadian(m_ZAngle));
device.Transform.World = Matrix.RotationQuaternion(rotquaternion);
m_XAngle, m_YAngle, m_ZAngle are incremented by the delta of the mouse movement. I only increment one of the angles at a time, i choose that angle by having a radio button to select whether to rotate around the X,Y, or Z axis.
Here is my code for the EulerToQuaternion method.
private Quaternion EulerToQuaternion(float yaw, float pitch, float roll)
{
float cr, cp, cy, sr, sp, sy, cpcy, spsy;
cy = (float)Math.Cos(yaw/2);
cp = (float)Math.Cos(pitch/2);
cr = (float)Math.Cos(roll/2);
sy = (float)Math.Sin(yaw/2);
sp = (float)Math.Sin(pitch/2);
sr = (float)Math.Sin(roll/2);
cpcy = cp * cy;
spsy = sp * sy;
float w = cr * cpcy + sr * spsy;
float x = cr * sp * cy - sr * cp * sy;
float y = cr * cp * sy + sr * sp * cy;
float z = sr * cpcy - cr * spsy;
Quaternion retval = new Quaternion(x,y,z,w);
return retval;
}
When my mesh is initially displayed i can rotate around any of the axis properly, but if i move around the X axis 270 deg. and the Y axis 270 deg. my X and Z movement until i move my Y axis again are around the same axis. What am I don't wrong? I've been struggling with this for days with a variety of Quaternion and Matrix calculations, and can't seem to get past this gimbal lock.