Skip to main content

math Namespace

Definition

namespace helios::math { ... }

Namespaces Index

namespaceconcepts
namespacetransform

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...

structvec2<T>

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

structvec3<T>

Represents a 3-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>
auto operator+ (const helios::math::aabb< T > aabb, const helios::math::vec3< T > v) noexcept -> constexpr helios::math::aabb< T >

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

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

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

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

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

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

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

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

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

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

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

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

Multiplies two vectors componentwise. More...

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

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

template <helios::math::concepts::IsNumeric T>
auto operator- (const vec3< T > &v1, const vec3< T > &v2) noexcept -> constexpr 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>
auto overlap (const helios::math::aabb< T > a, const helios::math::aabb< T > b) noexcept -> constexpr helios::math::vec3< T >

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

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

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

template <helios::math::concepts::IsNumeric 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::concepts::IsNumeric T>
T *value_ptr (mat4< T > &m) noexcept

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

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

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

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

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

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

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

template <helios::math::concepts::IsNumeric 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...

Typedefs

aabbd

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

Double-precision floating-point AABB.

Definition at line 387 of file aabb.ixx.

aabbf

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

Single-precision floating-point AABB.

Definition at line 372 of file aabb.ixx.

aabbi

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

Integer AABB.

Definition at line 377 of file aabb.ixx.

aabbui

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

Unsigned Integer AABB.

Definition at line 382 of file aabb.ixx.

FloatingPointType

template <typename T>
using helios::math::FloatingPointType = typedef 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.

22 >;

mat4d

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

Type alias for a 4x4 double matrix.

Definition at line 541 of file mat4.ixx.

mat4f

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

Type alias for a 4x4 float matrix.

Definition at line 536 of file mat4.ixx.

mat4i

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

Type alias for a 4x4 integer matrix.

Definition at line 546 of file mat4.ixx.

vec2d

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

Definition at line 218 of file vec2.ixx.

vec2f

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

Definition at line 217 of file vec2.ixx.

vec2i

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

Definition at line 219 of file vec2.ixx.

vec2ui

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

Definition at line 220 of file vec2.ixx.

vec3d

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

Double-precision floating-point 3D vector.

Definition at line 464 of file vec3.ixx.

vec3f

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

Single-precision floating-point 3D vector.

Definition at line 454 of file vec3.ixx.

vec3i

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

Integer 3D vector.

Definition at line 459 of file vec3.ixx.

vec4d

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

Double-precision floating-point 4D vector.

Definition at line 177 of file vec4.ixx.

vec4f

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

Single-precision floating-point 4D vector.

Definition at line 172 of file vec4.ixx.

vec4i

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

Integer 4D vector.

Definition at line 182 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:

Example usage:

 using namespace helios::math;
 
 // Camera follows spaceship position only
 
 // Full transform inheritance (default)
 childNode->setInheritance(TransformType::All);
 
 // Combine specific flags

Definition at line 41 of file TransformType.ixx.

41 enum class TransformType : uint8_t {
48 Translation = 1 << 0,
49
56 Rotation = 1 << 1,
57
64 Scale = 1 << 2,
65
73 };

Operators

operator-()

template <helios::math::concepts::IsNumeric T>
constexpr 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 400 of file vec3.ixx.

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

operator*()

template <typename T>
constexpr helios::math::aabb< T > helios::math::operator* (const helios::math::aabb< T > & aabb, const helios::math::vec3< T > v)
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.

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::concepts::IsNumeric T>
constexpr 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 198 of file vec2.ixx.

198 constexpr vec2<T> operator*(const vec2<T>& v, const T n) noexcept {
199 return vec2<T>{v[0] * n, v[1] * n};
200 }

operator*()

template <helios::math::concepts::IsNumeric T>
constexpr 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 289 of file vec3.ixx.

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

operator*()

template <helios::math::concepts::IsNumeric T>
constexpr 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 322 of file vec3.ixx.

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

operator*()

template <helios::math::concepts::IsNumeric T>
constexpr 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 337 of file vec3.ixx.

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

operator/()

template <helios::math::concepts::IsNumeric T>
constexpr 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 305 of file vec3.ixx.

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

operator+()

template <typename T>
constexpr helios::math::aabb< T > helios::math::operator+ (const helios::math::aabb< T > aabb, const helios::math::vec3< T > v)
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.

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::concepts::IsNumeric T>
constexpr 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 352 of file vec3.ixx.

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

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::concepts::IsNumeric T>
constexpr 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 367 of file vec3.ixx.

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

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

degrees()

constexpr 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.

dot()

template <helios::math::concepts::IsNumeric T>
constexpr 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 213 of file vec2.ixx.

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

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

dot()

template <helios::math::concepts::IsNumeric T>
constexpr 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 385 of file vec3.ixx.

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

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,
78 };
79 }

overlap()

template <typename T>
constexpr helios::math::vec3< T > helios::math::overlap (const helios::math::aabb< T > a, const helios::math::aabb< T > b)
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.

283 const helios::math::aabb<T> a, const helios::math::aabb<T> b) noexcept {
284
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
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 }

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

overlapCenter()

template <typename T>
constexpr helios::math::vec3< T > helios::math::overlapCenter (const helios::math::aabb< T > a, const helios::math::aabb< T > b)
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.

315 const helios::math::aabb<T> a, const helios::math::aabb<T> b) noexcept {
316
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
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 }

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

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 }

radians()

constexpr 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 and rotate.

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()

constexpr 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()

constexpr 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:

 using namespace helios::math;
 
 
  // 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< T >::decompose.

translate()

constexpr 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::concepts::IsNumeric 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 512 of file mat4.ixx.

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

Referenced by helios::math::mat4< T >::operator== and helios::math::mat4< T >::same.

value_ptr()

template <helios::math::concepts::IsNumeric 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 529 of file mat4.ixx.

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

value_ptr()

template <helios::math::concepts::IsNumeric 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 165 of file vec4.ixx.

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

Variables

EPSILON_LENGTH

constexpr float helios::math::EPSILON_LENGTH = 1e-6f
constexpr

A small epsilon value used for length-based comparisons.

This constant represents the minimum threshold value for length comparisons to account for numerical precision errors in floating-point calculations. It is often used to avoid treating very small values as significant, effectively filtering out noise in computations that involve vector-lengths.

Definition at line 22 of file utils.ixx.

22 constexpr float EPSILON_LENGTH = 1e-6f;

Referenced by helios::math::vec2< T >::isNormalized and helios::math::vec3< T >::isNormalized.

X_AXISf

constexpr 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 472 of file vec3.ixx.

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

Y_AXISf

constexpr 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 480 of file vec3.ixx.

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

Z_AXISf

constexpr 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 488 of file vec3.ixx.

488 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.9.8.