Skip to content

Transform2 ​

2D affine transform with position, rotation, scale, and pivot.

Transform2 represents a 2D transform that combines translation, rotation, and non-uniform scaling around an arbitrary pivot point. It lazily builds a Matrix3 suitable for use in 2D rendering pipelines and UI layouts.

Properties ​

pivot Vector2 ​

Pivot point for rotation and scaling, in local units.

For a texture transform the units are texture coordinates, so (0.5, 0.5) is the middle of the texture. For a canvas node the units are pixels.

cpp
Vector2 pivot {0.0f, 0.0f};

position Vector2 ​

Translation in 2D space.

cpp
Vector2 position {0.0f, 0.0f};

rotation float ​

Rotation angle in radians.

cpp
float rotation {0.0f};

scale Vector2 ​

Non-uniform scale in 2D.

cpp
Vector2 scale {1.0f, 1.0f};

touched bool ​

Dirty flag indicating the cached matrix needs to be recomputed.

cpp
bool touched {true};

Functions ​

Get() Matrix3 ​

Returns the 3×3 transform matrix.

Recomputes the underlying matrix if any component has changed since the last call, then returns the cached Matrix3.

cpp
Matrix3 Transform2::Get();

Get() Matrix3 ​

Returns the 3×3 transform matrix without updating the cache.

Computes the matrix on the fly if any component has changed since the last update, otherwise returns the cached Matrix3. The touched flag is not cleared, so a later non-const call still refreshes the cache.

cpp
Matrix3 Transform2::Get() const;

Rotate() void ​

Applies an additional rotation.

cpp
void Transform2::Rotate(float angle);
ParameterDescription
angleRotation angle in radians to add.

Scale() void ​

Scales the transform.

cpp
void Transform2::Scale(const Vector2& value);
ParameterDescription
valueScale factors to apply.

SetPivot() void ​

Sets the pivot point used for rotation and scaling.

cpp
void Transform2::SetPivot(const Vector2& pivot);
ParameterDescription
pivotNew pivot point.

SetPosition() void ​

Sets the translation component.

cpp
void Transform2::SetPosition(const Vector2& position);
ParameterDescription
positionNew position.

SetRotation() void ​

Sets the rotation component.

cpp
void Transform2::SetRotation(float rotation);
ParameterDescription
rotationNew rotation angle in radians.

SetScale() void ​

Sets the scale component.

cpp
void Transform2::SetScale(const Vector2& scale);
ParameterDescription
scaleNew scale factors.

Translate() void ​

Translates the transform in local space.

The input vector is rotated by the current rotation before being added to position.

cpp
void Transform2::Translate(const Vector2& value);
ParameterDescription
valueTranslation vector.

Released under the MIT License.