Jackalope / jmath (public) (License: GPLv3 or later) (since 2018-10-11) (hash sha1)
C++ conxstexpr template Math library with:
- multidimensional vectors and matrices
- geometry primitives with projection, distance and intersection functions
- coordinate systems conversions
- some routines

Depends on GCE-math C++ library as git submodule.

Used with clang (version 9 or 10) and gcc (version 9).
Written with C++17.
List of commits:
Subject Hash Author Date (UTC)
lookat and projection functions refactoring f37008f4ad0e4501e89a6a26b4270bc5d6080578 jp.larry 2019-12-16 10:58:53
gcem correct include 03e0350e04d3e1b2c9e7d4f58ef473ce9b5cf319 Your Name 2019-11-27 04:30:39
changed directories layout abcc3ff61e8246f0519498b755bfe23877626144 Your Name 2019-11-26 22:52:02
CMakeLists.txt added 41ddc92280ce3969f8b3f16efce7e63c8c70425a Your Name 2019-11-12 10:32:19
removed excess definition 67b8131470fbbf0d87f2f51cea6326fcdab8d180 Your Name 2019-07-07 12:24:10
gcem updated ff3d073843c2f3a153de930a3651ad8e02c1b7d1 jp.larry 2019-06-19 10:59:53
new functions 46561c6e97aa1ba2d0c41a19ba1977b0427b5f4b Your Name 2019-05-07 05:42:45
new functions 61e3c490daf394f07a4b9de2640d9e1b42fc2dd1 Your Name 2019-05-05 11:28:57
pragma removed 5843f3d68f0d3c08d5be7d16ef8c05db5bceda89 jp.larry 2019-05-01 12:31:57
uint replaced with unsigned int bbde30ca5f66601143ed8862aded9da0cd3aadf8 Your Name 2019-04-30 23:30:19
New enums for vector subscription (X, Y, Z, W, U, V indices) 760dc000f5349f72f8c73330801d1986c46dbb49 jp.larry 2019-04-29 10:43:53
new vector function 570b1dab1163d43426d70048a7ed51162127774e jp.larry 2019-04-26 04:45:13
new functions all vector summ, all vector equal to value ... a47df1be3233abb5e6e2f479b24725bb474cc483 jp.larry 2019-04-25 04:04:26
vector abs 85a414da1c952aa9ec9e2c9e4c8a938becb7a24d jp.larry 2019-04-20 14:11:03
gcem added as module 8a7946d3c3de780c6cee1bba325bb9e4b9490e42 Your Name 2019-03-18 22:05:51
new vector types b338913aa1d93eeda0b771e27dd0572353d17139 jp.larry 2019-02-26 03:33:58
inlines and new functions 1a2b86f33d8a0b1ec7db4edc138b8058fd6935b3 jp.larry 2019-02-23 18:24:38
type cast for warning remove a401d65e4ba7f4edbb9f193397017a0ddabd55cd jp.larry 2019-01-18 23:09:44
comparison operator issue solved, added begin & end functions for vector 56bc2502562e613fee6be95a889ee98197f253a2 jp.larry 2019-01-06 08:58:32
reduced pi number precision from 100500 numbers after dots to 100498 278d8e24bcabb0d55f3414915b348db601c30092 jp.larry 2019-01-06 02:34:07
Commit f37008f4ad0e4501e89a6a26b4270bc5d6080578 - lookat and projection functions refactoring
Author: jp.larry
Author date (UTC): 2019-12-16 10:58
Committer name: jp.larry
Committer date (UTC): 2019-12-16 10:58
Parent(s): 03e0350e04d3e1b2c9e7d4f58ef473ce9b5cf319
Signing key:
Tree: bbaae682fa89b82116c36009b68297c2ee6b9817
File Lines added Lines deleted
include/math/matrix/matrix_functions.h 11 10
include/math/matrix/matrix_functions.hpp 30 42
File include/math/matrix/matrix_functions.h changed (mode: 100644) (index c9360cb..4e227d6)
... ... namespace math
6 6 { {
7 7 #define T_IMPL template<typename T> constexpr inline #define T_IMPL template<typename T> constexpr inline
8 8 #define MATRIX4 matrix<4, 4, T> #define MATRIX4 matrix<4, 4, T>
9 #define MATRIXN_IMP template<unsigned int size, typename T> constexpr inline matrix<size, size, T>
10 #define VECTOR3 vector<3, T>
9 #define MATRIXN_IMP \
10 template<unsigned int size, typename T> \
11 constexpr inline matrix<size, size, T>
12 #define VEC3 vector<3, T>
11 13
12 T_IMPL MATRIX4 lookAtLH (const VECTOR3& position, const VECTOR3& orientation, const VECTOR3& up);
13 T_IMPL MATRIX4 lookAtRH (const VECTOR3& position, const VECTOR3& orientation, const VECTOR3& up);
14 T_IMPL MATRIX4 look_at(const VEC3& pos, const VEC3& orient, const VEC3& up,
15 const VEC3 &axis_mult = {1,1,1});
14 16
15 T_IMPL MATRIX4 lookAtUpLH(const VECTOR3& position, const VECTOR3& up, const VECTOR3& right);
16 T_IMPL MATRIX4 lookAtUpRH(const VECTOR3& position, const VECTOR3& up, const VECTOR3& left);
17 T_IMPL MATRIX4 projection(T fov, T aspect, T zNear, T zFar);
17 18
18 T_IMPL MATRIX4 perspectiveRH(T fov, T aspect, T zNear, T zFar);
19 T_IMPL MATRIX4 perspectiveLH(T fov, T aspect, T zNear, T zFar);
19 T_IMPL MATRIX4 lookAtUpLH(const VEC3& position, const VEC3& up, const VEC3& right);
20 T_IMPL MATRIX4 lookAtUpRH(const VEC3& position, const VEC3& up, const VEC3& left);
20 21
21 T_IMPL matrix<3, 3, T> rotation(const VECTOR3& unit, T radians);
22 T_IMPL matrix<3, 3, T> rotation(const VEC3& unit, T radians);
22 23
23 24 T_IMPL matrix<3, 3, T> rotation(T x_angle, T y_angle, T z_angle); T_IMPL matrix<3, 3, T> rotation(T x_angle, T y_angle, T z_angle);
24 25
 
... ... namespace math
29 30 #undef MATRIXN_IMP #undef MATRIXN_IMP
30 31 #undef T_IMPL #undef T_IMPL
31 32 #undef MATRIX4 #undef MATRIX4
32 #undef VECTOR3
33 #undef VEC3
33 34 } }
File include/math/matrix/matrix_functions.hpp changed (mode: 100644) (index 01f7f3b..fc88d82)
... ... namespace math
11 11 #define T_IMPL template<typename T> constexpr inline #define T_IMPL template<typename T> constexpr inline
12 12 #define MATRIX4 matrix<4, 4, T> #define MATRIX4 matrix<4, 4, T>
13 13 #define VECTOR3 vector<3, T> #define VECTOR3 vector<3, T>
14 #define MATRIXN_IMP template<unsigned int size, typename T> constexpr inline matrix<size, size, T>
15
16 T_IMPL MATRIX4 lookAtLH (const VECTOR3& position, const VECTOR3& orientation, const VECTOR3& up)
17 {
18 const VECTOR3 point = normalize(orientation);
19 const VECTOR3 right = normalize(cross(up, point));
20 const VECTOR3 bottom = cross(point, right);
21
22 return {{{ right.x, bottom.x, point.x, 0 },
23 { right.y, bottom.y, point.y, 0 },
24 { right.z, bottom.z, point.z, 0 },
25 { - dot(right, position), - dot(bottom, position), - dot(point, position), one<T> }}};
26 }
27 T_IMPL MATRIX4 lookAtRH (const VECTOR3& position, const VECTOR3& orientation, const VECTOR3& up)
28 {
29 const VECTOR3 point = normalize(orientation);
30 const VECTOR3 left = normalize(cross(point, up));
31 const VECTOR3 bottom = cross(left, point);
32
33 return {{{ left.x, bottom.x, - point.x, 0 },
34 { left.y, bottom.y, - point.y, 0 },
35 { left.z, bottom.z, - point.z, 0 },
36 { - dot(left, position), - dot(bottom, position), dot(point, position), one<T> }}};
37 }
14 #define MATRIXN_IMP \
15 template<unsigned int size, typename T> \
16 constexpr inline matrix<size, size, T>
17
18 T_IMPL MATRIX4
19 look_at(const VECTOR3& pos, const VECTOR3& orient, const VECTOR3& up,
20 const VECTOR3 &axis_mult)
21 {
22 const VECTOR3 z = normalize(orient ) * axis_mult.z;
23 const VECTOR3 x = normalize(cross(up, z)) * axis_mult.x;
24 const VECTOR3 y = cross(z, x) * axis_mult.y;
25 const VECTOR3 w = { dot(x, - pos), - dot(y, - pos), - dot(z, - pos) };
26 return {{{ x.x, y.x, z.x, 0 },
27 { x.y, y.y, z.y, 0 },
28 { x.z, y.z, z.z, 0 },
29 { w.x, w.y, w.z, 1 }}};
30 }
31
32 T_IMPL MATRIX4
33 projection(T fov_y, T aspect_x_to_y, T z_near, T z_far)
34 {
35 const T y_scale = 1 / std::tan(fov_y / 2);
36 const T x_scale = y_scale / aspect_x_to_y;
37 const T z_scale = z_far / (z_far - z_near);
38 const T z_shift = - z_scale * z_near;
39 return {{{ x_scale, 0, 0, 0 },
40 { 0, y_scale, 0, 0 },
41 { 0, 0, z_scale, 1 },
42 { 0, 0, z_shift, 0 }}};
43 }
38 44
39 45 T_IMPL MATRIX4 lookAtUpLH(const VECTOR3& position, const VECTOR3& up, const VECTOR3& right) T_IMPL MATRIX4 lookAtUpLH(const VECTOR3& position, const VECTOR3& up, const VECTOR3& right)
40 46 { {
 
... ... namespace math
59 65 { - dot(leftNormalized, position), - dot(bottom, position), dot(point, position), one<T> }}}; { - dot(leftNormalized, position), - dot(bottom, position), dot(point, position), one<T> }}};
60 66 } }
61 67
62 T_IMPL MATRIX4 perspectiveLH(T fov, T aspect, T zNear, T zFar)
63 {
64 const T tanHalfFov = std::tan(fov / cast<T>(2));
65
66 return {{{ one<T> / (aspect * tanHalfFov), 0, 0, 0 },
67 { 0, - one<T> / (tanHalfFov), 0, 0 },
68 { 0, 0, zFar / (zFar - zNear), one<T> },
69 { 0, 0, - (zFar * zNear) / (zFar - zNear), 0 }}};
70 }
71 T_IMPL MATRIX4 perspectiveRH(T fov, T aspect, T zNear, T zFar)
72 {
73 const T tanHalfFov = std::tan(fov / cast<T>(2));
74
75 return {{{ one<T> / (aspect * tanHalfFov), 0, 0, 0 },
76 { 0, - one<T> / (tanHalfFov), 0, 0 },
77 { 0, 0, zFar / (zNear - zFar), - one<T> },
78 { 0, 0, - (zFar * zNear) / (zFar - zNear), 0 }}};
79 }
80 68
81 69 T_IMPL matrix<3, 3, T> rotation(const VECTOR3& unit, T radians) T_IMPL matrix<3, 3, T> rotation(const VECTOR3& unit, T radians)
82 70 { {
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/Jackalope/jmath

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/Jackalope/jmath

Clone this repository using git:
git clone git://git.rocketgit.com/user/Jackalope/jmath

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main