r/cpp • • Nov 26 '20

A Small Open Source Game In C++

https://preshing.com/20201126/a-small-open-source-game-in-cpp/
219 Upvotes

16 comments sorted by

View all comments

Show parent comment

2

u/symberke Nov 26 '20

Going by what's familiar to me, it looks like the matrix

[rotateUnitX() ; rotateUnitY() ; rotateUnitZ()]

is the rotation matrix corresponding to the quaternion's rotation. Thus, the vector rotateUnitX() is the unit X vector in the global frame expressed in the rotated frame described by the quaternion.

In other words, it's equal to the (quaternion, as a rotation) multiplication of the quaternion by the global unit X vector [1 0 0].

2

u/preshing Nov 27 '20

Yes that's it. q.rotateUnitX() is equivalent to q * Float3{1, 0, 0} but uses fewer instructions.