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)
frustum data type 48480173a43561e7502458579378b78591716d1c jp.larry 2020-01-07 13:53:57
different projection matrix built functions for different fov specifications (horizontal, vertical, both) 0aa5dbb5e22c616a559bb6f6d75b0313db7b3e84 jp.larry 2020-01-07 13:53:30
normal from 3 points and plane from normal and offset functions 432070f339b8c48b18c4e2dab4389dc19ffa241c jp.larry 2020-01-06 07:27:29
check if floating point when converting from degrees 75397be78960535bca1ec487221b6b46382e0724 jp.larry 2020-01-06 07:26:59
distance between 2 vectors and intersection line with plane 1620677672179226ea92affb5e3dc600cd3fa133 jp.larry 2020-01-05 03:22:56
2D vector rotate function 049eae7f349cf44bde666b66684a47c8bb4f1300 jp.larry 2020-01-01 05:09:07
removed nodiscard from matrix *= operator and removed redundant function rotate(axis) 0dea084c205202125acfe390a248be61c962d393 jp.larry 2020-01-01 03:09:48
rafactoring update, matrix multiplication now works in different way 2f2e01d80896cd96428a9c9394382e6f040f92fb jp.larry 2019-12-31 11:00:01
round_down function 672a293659a39e29be0d84f28801cf2718070f10 Jackalope 2019-12-28 03:02:03
migw warning solved 80dec7906c5fe2dc026d6774fd526df2ded049cc Jackalope 2019-12-21 10:22:55
refactoring 8b9c8aef3bcbbe3a3a72160eacd15b2d8397524c jp.larry 2019-12-19 08:10:49
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
Commit 48480173a43561e7502458579378b78591716d1c - frustum data type
Author: jp.larry
Author date (UTC): 2020-01-07 13:53
Committer name: jp.larry
Committer date (UTC): 2020-01-07 13:53
Parent(s): 0aa5dbb5e22c616a559bb6f6d75b0313db7b3e84
Signing key:
Tree: f2c9f84e60e17341f0ce4d3ff631ad0b4706a9b9
File Lines added Lines deleted
include/math/frustum.h 74 0
File include/math/frustum.h added (mode: 100644) (index 0000000..7abf2f1)
1 #pragma once
2
3 #include "vector.h"
4 #include "matrix.h"
5
6 namespace math
7 {
8 enum class Fov { X, Y };
9
10 template<Fov FOV, typename T = float>
11 struct frustum
12 {
13 T zNear;
14 T zFar;
15 T fov;
16 T aspect;
17
18 [[nodiscard]] constexpr T fov_x() const {
19 if (FOV == Fov::X)
20 return fov;
21 else
22 return 2 * gcem::atan(gcem::tan(fov / 2) * aspect);
23 }
24 [[nodiscard]] constexpr T fov_y() const {
25 if (FOV == Fov::X)
26 return 2 * gcem::atan(gcem::tan(fov / 2) / aspect);
27 else
28 return fov;
29 }
30
31 void constexpr set_fov_x(T fov_x) {
32 fov = fov_x;
33 if (FOV == Fov::Y)
34 fov = fov_y();
35 }
36 void constexpr set_fov_y(T fov_y) {
37 fov = fov_y;
38 if (FOV == Fov::X)
39 fov = fov_x();
40 }
41 void constexpr set_aspect(T width, T height) {
42 aspect = width / T(height);
43 }
44
45 [[nodiscard]] constexpr m4f projection() const {
46 if (FOV == Fov::X)
47 return math::projection_fov_x(fov, aspect, zNear, zFar);
48 else
49 return math::projection_fov_y(fov, aspect, zNear, zFar);
50 }
51
52 [[nodiscard]] constexpr T bound_x(T depth) const {
53 return depth * gcem::tan(fov_x());
54 }
55 [[nodiscard]] constexpr T bound_y(T depth) const {
56 return depth * gcem::tan(fov_y());
57 }
58
59 [[nodiscard]] constexpr int32_t
60 cluster_slice(T nSlices, T depth) const {
61 T lfn = gcem::log(zFar / zNear);
62 T scale = nSlices / lfn;
63 T bias = -(nSlices * gcem::log(zNear) / lfn);
64 return int32_t(gcem::log(depth) * scale + bias);
65 }
66 [[nodiscard]] constexpr T
67 cluster_depth(T nSlices, uint cluster_slice) const {
68 T lfn = gcem::log(zFar / zNear);
69 T scale = nSlices / lfn;
70 T bias = -(nSlices * gcem::log(zNear) / lfn);
71 return gcem::exp((cluster_slice - bias) / scale);
72 }
73 };
74 }
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