My Journey into the Fundamentals of Computer Graphics - Part 4

My Journey into the Fundamentals of Computer Graphics - Part 4

The Quaternion Menace

Overview

Hi everyone! This week I continued my journey into the fundamentals of computer graphics by learning the basics of quaternions! They are an advanced math concept and I didn't completely grasp everything. However, I think that the introduction that I had will be fine for my current level. Let's go straight into my discoveries of the week!

Top 3 things I learned

Quaternions aren't the solution to all your rotational problems

Usually, when you start learning about quaternions, it's easy to fall into the misconception that they can just be used for everything that involves rotations and you won't have any problems. However, this isn't the case. Quaternions are just one of several tools for representing orientations and should be used after careful consideration of their advantages & disadvantages. I actually had a great discussion about this in my post last week in the Dev.to community, which you can read here. This was specifically regarding the use of matrices vs. quaternions, so a big shoutout to Thibaut for making all these clarifications!

Here is a comparison of the methods covered in the 3D Math Primer book:

Don't neglect polar coordinates!

Even though polar coordinates might look weird or scary at first sight, you definitely should learn how to use them and when. The authors of 3D Math Primer describe how they're actually the coordinate system that we use most of the time when having an informal conversation! For the specific purposes of video games, they are very useful when aiming a camera, weapon or any other object at some target.

Understand the rotation conventions of your game engine

Whenever you need to implement rotations in any aspect of a game that you're developing, you must have a good understanding of the conventions used by the game engine that you're using. It's important to remember that each game engine, and 3D software in general, follows their own convention regarding how they handle coordinate systems, so it's no surprise that they each have their conventions for rotations. A great example of this difference in conventions comes from this image created by @FreyaHolmer:

When it comes to rotation conventions, I just did a quick research online on the 3 game engines that I plan on using while learning about shaders. I'll leave the explanation of why I'll be using 3 game engines instead of just focusing on one for another day but I can tell you that Unity's reveal of their new pricing plan last week had some input in that decision. Anyway, here's what I found:

  • Unity: The order "YXZ" is used locally and "ZXY" is used in world space.

  • Unreal Engine: The order is roll, pitch, yaw, which would mean "XYZ" in Unreal's coordinate system convention.

  • Godot: The default order is "YXZ", although you can change this.

The first thing that I noticed after my quick research, is that the conventions used aren't very clear to understand by just reading them. So I'll follow up on this later in my journey when I start using rotations in each of these engines.

This week's math concepts

Polar Coordinate Systems

I learned about the importance of using this coordinate system, as mentioned in the previous section. Besides, I learned conversions in 2D coordinate space and in 3D with cylindrical coordinates & spherical coordinates.

Rotation in Three Dimensions

I learned how to represent orientations, including the advantages & disadvantages, of these 4 methods:

  • Matrices

  • Euler Angles

  • Exponential Map & Axis-Angle Representations

  • Quaternions

Useful resources

This week's resources are for people who are interested in learning more about quaternions:

What's next

After covering most of the math fundamentals in both of the books I'm reading, I'll finally start having an introduction to the render pipeline & shader programming. Meanwhile, I invite you to tell me if you've had to use quaternions before!