Skip to main content

math Namespace

Mathematical operations and types. More...

Definition

namespace helios::math { ... }

Namespaces Index

namespaceconcepts

Mathematical concepts for type constraints. More...

namespacetransform

Transformation utilities for 3D graphics and scene graph inheritance. More...

namespacetypes

Vector and matrix types. More...

Classes Index

structaabb<T>

Axis-Aligned Bounding Box for spatial culling and collision detection. More...

structmat4<T>

Represents a 4x4 matrix, stored in column-major order. More...

structvec3<T>

Represents a 3-dimensional vector of the generic type <T>. More...

structvec2<T>

Represents a 2-dimensional vector of the generic type <T>. More...

structvec4<T>

Represents a 4-dimensional vector of the generic type <T>. More...

Typedefs Index

template <typename T>
usingFloatingPointType = std::conditional_t< std::is_floating_point_v< T >, T, double >

Type trait that promotes integral types to double, while preserving floating-point types. More...

usingaabbf = aabb< float >

Single-precision floating-point AABB. More...

usingaabbi = aabb< int >

Integer AABB. More...

usingaabbui = aabb< unsigned int >

Unsigned Integer AABB. More...

usingaabbd = aabb< double >

Double-precision floating-point AABB. More...

usingmat4f = mat4< float >

Type alias for a 4x4 float matrix. More...

usingmat4d = mat4< double >

Type alias for a 4x4 double matrix. More...

usingmat4i = mat4< int >

Type alias for a 4x4 integer matrix. More...

usingvec2f = vec2< float >
usingvec2d = vec2< double >
usingvec2i = vec2< int >
usingvec2ui = vec2< unsigned int >
usingvec3f = vec3< float >

Single-precision floating-point 3D vector. More...

usingvec3i = vec3< int >

Integer 3D vector. More...

usingvec3d = vec3< double >

Double-precision floating-point 3D vector. More...

usingvec4f = vec4< float >

Single-precision floating-point 4D vector. More...

usingvec4d = vec4< double >

Double-precision floating-point 4D vector. More...

usingvec4i = vec4< int >

Integer 4D vector. More...

Enumerations Index

enum classTransformType : uint8_t { ... }

Bitmask enum controlling which transform components a child node inherits from its parent. More...

Operators Index

TransformTypeoperator| (TransformType a, TransformType b)

Combines two Inherit flags using bitwise OR. More...

template <typename T>
constexpr auto operator+ (const helios::math::aabb< T > aabb, const helios::math::vec3< T > v) noexcept -> helios::math::aabb< T >

Adds a translation vector to an AABB. More...

template <typename T>
constexpr auto operator* (const helios::math::aabb< T > &aabb, const helios::math::vec3< T > v) noexcept -> helios::math::aabb< T >

Scales an AABB by a given vector. More...

template <helios::math::Numeric T>
constexpr auto operator* (const vec2< T > &v, const T n) noexcept -> vec2< T >

Multiplies a 2D vector by a scalar value. More...

template <helios::math::Numeric T>
constexpr auto operator* (const vec3< T > &v, const T n) noexcept -> vec3< T >

Multiplies a 3D vector by a scalar value. More...

template <helios::math::Numeric T>
constexpr auto operator/ (const vec3< T > &v, T s) noexcept -> vec3< T >

Divides a 3D vector by a scalar value. More...

template <helios::math::Numeric T>
constexpr auto operator* (const T n, const vec3< T > &v) noexcept -> vec3< T >

Multiplies a scalar value by a 3D vector. More...

template <helios::math::Numeric T>
constexpr auto operator* (const vec3< T > &v1, const vec3< T > &v2) noexcept -> vec3< T >

Multiplies two vectors componentwise. More...

template <helios::math::Numeric T>
constexpr auto operator+ (const vec3< T > &v1, const vec3< T > &v2) noexcept -> vec3< T >

Calculates the componentwise sum of the two vectors. More...

template <helios::math::Numeric T>
constexpr auto operator- (const vec3< T > &v1, const vec3< T > &v2) noexcept -> vec3< T >

Computes the difference between two vectors (vector subtraction). More...

Functions Index

mat4fperspective (float fovY, float aspect, float zNear, float zFar) noexcept

Computes the 4x4 perspective projection matrix based on the specified field of view, aspect ratio, and near and far clipping planes. More...

mat4fortho (const float left, const float right, const float bottom, const float top, const float zNear=0.1f, const float zFar=100.0f) noexcept

Computes the 4x4 orthographic projection matrix. More...

mat4flookAt (const vec3f &eye, const vec3f &center, const vec3f &up) noexcept

Returns the 4x4 lookAt-matrix for transforming world coordinates to camera space. The method creates the camera coordinate system based on the parameters eye, i.e. the vantage point in world space, the camera's up direction and center, representing the point of interest. Note that the returned matrix is essentially a composition of a change of coordinates matrix P(C <- W) and a translation to the origin, i.e. the camera is sitting at the origin (0, 0, 0) looking down the negative z-axis, i.e. conceptually. More...

mat4frotate (const mat4f &model, float radians, const vec3f &axis) noexcept

Creates an affine rotation matrix R' = M * R by "baking" the rotation part into the model matrix. Any operation R' * v will make sure that v is rotated around the local origin, then transformed into world space. More...

constexpr mat4ftranslate (const mat4f &model, const vec3f &v) noexcept

Creates an affine transformation matrix M' = M * T by "baking" the translation part into the model matrix. Any operation M' * v will make sure that v is translated in local space, then transformed into world space. More...

constexpr mat4fscale (const mat4f &model, const vec3f &v) noexcept

Creates an affine transformation matrix S' = M * S by ""baking" the scaling part into the model matrix. Any operation S' * v will make sure that v is scaled in local space, then transformed into world space. More...

constexpr mat4fscale (const mat4f &model, const float scale_by) noexcept

Creates an affine transformation matrix S' = M * S by "baking" the scaling part into the model matrix. Any operation S' * v will make sure that v is scaled in local space, then transformed into world space. More...

booltransformTypeMatch (TransformType mask, TransformType flag)

Checks if a specific inheritance flag is set in a mask. More...

template <typename T>
constexpr auto overlap (const helios::math::aabb< T > a, const helios::math::aabb< T > b) noexcept -> helios::math::vec3< T >

Computes the signed dimensions of the overlapping region between two axis-aligned bounding boxes (AABBs). More...

template <typename T>
constexpr auto overlapCenter (const helios::math::aabb< T > a, const helios::math::aabb< T > b) noexcept -> helios::math::vec3< T >

Computes the center of intersection of the overlapping region between two axis-aligned bounding boxes (AABBs). More...

template <helios::math::Numeric T>
const T *value_ptr (const mat4< T > &m) noexcept

Returns a const pointer to the first element of the matrix's components. More...

template <helios::math::Numeric T>
T *value_ptr (mat4< T > &m) noexcept

Returns a pointer to the first element of the matrix's components. More...

template <helios::math::Numeric T>
constexpr Tdot (const vec2< T > &v1, const vec2< T > &v2) noexcept

Computes the dot product of two 2D vectors. More...

template <helios::math::Numeric T>
constexpr auto cross (const vec3< T > &v1, const vec3< T > &v2) noexcept -> vec3< T >

Computes the cross product of two 3D vectors. More...

template <helios::math::Numeric T>
constexpr Tdot (const vec3< T > &v1, const vec3< T > &v2) noexcept

Computes the dot product of two 3D vectors. More...

template <helios::math::Numeric T>
const T *value_ptr (const vec4< T > &m) noexcept

Returns a const pointer to the first element of the vector's components. More...

constexpr floatradians (const float angle) noexcept

Converts an angle from degrees to radians. More...

constexpr floatdegrees (const float radians) noexcept

Converts an angle from radians to degrees. More...

Variables Index

constexpr vec3fX_AXISf {1.0f, 0.0f, 0.0f}

Unit vector along the positive X-axis (1, 0, 0). More...

constexpr vec3fY_AXISf {0.0f, 1.0f, 0.0f}

Unit vector along the positive Y-axis (0, 1, 0). More...

constexpr vec3fZ_AXISf {0.0f, 0.0f, 1.0f}

Unit vector along the positive Z-axis (0, 0, 1). More...

constexpr floatEPSILON_LENGTH = 1e-6f

A small epsilon value used for length-based comparisons. More...

Description

Mathematical operations and types.

This namespace provides comprehensive mathematical functionality including vector and matrix types, transformation utilities, mathematical concepts, and utility functions for 3D graphics and game framework computations. Provides all mathematical operations required for 3D graphics, including transformations, projections, and spatial computations.

Typedefs

aabbd

using helios::math::aabbd = aabb<double>

Double-precision floating-point AABB.

Definition at line 387 of file aabb.ixx.

aabbf

using helios::math::aabbf = aabb<float>

Single-precision floating-point AABB.

Definition at line 372 of file aabb.ixx.

aabbi

using helios::math::aabbi = aabb<int>

Integer AABB.

Definition at line 377 of file aabb.ixx.

aabbui

using helios::math::aabbui = aabb<unsigned int>

Unsigned Integer AABB.

Definition at line 382 of file aabb.ixx.

FloatingPointType

template <typename T>
using helios::math::FloatingPointType = std::conditional_t< std::is_floating_point_v<T>, T, double >

Type trait that promotes integral types to double, while preserving floating-point types.

Template Parameters
T

the input type

Definition at line 18 of file FloatingPointTypeTrait.ixx.

18 using FloatingPointType = std::conditional_t<

mat4d

using helios::math::mat4d = mat4<double>

Type alias for a 4x4 double matrix.

Definition at line 539 of file mat4.ixx.

mat4f

using helios::math::mat4f = mat4<float>

Type alias for a 4x4 float matrix.

Definition at line 534 of file mat4.ixx.

mat4i

using helios::math::mat4i = mat4<int>

Type alias for a 4x4 integer matrix.

Definition at line 544 of file mat4.ixx.

vec2d

using helios::math::vec2d = vec2<double>

Definition at line 208 of file vec2.ixx.

vec2f

using helios::math::vec2f = vec2<float>

Definition at line 207 of file vec2.ixx.

vec2i

using helios::math::vec2i = vec2<int>

Definition at line 209 of file vec2.ixx.

vec2ui

using helios::math::vec2ui = vec2<unsigned int>

Definition at line 210 of file vec2.ixx.

vec3d

using helios::math::vec3d = vec3<double>

Double-precision floating-point 3D vector.

Definition at line 463 of file vec3.ixx.

vec3f

using helios::math::vec3f = vec3<float>

Single-precision floating-point 3D vector.

Definition at line 453 of file vec3.ixx.

vec3i

using helios::math::vec3i = vec3<int>

Integer 3D vector.

Definition at line 458 of file vec3.ixx.

vec4d

using helios::math::vec4d = vec4<double>

Double-precision floating-point 4D vector.

Definition at line 176 of file vec4.ixx.

vec4f

using helios::math::vec4f = vec4<float>

Single-precision floating-point 4D vector.

Definition at line 171 of file vec4.ixx.

vec4i

using helios::math::vec4i = vec4<int>

Integer 4D vector.

Definition at line 181 of file vec4.ixx.

Enumerations

TransformType

enum class helios::math::TransformType : uint8_t
strong

Bitmask enum controlling which transform components a child node inherits from its parent.

Enumeration values
TranslationInherit only the translation component from the parent (= 1 << 0)
RotationInherit only the rotation component from the parent (= 1 << 1)
ScaleInherit only the scale component from the parent (= 1 << 2)
AllInherit all transform components (Translation, Rotation, Scale) (= Translation | Rotation | Scale)

When a SceneNode is attached to a parent, its final world transform is computed by combining the parent's world transform with the child's local transform. The `Inherit` flags determine which components (Translation, Rotation, Scale) of the parent transform are applied to the child.

This enables flexible scene graph behaviors such as:

  • A camera that follows an object's position but maintains its own orientation (`TransformType::Translation`)
  • UI elements that inherit full transforms (`TransformType::All`)
  • Objects that only inherit rotation for billboard effects (`TransformType::Rotation`)

Example usage: ```cpp using namespace helios::math;

// Camera follows spaceship position only cameraNode->setInheritance(TransformType::Translation);

// Full transform inheritance (default) childNode->setInheritance(TransformType::All);

// Combine specific flags node->setInheritance(TransformType::Translation | TransformType::Rotation); ```

Definition at line 41 of file TransformType.ixx.

41 enum class TransformType : uint8_t {
42 /**
43 * @brief Inherit only the translation component from the parent.
44 *
45 * The child's world position is offset by the parent's world position,
46 * but rotation and scale remain unaffected by the parent.
47 */
48 Translation = 1 << 0,
49
50 /**
51 * @brief Inherit only the rotation component from the parent.
52 *
53 * The child's orientation is combined with the parent's orientation,
54 * but position and scale remain unaffected.
55 */
56 Rotation = 1 << 1,
57
58 /**
59 * @brief Inherit only the scale component from the parent.
60 *
61 * The child's scale is multiplied by the parent's scale,
62 * but position and rotation remain unaffected.
63 */
64 Scale = 1 << 2,
65
66 /**
67 * @brief Inherit all transform components (Translation, Rotation, Scale).
68 *
69 * This is the default behavior where the child's world transform is
70 * the full composition of parent and local transforms.
71 */
73 };

Operators

operator-()

template <helios::math::Numeric T>
vec3< T > helios::math::operator- (const vec3< T > & v1, const vec3< T > & v2)
constexpr noexcept

Computes the difference between two vectors (vector subtraction).

Template Parameters
T

The numeric type of the vector components.

Parameters
v1

The first vec3<T> vector.

v2

The second vec3<T> vector.

Returns

A new vec3<T> instance representing the difference between v1 and v2.

Definition at line 399 of file vec3.ixx.

399 constexpr vec3<T> operator-(const vec3<T>& v1, const vec3<T>& v2) noexcept {
400 return vec3{v1[0] - v2[0], v1[1] - v2[1], v1[2] - v2[2]};
401 }

operator*()

template <typename T>
helios::math::aabb< T > helios::math::operator* (const helios::math::aabb< T > & aabb, const helios::math::vec3< T > v)
nodiscard constexpr noexcept

Scales an AABB by a given vector.

This operator overload allows scaling of an axis-aligned bounding box (AABB) by multiplying its min and max points with the given vector.

Template Parameters
T

The numeric type of the vector components.

Parameters
aabb

The AABB to be scaled.

v

The scaling vector, for which only positive values are allowed.

Returns

A new AABB scaled by the given vector.

Definition at line 363 of file aabb.ixx.

363 [[nodiscard]] constexpr helios::math::aabb<T> operator*(
364 const helios::math::aabb<T>& aabb, const helios::math::vec3<T> v) noexcept {
365 assert(v[0] >= 0 && v[1] >= 0 && v[2] >= 0 && "unexpected negative value for scaling vector");
366 return helios::math::aabb<T>{aabb.min() * v, aabb.max() * v};
367 }

References helios::math::aabb< T >::max and helios::math::aabb< T >::min.

operator*()

template <helios::math::Numeric T>
vec2< T > helios::math::operator* (const vec2< T > & v, const T n)
constexpr noexcept

Multiplies a 2D vector by a scalar value.

Template Parameters
T

The numeric type of the vector components.

Parameters
v

The vec2<T> vector to be multiplied.

n

The scalar vector to multiplay the vector by.

Returns

a new vec2<T> instance representing the result of the scalar multiplication.

Definition at line 188 of file vec2.ixx.

188 constexpr vec2<T> operator*(const vec2<T>& v, const T n) noexcept {
189 return vec2<T>{v[0] * n, v[1] * n};
190 }

operator*()

template <helios::math::Numeric T>
vec3< T > helios::math::operator* (const vec3< T > & v, const T n)
constexpr noexcept

Multiplies a 3D vector by a scalar value.

Template Parameters
T

The numeric type of the vector components.

Parameters
v

The vec3<T> vector to be multiplied.

n

The scalar value to multiply the vector by.

Returns

a new vec3<T> instance representing the result of the scalar multiplication.

Definition at line 288 of file vec3.ixx.

288 constexpr vec3<T> operator*(const vec3<T>& v, const T n) noexcept {
289 return vec3<T>{v[0] * n, v[1] * n, v[2] * n};
290 }

operator*()

template <helios::math::Numeric T>
vec3< T > helios::math::operator* (const T n, const vec3< T > & v)
constexpr noexcept

Multiplies a scalar value by a 3D vector.

Template Parameters
T

The numeric type of the vector components.

Parameters
n

The scalar value to multiply the vector by.

v

The vec3<T> vector to be multiplied.

Returns

A new vec3<T> instance representing the result of the scalar multiplication.

Definition at line 321 of file vec3.ixx.

321 constexpr vec3<T> operator*(const T n, const vec3<T>& v) noexcept {
322 return vec3<T>{v[0] * n, v[1] * n, v[2] * n};
323 }

operator*()

template <helios::math::Numeric T>
vec3< T > helios::math::operator* (const vec3< T > & v1, const vec3< T > & v2)
constexpr noexcept

Multiplies two vectors componentwise.

Template Parameters
T

The numeric type of the vector components.

Parameters
v1

The left-hand vec3<T> vector to be multiplied.

v2

The right-hand vec3<T> vector to be multiplied.

Returns

A new vec3<T> instance representing the result of the componentwise multiplication of the two vectors.

Definition at line 336 of file vec3.ixx.

336 constexpr vec3<T> operator*(const vec3<T>& v1, const vec3<T>& v2) noexcept {
337 return vec3<T>{v1[0] * v2[0], v1[1] * v2[1], v1[2] * v2[2]};
338 }

operator/()

template <helios::math::Numeric T>
vec3< T > helios::math::operator/ (const vec3< T > & v, T s)
constexpr noexcept

Divides a 3D vector by a scalar value.

Template Parameters
T

The numeric type of the vector components.

Parameters
v

The vec3<T> vector to be divided.

s

The scalar divisor. Must not be zero.

Returns

A new vec3<T> instance representing the result of the scalar division.

Precondition

s != 0 (asserted in debug builds).

Definition at line 304 of file vec3.ixx.

304 constexpr vec3<T> operator/(const vec3<T>& v, T s) noexcept {
305 assert(static_cast<T>(0) != s && "s must not be 0");
306 const T inv = static_cast<T>(1) / s;
307 return vec3<T>{ v[0] * inv, v[1] * inv, v[2] * inv };
308 }

operator+()

template <typename T>
helios::math::aabb< T > helios::math::operator+ (const helios::math::aabb< T > aabb, const helios::math::vec3< T > v)
nodiscard constexpr noexcept

Adds a translation vector to an AABB.

This operator overload allows the addition of a translation vector to an axis-aligned bounding box (AABB), resulting in a new translated AABB.

Template Parameters
T

The numeric type of the vector components (e.g., `float` or `double`).

Parameters
aabb

The AABB to be translated.

v

The translation vector to apply.

Returns

A new AABB translated by the given vector.

Definition at line 345 of file aabb.ixx.

345 [[nodiscard]] constexpr helios::math::aabb<T> operator+(
346 const helios::math::aabb<T> aabb, const helios::math::vec3<T> v) noexcept {
347 return aabb.translate(v);
348 }

Reference helios::math::aabb< T >::translate.

operator+()

template <helios::math::Numeric T>
vec3< T > helios::math::operator+ (const vec3< T > & v1, const vec3< T > & v2)
constexpr noexcept

Calculates the componentwise sum of the two vectors.

Template Parameters
T

The numeric type of the vector components.

Parameters
v1

The left-hand vec3<T> vector to be added.

v2

The right-hand vec3<T> vector to be added.

Returns

A new vec3<T> instance representing the sum of the two vectors.

Definition at line 351 of file vec3.ixx.

351 constexpr vec3<T> operator+(const vec3<T>& v1, const vec3<T>& v2) noexcept {
352 return vec3<T>{v1[0] + v2[0], v1[1] + v2[1], v1[2] + v2[2]};
353 }

operator|()

TransformType helios::math::operator| (TransformType a, TransformType b)
inline

Combines two Inherit flags using bitwise OR.

Parameters
a

The first inheritance flag.

b

The second inheritance flag.

Returns

The combined inheritance mask.

Definition at line 83 of file TransformType.ixx.

84 return static_cast<TransformType>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
85 }

Functions

cross()

template <helios::math::Numeric T>
vec3< T > helios::math::cross (const vec3< T > & v1, const vec3< T > & v2)
constexpr noexcept

Computes the cross product of two 3D vectors.

Template Parameters
T

The numeric type of the vector components.

Parameters
v1

The first vec3<T> vector.

v2

The second vec3<T> vector.

Returns

A new vec3<T> instance representing the cross product.

Definition at line 366 of file vec3.ixx.

366 constexpr vec3<T> cross(const vec3<T>& v1, const vec3<T>& v2) noexcept {
367 return vec3{
368 v1[1]*v2[2] - v1[2]*v2[1],
369 v1[2]*v2[0] - v1[0]*v2[2],
370 v1[0]*v2[1] - v1[1]*v2[0]
371 };
372 }

Referenced by helios::math::mat4< float >::inverse, lookAt, helios::scene::CameraSceneNode::lookAt and helios::scene::CameraSceneNode::lookAtLocal.

degrees()

float helios::math::degrees (const float radians)
constexpr noexcept

Converts an angle from radians to degrees.

Parameters
radians

The angle value in radians.

Returns

The converted angle value in degrees.

Definition at line 40 of file utils.ixx.

40 constexpr float degrees(const float radians) noexcept {
41 return radians * 180.0f/static_cast<float>(std::numbers::pi);
42 }

Reference radians.

Referenced by helios::engine::modules::physics::motion::systems::SteeringSystem::update.

dot()

template <helios::math::Numeric T>
T helios::math::dot (const vec2< T > & v1, const vec2< T > & v2)
constexpr noexcept

Computes the dot product of two 2D vectors.

Template Parameters
T

The numeric type of the vector components.

Parameters
v1

The first vec2<T> vector.

v2

The second vec2<T> vector.

Returns

The dot product as a value of type T.

Definition at line 203 of file vec2.ixx.

203 constexpr T dot(const vec2<T>& v1, const vec2<T>& v2) noexcept {
204 return v1[0]*v2[0] + v1[1]*v2[1];
205 }

Referenced by helios::math::mat4< float >::inverse and lookAt.

dot()

template <helios::math::Numeric T>
T helios::math::dot (const vec3< T > & v1, const vec3< T > & v2)
constexpr noexcept

Computes the dot product of two 3D vectors.

Template Parameters
T

The numeric type of the vector components.

Parameters
v1

The first vec3<T> vector.

v2

The second vec3<T> vector.

Returns

The dot product as a value of type T.

Definition at line 384 of file vec3.ixx.

384 constexpr T dot(const vec3<T>& v1, const vec3<T>& v2) noexcept {
385 return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
386 }

lookAt()

mat4f helios::math::lookAt (const vec3f & eye, const vec3f & center, const vec3f & up)
inline noexcept

Returns the 4x4 lookAt-matrix for transforming world coordinates to camera space. The method creates the camera coordinate system based on the parameters eye, i.e. the vantage point in world space, the camera's up direction and center, representing the point of interest. Note that the returned matrix is essentially a composition of a change of coordinates matrix P(C <- W) and a translation to the origin, i.e. the camera is sitting at the origin (0, 0, 0) looking down the negative z-axis, i.e. conceptually.

P(W<-C) * T(-eye)

The 4x4 matrix can then be used for computing the perspective projection for creating the clip space

clip = P * V * W * M

Parameters
eye
center
up
Returns

Definition at line 106 of file camera.ixx.

106 inline mat4f lookAt(const vec3f& eye, const vec3f& center, const vec3f& up) noexcept {
107 const auto z = (eye - center).normalize();
108 const auto x = cross(up, z).normalize();
109 const auto y = cross(z, x).normalize();
110
111 return mat4f{
112 x[0], y[0], z[0], 0.0f,
113 x[1], y[1], z[1], 0.0f,
114 x[2], y[2], z[2], 0.0f,
115 -dot(x, eye), -dot(y, eye), -dot(z, eye), 1.0f,
116 };
117 }

References cross and dot.

ortho()

mat4f helios::math::ortho (const float left, const float right, const float bottom, const float top, const float zNear=0.1f, const float zFar=100.0f)
inline noexcept

Computes the 4x4 orthographic projection matrix.

Creates a projection matrix that maps 3D coordinates to normalized device coordinates without perspective distortion. Parallel lines remain parallel, and object size does not change with distance from the camera.

Suitable for 2D rendering, UI elements, and technical visualizations.

Parameters
left

The left boundary of the view volume.

right

The right boundary of the view volume.

bottom

The bottom boundary of the view volume.

top

The top boundary of the view volume.

zNear

The distance to the near clipping plane (default: 0.1).

zFar

The distance to the far clipping plane (default: 100.0).

Returns

A 4x4 orthographic projection matrix.

See Also

perspective()

Definition at line 68 of file camera.ixx.

68 inline mat4f ortho(
69 const float left , const float right,
70 const float bottom, const float top,
71 const float zNear = 0.1f, const float zFar = 100.0f) noexcept {
72
73 return mat4f{
74 2.0f/(right - left), 0.0f,0.0f,0.0f,
75 0.0f, 2.0f/(top-bottom),0.0f,0.0f,
76 0.0f, 0.0f, -2.0f/(zFar - zNear),0.0f,
77 -(right +left)/(right-left),-(top+bottom)/(top-bottom),-(zFar+zNear)/(zFar-zNear),1.0f
78 };
79 }

Referenced by helios::scene::Camera::update.

overlap()

template <typename T>
helios::math::vec3< T > helios::math::overlap (const helios::math::aabb< T > a, const helios::math::aabb< T > b)
nodiscard constexpr noexcept

Computes the signed dimensions of the overlapping region between two axis-aligned bounding boxes (AABBs).

Given two AABBs, this function calculates the intersection bounds along each axis. The resulting vector represents the size (extents) of the intersection.

Template Parameters
T

The numeric type used for the vector components (e.g., `float` or `double`).

Parameters
a

The first AABB.

b

The second AABB.

Returns

A 3D vector representing the dimensions of the overlapping region between the AABBs. If no overlap exists, the resulting vector may contain non-positive values in one or more components.

Definition at line 282 of file aabb.ixx.

282 [[nodiscard]] constexpr helios::math::vec3<T> overlap(
283 const helios::math::aabb<T> a, const helios::math::aabb<T> b) noexcept {
284
285 const auto overlapMin = helios::math::vec3<T>{
286 std::max(a.min()[0], b.min()[0]),
287 std::max(a.min()[1], b.min()[1]),
288 std::max(a.min()[2], b.min()[2])
289 };
290
291 const auto overlapMax = helios::math::vec3<T>{
292 std::min(a.max()[0], b.max()[0]),
293 std::min(a.max()[1], b.max()[1]),
294 std::min(a.max()[2], b.max()[2])
295 };
296
297 return overlapMax - overlapMin;
298 }

overlapCenter()

template <typename T>
helios::math::vec3< T > helios::math::overlapCenter (const helios::math::aabb< T > a, const helios::math::aabb< T > b)
nodiscard constexpr noexcept

Computes the center of intersection of the overlapping region between two axis-aligned bounding boxes (AABBs).

This function calculates the center of the intersection region of the two AABBs. If the AABBs do not overlap, the returned value represents the midpoint of the gap between them.

Template Parameters
T

The numeric type used for the vector components (e.g., `float` or `double`).

Parameters
a

The first AABB.

b

The second AABB.

Returns

A 3D vector representing the center point of the overlapping or gapping region between the AABBs.

Definition at line 314 of file aabb.ixx.

314 [[nodiscard]] constexpr helios::math::vec3<T> overlapCenter(
315 const helios::math::aabb<T> a, const helios::math::aabb<T> b) noexcept {
316
317 const auto overlapMin = helios::math::vec3<T>{
318 std::max(a.min()[0], b.min()[0]),
319 std::max(a.min()[1], b.min()[1]),
320 std::max(a.min()[2], b.min()[2])
321 };
322
323 const auto overlapMax = helios::math::vec3<T>{
324 std::min(a.max()[0], b.max()[0]),
325 std::min(a.max()[1], b.max()[1]),
326 std::min(a.max()[2], b.max()[2])
327 };
328
329 return (overlapMax + overlapMin) * static_cast<T>(0.5);
330 }

Referenced by helios::engine::modules::physics::collision::systems::GridCollisionDetectionSystem::solveCell.

perspective()

mat4f helios::math::perspective (float fovY, float aspect, float zNear, float zFar)
inline noexcept

Computes the 4x4 perspective projection matrix based on the specified field of view, aspect ratio, and near and far clipping planes.

This method returns a matrix suitable for projecting 3D points onto a 2D screen from the perspective of a camera. The perspective transformation maps 3D points inside the specified viewing frustum to normalized device coordinates, which are then clipped and transformed to screen space.

Parameters
fovY

Field of view in the Y direction, specified in radians.

aspect

The aspect ratio of the view, defined as width divided by height.

zNear

The distance to the near clipping plane. Must be greater than zero.

zFar

The distance to the far clipping plane. Must be greater than zNear.

Returns

A 4x4 matrix representing the perspective projection transformation.

See Also

https://thorsten.suckow-homberg.de/docs/articles/computer-graphics/from-camera-to-clip-space-derivation-of-the-projection-matrices

Definition at line 35 of file camera.ixx.

35 inline mat4f perspective(float fovY, float aspect, float zNear, float zFar) noexcept {
36
37 float f = 1 / std::tan(fovY/2);
38
39 return mat4f{
40 f/aspect, 0.0f, 0.0f, 0.0f,
41 0.0f, f, 0.0f, 0.0f,
42 0.0f, 0.0f , -(zFar + zNear)/(zFar - zNear), -1.0f,
43 0.0f, 0.0f, -2 * (zFar * zNear) / (zFar - zNear), 0.0f
44 };
45 }

Referenced by helios::scene::Camera::update.

radians()

float helios::math::radians (const float angle)
constexpr noexcept

Converts an angle from degrees to radians.

Parameters
angle

The angle value in degrees.

Returns

The converted angle value in radians.

Definition at line 30 of file utils.ixx.

30 constexpr float radians(const float angle) noexcept {
31 return angle * static_cast<float>(std::numbers::pi)/180.0f;
32 }

Referenced by degrees, helios::ext::imgui::widgets::CameraWidget::draw, rotate and helios::engine::modules::physics::motion::systems::SteeringSystem::update.

rotate()

mat4f helios::math::rotate (const mat4f & model, float radians, const vec3f & axis)
inline noexcept

Creates an affine rotation matrix R' = M * R by "baking" the rotation part into the model matrix. Any operation R' * v will make sure that v is rotated around the local origin, then transformed into world space.

Parameters
model
radians
axis
Returns

Definition at line 62 of file model.ixx.

62 inline mat4f rotate(const mat4f& model, float radians, const vec3f& axis) noexcept {
63
64
66 std::cos(radians),
67 std::sin(radians),
68 axis.normalize()
69 );
70 }

References helios::math::transform::make_rodrigues_rotation_matrix and radians.

scale()

mat4f helios::math::scale (const mat4f & model, const vec3f & v)
constexpr noexcept

Creates an affine transformation matrix S' = M * S by ""baking" the scaling part into the model matrix. Any operation S' * v will make sure that v is scaled in local space, then transformed into world space.

Parameters
model
v
Returns

Definition at line 100 of file model.ixx.

100 constexpr mat4f scale(const mat4f& model, const vec3f& v) noexcept {
101 mat4f t = model;
102
103 t(0, 0) *= v[0]; t(0, 1) *= v[1]; t(0, 2) *= v[2];
104 t(1, 0) *= v[0]; t(1, 1) *= v[1]; t(1, 2) *= v[2];
105 t(2, 0) *= v[0]; t(2, 1) *= v[1]; t(2, 2) *= v[2];
106
107 return t;
108 }

scale()

mat4f helios::math::scale (const mat4f & model, const float scale_by)
constexpr noexcept

Creates an affine transformation matrix S' = M * S by "baking" the scaling part into the model matrix. Any operation S' * v will make sure that v is scaled in local space, then transformed into world space.

Parameters
model
scale_by
Returns

Definition at line 120 of file model.ixx.

120 constexpr mat4f scale(const mat4f& model, const float scale_by) noexcept {
121 mat4f t = model;
122
123 t(0, 0) *= scale_by; t(0, 1) *= scale_by; t(0, 2) *= scale_by;
124 t(1, 0) *= scale_by; t(1, 1) *= scale_by; t(1, 2) *= scale_by;
125 t(2, 0) *= scale_by; t(2, 1) *= scale_by; t(2, 2) *= scale_by;
126
127 return t;
128 }

transformTypeMatch()

bool helios::math::transformTypeMatch (TransformType mask, TransformType flag)
inline

Checks if a specific inheritance flag is set in a mask.

Parameters
mask

The inheritance mask to check against.

flag

The specific flag to test for.

Returns

`true` if the flag is present in the mask, `false` otherwise.

Example usage: ```cpp using namespace helios::math;

TransformType mode = TransformType::Translation | TransformType::Rotation;

if (transformTypeMatch(mode, TransformType::Translation)) { // Apply parent translation... } ```

Definition at line 107 of file TransformType.ixx.

108 return (static_cast<uint8_t>(mask) & static_cast<uint8_t>(flag)) != 0;
109 }

Referenced by helios::math::mat4< float >::decompose and helios::scene::CameraSceneNode::lookAt.

translate()

mat4f helios::math::translate (const mat4f & model, const vec3f & v)
constexpr noexcept

Creates an affine transformation matrix M' = M * T by "baking" the translation part into the model matrix. Any operation M' * v will make sure that v is translated in local space, then transformed into world space.

Parameters
model
v
Returns

Definition at line 82 of file model.ixx.

82 constexpr mat4f translate(const mat4f& model, const vec3f& v) noexcept {
83 mat4 t = model;
84 t(0, 3) += t(0,0) * v[0] + t(0, 1) * v[1] + t(0, 2) * v[2];
85 t(1, 3) += t(1,0) * v[0] + t(1, 1) * v[1] + t(1, 2) * v[2];
86 t(2, 3) += t(2,0) * v[0] + t(2, 1) * v[1] + t(2, 2) * v[2];
87 return t;
88 };

value_ptr()

template <helios::math::Numeric T>
const T * helios::math::value_ptr (const mat4< T > & m)
noexcept

Returns a const pointer to the first element of the matrix's components.

Useful for APIs that expect a pointer to matrix data, like OpenGL.

Template Parameters
T

The numeric type of the matrix components.

Parameters
m

A reference to the `mat4<T>` matrix.

Returns

A const pointer to the element at [0, 0].

Definition at line 510 of file mat4.ixx.

510 const T* value_ptr(const mat4<T>& m) noexcept {
511 return &m(0, 0);
512 }

Referenced by helios::rendering::shader::UniformValueMap::mat4f_ptr, helios::math::mat4< float >::operator==, helios::math::mat4< float >::same and helios::rendering::shader::UniformValueMap::vec4f_ptr.

value_ptr()

template <helios::math::Numeric T>
T * helios::math::value_ptr (mat4< T > & m)
noexcept

Returns a pointer to the first element of the matrix's components.

Useful for APIs that expect a pointer to matrix data, like OpenGL.

Template Parameters
T

The numeric type of the matrix components.

Parameters
m

A reference to the `mat4<T>` matrix.

Returns

A pointer to the element at [0, 0].

Definition at line 527 of file mat4.ixx.

527 T* value_ptr(mat4<T>& m) noexcept {
528 return &m(0, 0);
529 }

value_ptr()

template <helios::math::Numeric T>
const T * helios::math::value_ptr (const vec4< T > & m)
noexcept

Returns a const pointer to the first element of the vector's components.

Useful for APIs that expect a pointer to vector data, like OpenGL

Parameters
m

A reference to the `vec4<T>` vector.

Template Parameters
T

The numeric type of the vector components.

Definition at line 164 of file vec4.ixx.

164 const T* value_ptr(const vec4<T>& m) noexcept {
165 return &m[0];
166 }

Variables

EPSILON_LENGTH

X_AXISf

vec3f helios::math::X_AXISf {1.0f, 0.0f, 0.0f}
constexpr

Unit vector along the positive X-axis (1, 0, 0).

Commonly used as the default "right" direction in helios's left-handed coordinate system.

Definition at line 471 of file vec3.ixx.

471 inline constexpr vec3f X_AXISf{1.0f, 0.0f, 0.0f};

Referenced by helios::engine::runtime::spawn::behavior::initializers::MoveInitializer::initialize.

Y_AXISf

vec3f helios::math::Y_AXISf {0.0f, 1.0f, 0.0f}
constexpr

Unit vector along the positive Y-axis (0, 1, 0).

Commonly used as the default "up" direction in helios's left-handed coordinate system.

Definition at line 479 of file vec3.ixx.

479 inline constexpr vec3f Y_AXISf{0.0f, 1.0f, 0.0f};

Z_AXISf

vec3f helios::math::Z_AXISf {0.0f, 0.0f, 1.0f}
constexpr

Unit vector along the positive Z-axis (0, 0, 1).

Commonly used as the default "forward" direction in helios's left-handed coordinate system.

Definition at line 487 of file vec3.ixx.

487 inline constexpr vec3f Z_AXISf{0.0f, 0.0f, 1.0f};

The documentation for this namespace was generated from the following files:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.