Skip to main content
added 347 characters in body
Source Link
Maik Semder
  • 4.7k
  • 1
  • 27
  • 24
I wonder if it's not a gimbal lock problem? But I use quaternions?

Yes, your code has a Gimbal Lock problem, since you use Euler Angles. There is a lot of myth out there about Gimbal Locks and how to prevent them. You can also have Gimbal Locks using quaternions, if you use them the way you do. The key is not to store the rotation around each axis separately and not to apply one after another, your code does it here:

    Quaternion additionalAircraftRotation = 
        Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), yokeUpDown) * 
        Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), yokeRightLeft) *
        Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), RollRotation);

    Quaternion additionalSphereRotation = 
        Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), sphereAngle.X) *  
        Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), sphereAngle.Y) * 
        Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), sphereAngle.Z);

The solution is not to use Euler Angles. {yokeUpDown, yokeRightLeft, RollRotation} and sphereAngle are Euler Angles. Rather store them as matrices or quaternions, basically any representation of orientation/rotation will do, except Euler Angles.

Also this code does not do what you want, you can't just add Euler-Angles to combine 2 rotations:

    // make vector3 sphere angle rotation
    sphereAngle.X = sphereAngle.X + yokeUpDown;
    sphereAngle.Y = sphereAngle.Y + yokeRightLeft;
    sphereAngle.Z = sphereAngle.Z + RollRotation;
I wonder if it's not a gimbal lock problem? But I use quaternions?

Yes, your code has a Gimbal Lock problem, since you use Euler Angles. There is a lot of myth out there about Gimbal Locks and how to prevent them. You can also have Gimbal Locks using quaternions, if you use them the way you do. The key is not to store the rotation around each axis separately and not to apply one after another, your code does it here:

Quaternion additionalAircraftRotation = 
    Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), yokeUpDown) * 
    Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), yokeRightLeft) *
    Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), RollRotation);

Quaternion additionalSphereRotation = 
    Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), sphereAngle.X) *  
    Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), sphereAngle.Y) * 
    Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), sphereAngle.Z);

The solution is not to use Euler Angles. {yokeUpDown, yokeRightLeft, RollRotation} and sphereAngle are Euler Angles. Rather store them as matrices or quaternions, basically any representation of orientation/rotation will do, except Euler Angles.

I wonder if it's not a gimbal lock problem? But I use quaternions?

Yes, your code has a Gimbal Lock problem, since you use Euler Angles. There is a lot of myth out there about Gimbal Locks and how to prevent them. You can also have Gimbal Locks using quaternions, if you use them the way you do. The key is not to store the rotation around each axis separately and not to apply one after another, your code does it here:

    Quaternion additionalAircraftRotation = 
        Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), yokeUpDown) * 
        Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), yokeRightLeft) *
        Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), RollRotation);

    Quaternion additionalSphereRotation = 
        Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), sphereAngle.X) *  
        Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), sphereAngle.Y) * 
        Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), sphereAngle.Z);

The solution is not to use Euler Angles. {yokeUpDown, yokeRightLeft, RollRotation} and sphereAngle are Euler Angles. Rather store them as matrices or quaternions, basically any representation of orientation/rotation will do, except Euler Angles.

Also this code does not do what you want, you can't just add Euler-Angles to combine 2 rotations:

    // make vector3 sphere angle rotation
    sphereAngle.X = sphereAngle.X + yokeUpDown;
    sphereAngle.Y = sphereAngle.Y + yokeRightLeft;
    sphereAngle.Z = sphereAngle.Z + RollRotation;
Source Link
Maik Semder
  • 4.7k
  • 1
  • 27
  • 24

I wonder if it's not a gimbal lock problem? But I use quaternions?

Yes, your code has a Gimbal Lock problem, since you use Euler Angles. There is a lot of myth out there about Gimbal Locks and how to prevent them. You can also have Gimbal Locks using quaternions, if you use them the way you do. The key is not to store the rotation around each axis separately and not to apply one after another, your code does it here:

Quaternion additionalAircraftRotation = 
    Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), yokeUpDown) * 
    Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), yokeRightLeft) *
    Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), RollRotation);

Quaternion additionalSphereRotation = 
    Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), sphereAngle.X) *  
    Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), sphereAngle.Y) * 
    Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), sphereAngle.Z);

The solution is not to use Euler Angles. {yokeUpDown, yokeRightLeft, RollRotation} and sphereAngle are Euler Angles. Rather store them as matrices or quaternions, basically any representation of orientation/rotation will do, except Euler Angles.