Skip to content

Transform2

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

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

Properties

center Vector2

Pivot point for rotation and scaling.

cpp
Vector2 center {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();

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.

SetCenter() void

Sets the pivot point used for rotation and scaling.

cpp
void Transform2::SetCenter(const Vector2& center);
ParameterDescription
centerNew 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.