Rotation: Eulers and Quaternions. - Gr8-Tools/game-developer-roadmap-doc GitHub Wiki
Total time: 4 hours
Rotation is a fundamental concept in game development, allowing objects in a virtual world to change their orientation. Two widely used representations for rotation are Euler angles and Quaternions. Both approaches have their own pros and cons, which we will explore in this article.
Subtopics and Definitions
- Euler Angles - Euler angles are a way to represent rotation using three separate angles, typically around the X, Y, and Z axes. These angles are measured in degrees or radians and can be visualized as a sequence of rotations around each axis.
- Quaternions - Quaternions are a four-dimensional mathematical representation of rotation. They consist of a scalar component (w) and a vector component (x, y, z). Quaternions have properties that make them particularly useful for interpolation and avoiding gimbal lock.
- Gimbal Lock - Gimbal lock is a phenomenon that occurs when using Euler angles, where two of the rotational axes align, causing a loss of one degree of freedom. This can result in unexpected and undesirable behavior during rotations.
Pros and Cons
- Pros of Euler Angles:
- Intuitive and easy to understand, representing rotations in a human-readable format.
- Suitable for simple applications and situations where precision is not critical.
- Efficient for certain calculations and transformations.
- Cons of Euler Angles:
- Prone to gimbal lock, which can lead to unexpected behavior.
- Difficult to interpolate between two Euler angle rotations.
- Can be challenging to work with in complex 3D rotations and hierarchical structures.
- Pros of Quaternions:
- Avoids gimbal lock and allows for smooth interpolation between rotations.
- Provides a compact representation and efficient mathematical operations.
- Suitable for complex 3D rotations and hierarchical structures.
- Cons of Quaternions:
- More difficult to understand and visualize compared to Euler angles.
- Require additional steps for conversion to and from Euler angles.
- Slightly more computationally expensive compared to Euler angles.
In conclusion, both Euler angles and Quaternions have their strengths and weaknesses when it comes to representing rotations in game development. While Euler angles are intuitive and easy to work with in simple scenarios, they are prone to gimbal lock and are less suitable for complex rotations. On the other hand, quaternions provide a robust solution for avoiding gimbal lock and interpolating between rotations, but they can be more difficult to understand and compute. The choice between Euler angles and quaternions depends on the specific requirements of the game and the desired trade-offs between simplicity and precision.
Additional Materials:
Video
- Euler vs Quaternions: Explain the difference between Euler and Quaternion
20 minutes
- Euler vs Quaternions: Direction vs Rotation: One more explanation the difference between Euler and Quaternion
20 minutes
Tasks
Cube-game
The following tasks extend current game experience in our "Cube"-competitor game (where we trying achieve as more goals as we can)
- Change navigation system in your competition-game from task Unity Game Engine: Get started: let it rotate around with keys 'A' and 'D' to the left and right, and the only keys 'W' and 'S' will move the object. Set up camera at "first-person" mode.
Self task time: 1.5 hour
Spend some time to refactor your code: make attempts to build your own code architecture with splitting responsibilities to different classes. Refactor time: 2 hours.