I want to add an euler angle to an existing quaternion. Here is what i got:
Quaternion oldTransform = transform.Rotation;
float YawRotation = mouseDiff.x * RotationSpeed;
Quaternion YawRotationQuaternion = new Quaternion();
YawRotationQuaternion.CreateFromAxisAngle (0, 1, 0, YawRotation);
float PitchRotation = mouseDiff.y * RotationSpeed;
Quaternion PitchRotationQuaternion = new Quaternion();
PitchRotationQuaternion.CreateFromAxisAngle ( 1, 0, 0, PitchRotation);
Quaternion result = oldTransform * YawRotationQuaternion * PitchRotationQuaternion;
transform.Rotation = result;
I want to have only yaw and pitch rotation. The old transform has this property. My euler angles I add to it are also only pitch and yaw rotations. What happens when i multiply it is that the rotation that oldTransform describes introduces a roll rotation.
Then i tried:
Quaternion result = YawRotationQuaternion * oldTransform * PitchRotationQuaternion;
This introduces no roll rotation. This option is even worse as it has a gimbal lock when oldTransform rotates the yaw-axis onto the pitch-axis.
Now what I could imagine is that one gets the old yaw and pitch rotation from the oldTransform and modifies the yaw and pitch-axis so that they are not (0,1,0) and (1,0,0) anymore. The problem here is that when I extract the euler angles from the quaternion I get gimbal locks as well.
So how do you add an euler angle of a specific axis to a quaternion?