Transform class

A class that represents a 3D transformation; it can store the same information as a 4x4 matrix, but it's easier to use.

This class stores the location, scale and rotation (as a 3x3 matrix) separately, making it a lot easier to use than a matrix. It has a method to convert it to a 4x4 matrix, so that it can be used in matematical operations. Transforms can be multiplied in order to concatenate multiple transformations using Multiply(other)

Public types

enum TransformFlags { kTransformFlagScale = 1, kTransformFlagRotation = 2, kTransformFlagOffset = 4 }

Constructors, destructors, conversion operators

Transform()

Public functions

auto GetOffset() const -> const Vector3&
auto SetOffset(const Vector3& value) -> Transform&
auto SetOffset(float x, float y, float z) -> Transform&
auto GetScale() const -> float
auto SetScale(float value) -> Transform&
auto GetRotation() const -> const Matrix3&
auto SetRotation(const Matrix3& value) -> Transform&
auto SetRotation(const Vector3& euler) -> Transform&
auto SetRotation(const Quaternion& value) -> Transform&
auto ToMatrix4() const -> Matrix4
Returns the 4x4 matrix that represents this transform.
auto Multiply(const Transform& other) -> Transform&
Applies another transform into this transform.
void Invert()
Inverts this transform, so that now it will do exactly the opposite transformation.

Protected variables

int16_t mnFlags
int16_t mnTransformCount
Vector3 mOffset
float mfScale
Matrix3 mRotation

Function documentation

Matrix4 Transform::ToMatrix4() const

Returns the 4x4 matrix that represents this transform.

This matrix can be used to apply the transform to vectors, by just multiplying.

Transform& Transform::Multiply(const Transform& other)

Applies another transform into this transform.

Parameters
other

void Transform::Invert()

Inverts this transform, so that now it will do exactly the opposite transformation.

A transform multiplied by its inverse results in the identity transform, which doesn't change anything.