Skip to content

Engine → Core → transform.h

transform

Syntax

struct CONJURE_API transform

Variables

AccessNameTypeDefaultDescription
publicpositionvec3vec3(0.0f)
publicrotationquatquat(1.0f, 0.0f, 0.0f, 0.0f)
publicscalevec3vec3(1.0f)

Functions

Public

forward

[[nodiscard]] vec3 forward() const noexcept;

The rotated -Z axis.

from_matrix

[[nodiscard]] static transform from_matrix(
    const mat4 &matrix) noexcept;

Decomposes a TRS matrix (no shear). A negative determinant (mirroring) is expressed as a negative x scale; a zero-length axis yields a zero scale on that axis and the identity direction for its rotation column.

from_position

[[nodiscard]] static transform from_position(
    vec3 value) noexcept;

A transform with only a position.

from_rotation

[[nodiscard]] static transform from_rotation(
    quat value) noexcept;

A transform with only a rotation.

from_scale

[[nodiscard]] static transform from_scale(
    vec3 value) noexcept;

A transform with only a scale.

inverse

[[nodiscard]] transform inverse() const noexcept;

The transform that undoes this one: inverse() * (*this) is the identity for every transform, and inverse().to_matrix() equals glm::inverse(to_matrix()) when the scale is uniform. A (nearly) zero scale component inverts to zero instead of infinity.

inverse_transform_direction

[[nodiscard]] vec3 inverse_transform_direction(
    vec3 direction) const noexcept;

Rotates a direction from the parent space back into local space.

inverse_transform_point

[[nodiscard]] vec3 inverse_transform_point(
    vec3 point) const noexcept;

Maps a point from the parent space back into this transform's local space; exact for every scale (the exact inverse of transform_point, including non-uniform scale).

lerp

[[nodiscard]] static transform lerp(
    const transform &a,
    const transform &b,
    f32 t) noexcept;

Interpolates position and scale linearly and the rotation by shortest-path slerp. t is not clamped (like math::lerp): values outside [0, 1] extrapolate.

look_at

[[nodiscard]] static transform look_at(
    vec3 eye,
    vec3 target,
    vec3 upHint) noexcept;

A transform at eye whose forward() points at target with the given up hint and unit scale. A target equal to eye keeps the identity rotation; an up hint parallel to the view direction (or zero) is replaced by the world axis least aligned with the direction so the result is always a valid rotation.

right

[[nodiscard]] vec3 right() const noexcept;

The rotated +X axis.

to_matrix

[[nodiscard]] mat4 to_matrix() const noexcept;

The 4x4 matrix translate(position) * rotate(rotation) * scale(scale).

transform_direction

[[nodiscard]] vec3 transform_direction(
    vec3 direction) const noexcept;

Applies only the rotation to a direction (no scale, no translation).

transform_point

[[nodiscard]] vec3 transform_point(
    vec3 point) const noexcept;

Applies scale, rotation and translation to a point in this transform's local space.

up

[[nodiscard]] vec3 up() const noexcept;

The rotated +Y axis.

Operator Overloads

Public

operator*

[[nodiscard]] transform operator*(
    const transform &child) const noexcept;

Composes parent * child: the child expressed in the parent's space is moved into the parent's parent space. Equals from_matrix(to_matrix() * child.to_matrix()) exactly when the parent scale is uniform or the child rotation is the identity.

operator==

[[nodiscard]] bool operator==(
    const transform &other) const = default;