Skip to content

Transform3

3D affine transform with position, rotation, and scale.

Transform3 represents a 3D transform combining translation, non-uniform scaling, and quaternion-based rotation. It lazily builds a Matrix4 suitable for use as a world transform in scene graphs and rendering code.

Properties

position Vector3

Translation in 3D space.

cpp
Vector3 position {0.0f};

rotation Quaternion

Rotation stored as a unit quaternion.

cpp
Quaternion rotation {};

scale Vector3

Non-uniform scale in 3D.

cpp
Vector3 scale {1.0f};

touched bool

Dirty flag indicating the cached matrix needs to be recomputed.

cpp
bool touched {true};

Functions

Get() Matrix4

Returns the 4×4 transform matrix.

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

cpp
Matrix4 Transform3::Get();

GetEuler() Euler

Returns the rotation as Euler angles.

Provided as a convenience for inspection; the conversion is lossy near gimbal lock and only resolves angles within the Euler reconstruction range. The quaternion remains the authoritative representation.

cpp
Euler Transform3::GetEuler() const;

LookAt() void

Sets the rotation such that the object looks at a target point.

Computes an orientation that looks from position toward target, using world_up to resolve roll and construct a stable basis.

cpp
void Transform3::LookAt(const Vector3& position, const Vector3& target, const Vector3& world_up);
ParameterDescription
positionObject position.
targetTarget point to look at.
world_upWorld up direction.

Rotate() void

Applies an additional rotation around an axis in local space.

The rotation is composed after the current orientation, so the axis is interpreted in the transform's local frame.

cpp
void Transform3::Rotate(const Vector3& axis, float angle);
ParameterDescription
axisRotation axis; normalized internally.
angleRotation angle in radians.

Scale() void

Scales the transform.

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

SetPosition() void

Sets the translation component.

cpp
void Transform3::SetPosition(const Vector3& position);
ParameterDescription
positionNew position.

SetRotation() void

Sets the rotation component from Euler angles.

Provided as a convenience; the angles are converted to and stored as a quaternion.

cpp
void Transform3::SetRotation(const Euler& rotation);
ParameterDescription
rotationNew Euler rotation.

SetRotation() void

Sets the rotation component.

cpp
void Transform3::SetRotation(const Quaternion& rotation);
ParameterDescription
rotationNew rotation quaternion.

SetScale() void

Sets the scale component.

cpp
void Transform3::SetScale(const Vector3& scale);
ParameterDescription
scaleNew scale factors.

Translate() void

Translates the transform a distance along an axis in local space.

Convenience overload mirroring Rotate. The axis is normalized internally, so distance is a true distance along it. For an arbitrary offset, use the single-vector overload instead.

cpp
void Transform3::Translate(const Vector3& axis, float distance);
ParameterDescription
axisTranslation axis; normalized internally.
distanceDistance to translate along the axis.

Translate() void

Translates the transform in local space.

If the rotation is not empty, the input vector is rotated by the current orientation before being added to position.

cpp
void Transform3::Translate(const Vector3& value);
ParameterDescription
valueTranslation vector.

Released under the MIT License.