Skip to content

Commit acac312

Browse files
committed
update 2022-2-15
1 parent f09b575 commit acac312

33 files changed

+3878
-1175
lines changed

glm/detail/constants.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
#include "setup.hpp"
1313

14-
namespace glm{
14+
15+
16+
namespace glm {
1517

1618
//
1719
// class constants

glm/detail/functional.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#ifndef GLM_FUNCTIONAL_HPP_20211116111721
1010
#define GLM_FUNCTIONAL_HPP_20211116111721
1111

12-
#include "../vec.hpp"
12+
#include "../vector.hpp"
1313

1414

1515

16-
namespace glm{
16+
namespace glm {
1717

1818

1919

glm/detail/functions.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,19 @@ matrixCompMult
2828

2929

3030

31-
namespace glm{
31+
namespace glm {
32+
33+
template<typename T>
34+
GLM_API T min(const T& x, const T& y)
35+
{
36+
return x < y ? x : y;
37+
}
38+
39+
template<typename T>
40+
GLM_API T max(const T& x, const T& y)
41+
{
42+
return x < y ? y : x;
43+
}
3244

3345
template<typename T>
3446
GLM_API T abs(const T& value)
@@ -57,13 +69,13 @@ GLM_API T exp(const T& value)
5769
template<typename T>
5870
GLM_API T exp2(const T& value)
5971
{
60-
static_cast<T>(std::exp2(static_cast<double>(value)));
72+
return static_cast<T>(std::exp2(static_cast<double>(value)));
6173
}
6274

6375
template<typename T>
6476
GLM_API T floor(const T& value)
6577
{
66-
static_cast<T>(std::floor(static_cast<double>(value)));
78+
return static_cast<T>(std::floor(static_cast<double>(value)));
6779
}
6880

6981
// ȡСÊý²¿·Ö
@@ -73,24 +85,12 @@ GLM_API T fract(const T& value)
7385
return value - floor(value);
7486
}
7587

76-
template<typename T>
77-
GLM_API T max(const T& x, const T& y)
78-
{
79-
return x < y ? y : x;
80-
}
81-
8288
template<typename T>
8389
GLM_API T mid(const T& x, const T& y)
8490
{
8591
return mix(x, y, constants<T>::half);
8692
}
8793

88-
template<typename T>
89-
GLM_API T min(const T& x, const T& y)
90-
{
91-
return x < y ? x : y;
92-
}
93-
9494
template<typename T, typename A>
9595
GLM_API T mix(const T& x, const T& y, A a)
9696
{
@@ -117,9 +117,9 @@ GLM_API T pow(const T& x, const T& y)
117117
}
118118

119119
template<typename T>
120-
GLM_API int round(const T& value)
120+
GLM_API T round(const T& value)
121121
{
122-
static_cast<T>(std::round(static_cast<double>(value)));
122+
return value + (value < T(0) ? T(-0.5) : (0.5));
123123
}
124124

125125
template<typename T>
@@ -223,7 +223,7 @@ GLM_API vec<N, T> pow(const vec<N, T>& x, const vec<N, T>& y)
223223
}
224224

225225
template<size_t N, typename T>
226-
GLM_API int round(const vec<N, T>& v)
226+
GLM_API vec<N, T> round(const vec<N, T>& v)
227227
{
228228
return compute<T, N, T>(round<T>, v);
229229
}

glm/detail/logical.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
#ifndef GLM_LOGICAL_HPP_20211119132746
1010
#define GLM_LOGICAL_HPP_20211119132746
1111

12-
#include "../vec.hpp"
13-
#include "functions.hpp"
1412
#include "functional.hpp"
13+
#include "functions.hpp"
14+
#include "type_traits.hpp"
1515

1616

1717

18-
namespace glm{
18+
namespace glm {
1919

2020
//
2121
// Logical operation

glm/detail/setup.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373

7474

7575

76-
namespace glm{
76+
namespace glm {
7777

7878
typedef size_t length_t;
7979

glm/detail/type_traits.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515

16-
namespace glm{
16+
namespace glm {
1717

1818

1919
template<typename T>

glm/geometric.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#include "detail/functions.hpp"
1313
#include "detail/functional.hpp"
1414
#include "trigonometric.hpp"
15-
#include "vec.hpp"
15+
16+
1617

1718
namespace glm{
1819

glm/glm.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,29 @@
1010
#define GLM_HPP_20211115201400
1111

1212
#include "detail/setup.hpp"
13-
#include "detail/functions.hpp"
1413
#include "detail/functional.hpp"
14+
#include "detail/functions.hpp"
1515
#include "detail/logical.hpp"
1616
#include "detail/type_traits.hpp"
1717

1818
#include "vec2.hpp"
1919
#include "vec3.hpp"
2020
#include "vec4.hpp"
2121

22-
#include "mat2.hpp"
23-
#include "mat3.hpp"
24-
#include "mat4.hpp"
22+
#include "mat2x2.hpp"
23+
#include "mat2x3.hpp"
24+
#include "mat2x4.hpp"
25+
#include "mat3x2.hpp"
26+
#include "mat3x3.hpp"
27+
#include "mat3x4.hpp"
28+
#include "mat4x2.hpp"
29+
#include "mat4x3.hpp"
30+
#include "mat4x4.hpp"
2531

2632
#include "geometric.hpp"
2733
#include "trigonometric.hpp"
34+
#include "gtc/matrix_determinant.hpp"
35+
#include "gtc/matrix_inverse.hpp"
2836
#include "gtc/operator.hpp"
2937
#include "gtx/io.hpp"
3038
#include "gtx/string_cast.hpp"

glm/gtc/matrix_determinant.hpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright (c) 2005-2020 sdragonx (mail:sdragonx@foxmail.com)
3+
4+
glm.matrix_determinant.hpp
5+
6+
2022-02-13 23:01:45
7+
8+
*/
9+
#ifndef GLM_MATRIX_DETERMINANT_HPP_20220213230145
10+
#define GLM_MATRIX_DETERMINANT_HPP_20220213230145
11+
12+
#include "../matrix.hpp"
13+
14+
15+
16+
namespace glm {
17+
18+
//
19+
// bool mat2_determinant( in mat2, out T )
20+
//
21+
22+
template<typename T>
23+
T determinant(const mat<2, 2, T>& m)
24+
{
25+
return m[0][0] * m[1][1] - m[0][1] * m[1][0];
26+
}
27+
28+
//
29+
// bool mat3_determinant( in mat3, out T )
30+
//
31+
32+
template<typename T>
33+
GLM_API T determinant(const mat<3, 3, T>& m)
34+
{
35+
return
36+
+ m[0][0] * (m[1][1] * m[2][2] - m[2][1] * m[1][2])
37+
- m[1][0] * (m[0][1] * m[2][2] - m[2][1] * m[0][2])
38+
+ m[2][0] * (m[0][1] * m[1][2] - m[1][1] * m[0][2]);
39+
}
40+
41+
//
42+
// bool mat4_determinant( in mat4, out T )
43+
//
44+
45+
template<typename T>
46+
GLM_API T determinant(const mat<4, 4, T>& m)
47+
{
48+
T a0 = m[0][0] * m[1][1] - m[0][1] * m[1][0];
49+
T a1 = m[0][0] * m[1][2] - m[0][2] * m[1][0];
50+
T a2 = m[0][0] * m[1][3] - m[0][3] * m[1][0];
51+
T a3 = m[0][1] * m[1][2] - m[0][2] * m[1][1];
52+
T a4 = m[0][1] * m[1][3] - m[0][3] * m[1][1];
53+
T a5 = m[0][2] * m[1][3] - m[0][3] * m[1][2];
54+
T b0 = m[2][0] * m[3][1] - m[2][1] * m[3][0];
55+
T b1 = m[2][0] * m[3][2] - m[2][2] * m[3][0];
56+
T b2 = m[2][0] * m[3][3] - m[2][3] * m[3][0];
57+
T b3 = m[2][1] * m[3][2] - m[2][2] * m[3][1];
58+
T b4 = m[2][1] * m[3][3] - m[2][3] * m[3][1];
59+
T b5 = m[2][2] * m[3][3] - m[2][3] * m[3][2];
60+
61+
return a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
62+
}
63+
64+
}// end namespace glm
65+
66+
#endif// GLM_MATRIX_DETERMINANT_HPP_20220213230145

glm/gtc/matrix_inverse.hpp

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
Copyright (c) 2005-2020 sdragonx (mail:sdragonx@foxmail.com)
3+
4+
matrix_inverse.hpp
5+
6+
2022-02-13 23:00:38
7+
8+
*/
9+
#ifndef GLM_MATRIX_INVERSE_HPP_20220213230038
10+
#define GLM_MATRIX_INVERSE_HPP_20220213230038
11+
12+
#include "matrix_determinant.hpp"
13+
14+
15+
16+
namespace glm {
17+
18+
//
19+
// mat2 inverse( in mat2 )
20+
//
21+
22+
template<typename T>
23+
GLM_API mat<2, 2, T> inverse(const mat<2, 2, T>& m)
24+
{
25+
T d = mat2_determinant(m);
26+
27+
if (abs(d) < constants<T>::epsilon) {
28+
return m;
29+
}
30+
31+
d = constants<T>::one / d;
32+
33+
mat<2, 2, T> product;
34+
product[0][0] = + m[1][1] * d;
35+
product[0][1] = - m[0][1] * d;
36+
product[1][0] = - m[1][0] * d;
37+
product[1][1] = + m[0][0] * d;
38+
39+
return product;
40+
}
41+
42+
43+
//
44+
// mat3 inverse( in mat3 )
45+
//
46+
47+
template<typename T>
48+
GLM_API mat<3, 3, T> inverse(const mat<3, 3, T>& m)
49+
{
50+
T d = determinant(m);
51+
52+
if (abs(d) < constants<T>::epsilon) {
53+
return m;
54+
}
55+
56+
d = constants<T>::one / d;
57+
58+
mat<3, 3, T> product;
59+
product[0][0] = +(m[1][1] * m[2][2] - m[2][1] * m[1][2]) * d;
60+
product[0][1] = -(m[0][1] * m[2][2] - m[2][1] * m[0][2]) * d;
61+
product[0][2] = +(m[0][1] * m[1][2] - m[1][1] * m[0][2]) * d;
62+
product[1][0] = -(m[1][0] * m[2][2] - m[2][0] * m[1][2]) * d;
63+
product[1][1] = +(m[0][0] * m[2][2] - m[2][0] * m[0][2]) * d;
64+
product[1][2] = -(m[0][0] * m[1][2] - m[1][0] * m[0][2]) * d;
65+
product[2][0] = +(m[1][0] * m[2][1] - m[2][0] * m[1][1]) * d;
66+
product[2][1] = -(m[0][0] * m[2][1] - m[2][0] * m[0][1]) * d;
67+
product[2][2] = +(m[0][0] * m[1][1] - m[1][0] * m[0][1]) * d;
68+
69+
return product;
70+
}
71+
72+
//
73+
// mat4 inverse( in mat4 )
74+
//
75+
76+
template<typename T>
77+
GLM_API mat<4, 4, T> inverse(const mat<4, 4, T>& m)
78+
{
79+
T a0 = m[0][0] * m[1][1] - m[0][1] * m[1][0];
80+
T a1 = m[0][0] * m[1][2] - m[0][2] * m[1][0];
81+
T a2 = m[0][0] * m[1][3] - m[0][3] * m[1][0];
82+
T a3 = m[0][1] * m[1][2] - m[0][2] * m[1][1];
83+
T a4 = m[0][1] * m[1][3] - m[0][3] * m[1][1];
84+
T a5 = m[0][2] * m[1][3] - m[0][3] * m[1][2];
85+
T b0 = m[2][0] * m[3][1] - m[2][1] * m[3][0];
86+
T b1 = m[2][0] * m[3][2] - m[2][2] * m[3][0];
87+
T b2 = m[2][0] * m[3][3] - m[2][3] * m[3][0];
88+
T b3 = m[2][1] * m[3][2] - m[2][2] * m[3][1];
89+
T b4 = m[2][1] * m[3][3] - m[2][3] * m[3][1];
90+
T b5 = m[2][2] * m[3][3] - m[2][3] * m[3][2];
91+
92+
// calculate the determinant.
93+
T d = a0 * b5 - a1 * b4 + a2 * b3 + a3 * b2 - a4 * b1 + a5 * b0;
94+
95+
if (abs(d) < constants<T>::epsilon) {
96+
return m;
97+
}
98+
99+
d = constants<T>::one / d;
100+
101+
mat<4, 4, T> product;
102+
product[0][0] = (+ m[1][1] * b5 - m[1][2] * b4 + m[1][3] * b3) * d;
103+
product[0][1] = (- m[0][1] * b5 + m[0][2] * b4 - m[0][3] * b3) * d;
104+
product[0][2] = (+ m[3][1] * a5 - m[3][2] * a4 + m[3][3] * a3) * d;
105+
product[0][3] = (- m[2][1] * a5 + m[2][2] * a4 - m[2][3] * a3) * d;
106+
107+
product[1][0] = (- m[1][0] * b5 + m[1][2] * b2 - m[1][3] * b1) * d;
108+
product[1][1] = (+ m[0][0] * b5 - m[0][2] * b2 + m[0][3] * b1) * d;
109+
product[1][2] = (- m[3][0] * a5 + m[3][2] * a2 - m[3][3] * a1) * d;
110+
product[1][3] = (+ m[2][0] * a5 - m[2][2] * a2 + m[2][3] * a1) * d;
111+
112+
product[2][0] = (+ m[1][0] * b4 - m[1][1] * b2 + m[1][3] * b0) * d;
113+
product[2][1] = (- m[0][0] * b4 + m[0][1] * b2 - m[0][3] * b0) * d;
114+
product[2][2] = (+ m[3][0] * a4 - m[3][1] * a2 + m[3][3] * a0) * d;
115+
product[2][3] = (- m[2][0] * a4 + m[2][1] * a2 - m[2][3] * a0) * d;
116+
117+
product[3][0] = (- m[1][0] * b3 + m[1][1] * b1 - m[1][2] * b0) * d;
118+
product[3][1] = (+ m[0][0] * b3 - m[0][1] * b1 + m[0][2] * b0) * d;
119+
product[3][2] = (- m[3][0] * a3 + m[3][1] * a1 - m[3][2] * a0) * d;
120+
product[3][3] = (+ m[2][0] * a3 - m[2][1] * a1 + m[2][2] * a0) * d;
121+
122+
return product;
123+
}
124+
125+
126+
}// end namespace glm
127+
128+
#endif// GLM_MATRIX_INVERSE_HPP_20220213230038

0 commit comments

Comments
 (0)