Skip to content

Engine → Core

glm_types.h

The engine's vector, quaternion and matrix types are glm's. This is the single public header through which glm reaches the rest of the engine; glm is configured by the build with GLM_FORCE_RADIANS, GLM_FORCE_DEPTH_ZERO_TO_ONE, GLM_ENABLE_EXPERIMENTAL and GLM_FORCE_EXPLICIT_CTOR, so write vec3(0.0f), never vec3 value = 0.0f.

Structs

File Description
std::formatter<conjure::math::ivec2>
std::formatter<conjure::math::ivec3>
std::formatter<conjure::math::ivec4>
std::formatter<conjure::math::mat3>
std::formatter<conjure::math::mat4>
std::formatter<conjure::math::quat>
std::formatter<conjure::math::uvec2>
std::formatter<conjure::math::uvec3>
std::formatter<conjure::math::uvec4>
std::formatter<conjure::math::vec2>
std::formatter<conjure::math::vec3>
std::formatter<conjure::math::vec4>

Type Aliases

ivec2

using ivec2 = glm::ivec2;

ivec3

using ivec3 = glm::ivec3;

ivec4

using ivec4 = glm::ivec4;

mat3

using mat3 = glm::mat3;

mat4

using mat4 = glm::mat4;

quat

using quat = glm::quat;

uvec2

using uvec2 = glm::uvec2;

uvec3

using uvec3 = glm::uvec3;

uvec4

using uvec4 = glm::uvec4;

vec2

using vec2 = glm::vec2;

vec3

using vec3 = glm::vec3;

vec4

using vec4 = glm::vec4;

Functions

Public

detail::format_components

template <typename ComponentType, typename FormatContext> typename FormatContext::iterator format_components( const std::formatter<ComponentType> &componentFormatter, std::span<const ComponentType> components, FormatContext &context );

Writes "(c0, c1, ...)" applying one component formatter (which already parsed the format spec) to every component.

nearly_equal

[[nodiscard]] inline bool nearly_equal(
    const vec2 &a,
    const vec2 &b,
    f32 epsilon = EPSILON) noexcept;

True when every component of a is within epsilon of the matching component of b.

[[nodiscard]] inline bool nearly_equal(
    const vec3 &a,
    const vec3 &b,
    f32 epsilon = EPSILON) noexcept;

True when every component of a is within epsilon of the matching component of b.

[[nodiscard]] inline bool nearly_equal(
    const vec4 &a,
    const vec4 &b,
    f32 epsilon = EPSILON) noexcept;

True when every component of a is within epsilon of the matching component of b.

[[nodiscard]] inline bool nearly_equal(
    const quat &a,
    const quat &b,
    f32 epsilon = EPSILON) noexcept;

True when every component of a is within epsilon of the matching component of b. Note that q and -q are different quaternions here although they encode the same rotation; use same_rotation() to compare rotations.

[[nodiscard]] inline bool nearly_equal(
    const mat3 &a,
    const mat3 &b,
    f32 epsilon = EPSILON) noexcept;

True when every element of a is within epsilon of the matching element of b.

[[nodiscard]] inline bool nearly_equal(
    const mat4 &a,
    const mat4 &b,
    f32 epsilon = EPSILON) noexcept;

True when every element of a is within epsilon of the matching element of b.

nearly_zero

[[nodiscard]] inline bool nearly_zero(
    const vec3 &value,
    f32 epsilon = EPSILON) noexcept;

True when the vector's length is at most epsilon.

[[nodiscard]] inline bool nearly_zero(
    const vec2 &value,
    f32 epsilon = EPSILON) noexcept;

True when the vector's length is at most epsilon.

safe_normalize

[[nodiscard]] inline vec3 safe_normalize(
    const vec3 &value,
    const vec3 &fallback = vec3(0.0f, 0.0f, -1.0f)) noexcept;

Normalises the vector, or returns fallback when its length is (nearly) zero. glm::normalize would produce NaN there.

[[nodiscard]] inline vec2 safe_normalize(
    const vec2 &value,
    const vec2 &fallback = vec2(1.0f, 0.0f)) noexcept;

Normalises the vector, or returns fallback when its length is (nearly) zero.

same_rotation

[[nodiscard]] inline bool same_rotation(
    const quat &a,
    const quat &b,
    f32 epsilon = EPSILON) noexcept;

True when two unit quaternions encode the same rotation within epsilon. q and -q are one rotation, so b is negated first when its dot product with a is negative; then every component of a must be within epsilon of the matching component of b, the tolerance nearly_equal() uses. In angles, for a small epsilon: two rotations up to 2 * epsilon radians apart compare equal, two more than about 4 * epsilon radians apart do not, and in between it depends on the axis. Float rounding of the inputs comes on top, so an epsilon near 1e-7 only accepts quaternions equal to the last bit or two.