Module fyrox::scene::transform

source ·
Expand description

Contains all structures and methods to create and manage 3D transforms.

Transform allows you to combine spatial properties into a single matrix in an easy manner. It contains many methods that can be used to modify a single property of a transform which then will be “baked” into the single matrix.

§Complexity

Fyrox uses a complex transform model inherited from the FBX transform formulae:

Transform = T * Roff * Rp * Rpre * R * Rpost * Rp⁻¹ * Soff * Sp * S * Sp⁻¹

where
T - Translation
Roff - Rotation offset
Rp - Rotation pivot
Rpre - Pre-rotation
R - Rotation
Rpost - Post-rotation
Rp⁻¹ - Inverse of the rotation pivot
Soff - Scaling offset
Sp - Scaling pivot
S - Scaling
Sp⁻¹ - Inverse of the scaling pivot

It is very flexible, however it can be slow to computate. To solve possible performance issues, Fyrox tries to precache every possible component. This means that we use lazy evaluation: you can setup all the required properties, and the actual calculations will be delayed until you try to get the matrix from the transform. This makes calculations faster, but increases the required amount of memory.

In most cases you don’t need to worry about all those properties, you need just T, R, S - those will cover 99% of your requirements.

Fun fact: the transform format was dictated by the use of the monster called FBX file format. Some libraries (like assimp) decompose this complex formula into a set of smaller transforms which contain only T R S components and then combine them to get the final result, I find this approach very bug prone and it is still heavy from a computation perspective. It is much easier to use it as is.

§Decomposition

Once the transform is baked into a matrix, it is almost impossible to decompose it back into its initial components, thats why the engine does not provide any methods to get those properties back.

Structs§

  • See module docs.
  • Transform builder allows you to construct transform in declarative manner. This is typical implementation of Builder pattern.