Skip to content

Transform2

A 2D transformation class supporting translation, scaling, and rotation.

Internally manages position, scale, rotation, and center of transformation. Lazily computes the final transformation matrix when accessed.

Properties

center Vector2

cpp
Vector2 center { 0.0f, 0.0f }

Pivot for rotation and scaling.

position Vector2

cpp
Vector2 position { 0.0f, 0.0f }

World-space translation.

rotation float

cpp
float rotation { 0.0f }

Rotation angle in radians.

scale Vector2

cpp
Vector2 scale { 1.0f, 1.0f }

Local scale.

touched bool

cpp
bool touched { true }

Indicates whether the transformation matrix needs to be recomputed.

Functions

Get() auto

cpp
auto vglx::Transform2::Get()

Returns the 3x3 transformation matrix. Lazily recomputes the matrix if any component has changed since last access.

Rotate() auto

cpp
auto vglx::Transform2::Rotate(float angle)
ParameterDescription
angleRotation angle in radians.

Applies a rotation delta to the current rotation.

Scale() auto

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

Applies a scale to the current scale.

SetCenter() auto

cpp
auto vglx::Transform2::SetCenter(const Vector2 &center)
ParameterDescription
centerPivot point in local space.

Sets the pivot point for rotation and scaling.

SetPosition() auto

cpp
auto vglx::Transform2::SetPosition(const Vector2 &position)
ParameterDescription
positionNew position vector.

Sets the world position of the transform.

SetRotation() auto

cpp
auto vglx::Transform2::SetRotation(float rotation)
ParameterDescription
rotationRotation angle in radians.

Sets the rotation angle of the transform.

SetScale() auto

cpp
auto vglx::Transform2::SetScale(const Vector2 &scale)
ParameterDescription
scaleNew scale vector.

Sets the local scale of the transform.

Translate() auto

cpp
auto vglx::Transform2::Translate(const Vector2 &value)
ParameterDescription
valueTranslation vector.

Applies a translation in local space. If rotation is non-zero, the translation is rotated accordingly.

Released under the MIT License.