Extract vector from rotation matrix

Hi everyone,

I’m looking to build a vector pointing in the direction my object is facing; this will be used to move the object in that direction over a time period. I have a 4x4 rotation matrix describing the orientation of the object, and I want to get that orientation as a unit vector (vec3 ideally) from the origin of the object so I can add this times by a deltaTime to simulate a motion. I’m having trouble getting this vector, and also wondering in fact if this is the correct way to go about things. Does have anyone have any thoughts on this?

If you multiply an abritrary vector with the upper left 3x3 sub part (the rotation and scaling part) of the object-to-world 4x4 matrix, the object-to-world
rotation is applied to the given vector.

So multiplying (0,0,1,0) with the 4x4 object-to-world matrix of your object, gives you the direction of the object local Z axis in world coordinates.
If you think about it, you realize that this returns the third column of the matrix. If you take a column-major 3x3 matrix, expressing an object-to-world
rotation, the 1st column is the direction of the local X axis in world coordinates, the second the Y-axis and the third the Z axis.