This is an old revision of the document!


General

Unity uses 3 rotation systems. Intro to Quaternion Rotations (in Unity)

  1. Euler Angers - rotation about x, y, z axis
  2. Angle Axis - A normalized Vector3 representing the axis about which to rotate by float angle amount
  3. Quaternions - Angle Axis rotation representation that have been scaled to improve performance.

Quaternions

They are in the form of x, y, z, w. They are always normalized, so x² + y² + z² + w² = 0

Convertions

// Convert from Quaternion to Euler:
Vector3 inEuler = quaternionRotation.eulerAngles;
 
// Convert Euler to Quaternion
Quaternion inQuaternion = Quaternion.Euler(inEuler);
 
// To Angle-Axis
Quaternion randomQuaternion = Random.rotation;
float angle;
Vector3 axis;
 
randomQuaternion.ToAngleAxis(out angle, out axis);
 
// And back
Quaternion rotation = Quaternion.AngleAxis(angle,axis);
  • general.1586542408.txt.gz
  • Last modified: 2020/04/10 18:13
  • by paul