Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
general [2020/04/10 18:08] paul [Rotations] |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== General ====== | ||
- | |||
- | ===== Rotations ===== | ||
- | Unity uses 3 rotation systems. | ||
- | |||
- | - Euler Angers - rotation about x, y, z axis | ||
- | - Angle Axis - A normalized Vector3 representing the axis about which to rotate by float angle amount | ||
- | - Quaternions | ||
- | |||
- | |||
- | <code c#> | ||
- | // 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, | ||
- | </ | ||