1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/*
* Author: Sven Gothel <sgothel@jausoft.com>
* Copyright (c) 2024 Gothel Software e.K.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <thread>
#include <cassert>
#include <cinttypes>
#include <cstring>
#include <jau/test/catch2_ext.hpp>
#include <jau/int_math.hpp>
#include <jau/float_math.hpp>
#include <jau/math/vec2f.hpp>
#include <jau/math/vec2i.hpp>
#include <jau/math/vec3f.hpp>
#include <jau/math/vec4f.hpp>
#include <jau/math/mat4f.hpp>
#include <jau/math/quaternion.hpp>
#include <jau/math/aabbox2f.hpp>
#include <jau/math/aabbox3f.hpp>
#include <jau/math/mat4f.hpp>
#include <jau/math/recti.hpp>
#include <jau/math/math_error.hpp>
using namespace jau;
using namespace jau::math;
static const float EPSILON = std::numeric_limits<float>::epsilon();
static const float mI_0[] = { 1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
static const Mat4f mI(mI_0);
static const float m1_0[] = { 1, 3, 4, 0,
6, 7, 8, 5,
98, 7, 6, 9,
54, 3, 2, 5 };
static const Mat4f m1(m1_0);
static const float m1T_0[] = { 1, 6, 98, 54,
3, 7, 7, 3,
4, 8, 6, 2,
0, 5, 9, 5 };
static const Mat4f m1T(m1T_0);
static const float m2_0[] = { 1, 6, 98, 54,
3, 7, 7, 3,
4, 8, 6, 2,
0, 5, 9, 5 };
static const Mat4f m2(m2_0);
static const float m2xm1_0[] = { 26, 59, 143, 71,
59, 174, 730, 386,
143, 730, 9770, 5370,
71, 386, 5370, 2954 };
static const Mat4f m2xm1(m2xm1_0);
static const float m1xm2_0[] = {12557, 893, 748, 1182,
893, 116, 116, 113,
748, 116, 120, 104,
1182, 113, 104, 131 };
static const Mat4f m1xm2(m1xm2_0);
TEST_CASE( "Test 00 Load Get", "[mat4f][linear_algebra][math]" ) {
{
Mat4f m;
REQUIRE(mI == m);
}
{
float f16[16];
m1.get(f16);
COMPARE_NARRAYS_EPS(m1_0, f16, 16, EPSILON);
Mat4f m;
m.load(f16);
REQUIRE(m1 == m);
}
}
TEST_CASE( "Test 01 Mul", "[mat4f][linear_algebra][math]" ) {
{
REQUIRE(m1xm2 == m1 * m2);
Mat4f m; m.mul(m1, m2);
REQUIRE(m1xm2 == m);
}
{
REQUIRE(m2xm1 == m2 * m1);
Mat4f m; m.mul(m2, m1);
REQUIRE(m2xm1 == m);
}
}
TEST_CASE( "Test 02 Transpose", "[mat4f][linear_algebra][math]" ) {
REQUIRE(m1T == Mat4f(m1).transpose());
REQUIRE(m1T == Mat4f().transpose(m1));
}
TEST_CASE( "Test 80 LookAtNegZ", "[mat4f][linear_algebra][math]" ) {
Mat4f tmp;
Mat4f m;
// Look towards -z
m.setToLookAt(
Vec3f(0, 0, 0), // eye
Vec3f(0, 0, -1), // center
Vec3f(0, 1, 0), // up
tmp);
/**
* The 3 rows of the matrix (= the 3 columns of the array/buffer) should be: side, up, -forward.
*/
Mat4f exp( { 1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 } );
REQUIRE(exp == m);
}
TEST_CASE( "Test 81 LookAtPosY", "[mat4f][linear_algebra][math]" ) {
Mat4f tmp;
Mat4f m;
// Look towards -z
m.setToLookAt(
Vec3f(0, 0, 0), // eye
Vec3f(0, 1, 0), // center
Vec3f(0, 0, 1), // up
tmp);
/**
* The 3 rows of the matrix (= the 3 columns of the array/buffer) should be: side, up, -forward.
*/
Mat4f exp( { 1, 0, 0, 0,
0, 0, -1, 0,
0, 1, 0, 0,
0, 0, 0, 1
} );
REQUIRE(exp == m);
}
|