Skip to content

Commit 90f2b02

Browse files
Fixed EXT_matrix_transform inverted shear matrix multiple #1140 #1182
1 parent 7adb4a5 commit 90f2b02

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

glm/ext/matrix_transform.inl

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ namespace glm
117117
);
118118

119119
mat<4, 4, T, Q> Result;
120-
Result[0] = Shear[0] * m[0][0] + Shear[1] * m[0][1] + Shear[2] * m[0][2] + Shear[3] * m[0][3];
121-
Result[1] = Shear[0] * m[1][0] + Shear[1] * m[1][1] + Shear[2] * m[1][2] + Shear[3] * m[1][3];
122-
Result[2] = Shear[0] * m[2][0] + Shear[1] * m[2][1] + Shear[2] * m[2][2] + Shear[3] * m[2][3];
123-
Result[3] = Shear[0] * m[3][0] + Shear[1] * m[3][1] + Shear[2] * m[3][2] + Shear[3] * m[3][3];
120+
Result[0] = m[0] * Shear[0][0] + m[1] * Shear[0][1] + m[2] * Shear[0][2] + m[3] * Shear[0][3];
121+
Result[1] = m[0] * Shear[1][0] + m[1] * Shear[1][1] + m[2] * Shear[1][2] + m[3] * Shear[1][3];
122+
Result[2] = m[0] * Shear[2][0] + m[1] * Shear[2][1] + m[2] * Shear[2][2] + m[3] * Shear[2][3];
123+
Result[3] = m[0] * Shear[3][0] + m[1] * Shear[3][1] + m[2] * Shear[3][2] + m[3] * Shear[3][3];
124124
return Result;
125125
}
126126

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ target_link_libraries(main PRIVATE glm::glm)
114114
#### Fixes:
115115
- Fixed C++ language auto detection build, disable C++98 warnings with Clang #1235, #1231
116116
- Fixed `GTX_color_space` missing <glm/ext/scalar_constants.hpp> include #1233 #1238
117+
- Fixed `EXT_matrix_transform` `shear` implementation #1140 #1182
117118

118119
### [GLM 1.0.0](https://github.com/g-truc/glm/releases/tag/1.0.0) - 2024-01-24
119120
#### Features:

test/core/core_func_matrix.cpp

+25-16
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,14 @@ static int test_shearing()
280280
glm::vec4(1, 1, 1, 0),
281281
glm::vec4(1, 1, 0, 1));
282282
glm::mat4x4 const B4x4 = glm::shear(A4x4, center, l_x, l_y, l_z);
283+
glm::mat4x4 const C4x4 = glm::shear_slow(A4x4, center, l_x, l_y, l_z);
283284
glm::mat4x4 const expected(
284285
glm::vec4(0, 0, 1, 1),
285-
glm::vec4(2, 1, 1, 0),
286-
glm::vec4(3, 1, 1, 0),
287-
glm::vec4(3, 1, 0, 1));
286+
glm::vec4(0, 1, 3, 2),
287+
glm::vec4(1, 1, 1, 0),
288+
glm::vec4(1, 1, 0, 1));
288289
Error += all(equal(B4x4, expected, epsilon<float>())) ? 0 : 1;
290+
Error += all(equal(C4x4, expected, epsilon<float>())) ? 0 : 1;
289291
}
290292

291293
{
@@ -299,12 +301,14 @@ static int test_shearing()
299301
glm::vec4(1, 1, 1, 0),
300302
glm::vec4(1, 0, 0, 0));
301303
glm::mat4x4 const B4x4 = glm::shear(A4x4, center, l_x, l_y, l_z);
304+
glm::mat4x4 const C4x4 = glm::shear_slow(A4x4, center, l_x, l_y, l_z);
302305
glm::mat4x4 const expected(
303-
glm::vec4(0, 1, 1, 0),
304-
glm::vec4(1, 2, 1, 0),
305-
glm::vec4(2, 2, 2, 0),
306-
glm::vec4(1, 0, 1, 0));
306+
glm::vec4(1, 1, 2, 0),
307+
glm::vec4(0, 1, 2, 0),
308+
glm::vec4(1, 2, 2, 0),
309+
glm::vec4(1, 0, 0, 0));
307310
Error += all(equal(B4x4, expected, epsilon<float>())) ? 0 : 1;
311+
Error += all(equal(C4x4, expected, epsilon<float>())) ? 0 : 1;
308312
}
309313

310314
{
@@ -314,12 +318,14 @@ static int test_shearing()
314318
glm::vec2 const l_z(4, 5);
315319
glm::mat4x4 const A4x4(1);
316320
glm::mat4x4 const B4x4 = glm::shear(A4x4, center, l_x, l_y, l_z);
321+
glm::mat4x4 const C4x4 = glm::shear_slow(A4x4, center, l_x, l_y, l_z);
317322
glm::mat4x4 const expected(
318323
glm::vec4(1, 3, 4, 0),
319324
glm::vec4(1, 1, 5, 0),
320325
glm::vec4(2, 1, 1, 0),
321326
glm::vec4(-9, -8, -9, 1));
322327
Error += all(equal(B4x4, expected, epsilon<float>())) ? 0 : 1;
328+
Error += all(equal(C4x4, expected, epsilon<float>())) ? 0 : 1;
323329
}
324330

325331
{
@@ -333,12 +339,14 @@ static int test_shearing()
333339
glm::vec4(4, -8, 0, 0),
334340
glm::vec4(7, 1, -2, 0));
335341
glm::mat4x4 const B4x4 = glm::shear(A4x4, center, l_x, l_y, l_z);
342+
glm::mat4x4 const C4x4 = glm::shear_slow(A4x4, center, l_x, l_y, l_z);
336343
glm::mat4x4 const expected(
337-
glm::vec4(1, -6, -1, 0),
338-
glm::vec4(7, 12, 23, 0),
339-
glm::vec4(-4, 4, -24, 0),
340-
glm::vec4(4, 20, 31, 0));
344+
glm::vec4(22, -24, 4, 0),
345+
glm::vec4(20, -36, 2, 0),
346+
glm::vec4(1, -2, 3, 0),
347+
glm::vec4(-26, 39, -19, 0));
341348
Error += all(equal(B4x4, expected, epsilon<float>())) ? 0 : 1;
349+
Error += all(equal(C4x4, expected, epsilon<float>())) ? 0 : 1;
342350
}
343351

344352
return Error;
@@ -392,19 +400,20 @@ static int test_inverse_perf(std::size_t Count, std::size_t Instance, char const
392400
int main()
393401
{
394402
int Error = 0;
403+
395404
Error += test_matrixCompMult();
396405
Error += test_outerProduct();
397406
Error += test_transpose();
398407
Error += test_determinant();
399408
Error += test_inverse();
400-
Error += test_inverse_simd();
401-
Error += test_shearing();
409+
Error += test_inverse_simd();
410+
Error += test_shearing();
402411

403-
# ifdef NDEBUG
412+
#ifdef NDEBUG
404413
std::size_t const Samples = 1000;
405-
# else
414+
#else
406415
std::size_t const Samples = 1;
407-
# endif//NDEBUG
416+
#endif//NDEBUG
408417

409418
for(std::size_t i = 0; i < 1; ++i)
410419
{

0 commit comments

Comments
 (0)