Skip to main content

model.ixx File

Model transform helper functions. More...

Included Headers

#include <cmath> #include <helios.math.types>

Namespaces Index

namespacehelios
namespacemath
namespacetransform

Description

Model transform helper functions.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <cmath>
8
9export module helios.math.transform:model;
10
11import helios.math.types;
12
14
16 const float cos_theta,
17 const float sin_theta,
18 const vec3f& normalized_axis
19 ) noexcept {
20
21 const float t = 1.0f - cos_theta;
22
23 const float x = normalized_axis[0],
24 y = normalized_axis[1],
25 z = normalized_axis[2];
26
27
28 return mat4f{
29 cos_theta + x * x * t,
30 x * y * t + z * sin_theta,
31 x * z * t - y * sin_theta,
32 0,
33
34 x * y * t - z * sin_theta,
35 cos_theta + y * y * t,
36 y * z * t + x * sin_theta,
37 0,
38
39 x * z * t + y * sin_theta,
40 y * z * t - x * sin_theta,
41 cos_theta + z * z * t,
42 0,
43
44 0, 0, 0, 1
45 };
46 };
47
48};
49
50export namespace helios::math {
51
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 }
71
82 constexpr mat4f translate(const mat4f& model, const vec3f& v) noexcept {
83 mat4f 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 };
89
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 }
109
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 }
129
130};

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.