0
\$\begingroup\$

I am working on FPS shooter example in Unreal engine 4 documentation.


One of the lines for forward movement of pawn is

FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);




This line gets the forward facing direction of the pawn in world coordinates. I understand that part.

I would like to know what is it mathematically and how does FRotationMatrix get values it gets? How does simple 3 valued vector like rotation get converted to a 4x4 matrix?

Can some one please help me understand.

\$\endgroup\$
3
\$\begingroup\$

Rotations are linear transformations, and linear transformations can be represented by matrices. The basic rotations about the X, Y and Z axes are considered well-known (although you can derive them if you want to understand them). "Well-known" in this case means we as game programmers mostly just accept them to be what they are as far as our code is concerned, and write functions that directly produce them for a given angle about a given axes.

To that end, FRotationMatrix is a FMatrix subclass that exists to facilitate constructing a matrix that represents a pure rotation with no translation or scale (which are also operations that can be encoded into a matrix).

It is constructed using an FRotator (in this case, the one from the player controller actor, Controller), which stores pitch, roll and yaw values. It uses those, ultimately, to construct a rotation matrix.

You could do the same thing yourself; pitch, roll and yaw just represent rotations around the Y, X and Z axes (in Unreal's coordinate system). You can build the three equivalent basic rotation matrices and then concatenate them to arrive at a result equivalent to what FRotationMatrix is computing.

\$\endgroup\$
  • \$\begingroup\$ thanks a lot! can you write a bit more on the last paragraph, on how I could arrive at result without the library functions? \$\endgroup\$ – Ramachandra Junior Jan 17 '18 at 8:03
  • \$\begingroup\$ Do you already understand how transformations are represented as matrices and how matrix multiplication works to concatenate transformations? \$\endgroup\$ – Josh Jan 17 '18 at 16:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.