Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
test_math_mat4f_11_unproject.cpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2024 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24#include <thread>
25#include <cassert>
26#include <cinttypes>
27#include <cstring>
28
30
32
33using namespace jau;
34using namespace jau::math;
35using namespace jau::math::util;
36
37static const float NaN = std::numeric_limits<float>::quiet_NaN();
38
39TEST_CASE( "Test 01 Unproject NaN", "[unproject][mat4f][linear_algebra][math]" ) {
40 const Mat4f mMv({1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1});
41 const Mat4f mP({1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1});
42 const Recti viewport(0,0,800,600);
43 const float pick[] = { 400, 300, 0 };
44
45 Vec3f objPos(NaN, NaN, NaN);
46 Mat4f tmp;
47
48 // gluUnProject
49 bool res = Mat4f::mapWinToObj(pick[0], pick[1], pick[2],
50 mMv, mP, viewport,
51 objPos, tmp);
52
53 REQUIRE( false == std::isnan(objPos.x) );
54 REQUIRE( false == std::isnan(objPos.y) );
55 REQUIRE( false == std::isnan(objPos.z) );
56
57 REQUIRE( true == res );
58}
59
60TEST_CASE( "Test 10 Unproject Pick 1", "[unproject][mat4f][linear_algebra][math]" ) {
61 const Mat4f mMv({ 1, 0, 0, 0,
62 0, 1, 0, 0,
63 0, 0, 1, 0,
64 0, 0, 0, 1 });
65 const Mat4f mP({ 2.3464675f, 0, 0, 0,
66 0, 2.4142134f, 0, 0,
67 0, 0, -1.0002f, -1,
68 0, 0, -20.002f, 0 });
69 const Recti viewport(0, 0, 1000, 1000);
70 const float pick[] = { 250, 250, 0.5f };
71
72 const Vec3f expected(-4.2612f, -4.1417f, -19.9980f );
73 Vec3f result;
74 Mat4f tmp;
75
76 // gluUnProject
77 bool res = Mat4f::mapWinToObj(pick[0], pick[1], pick[2],
78 mMv, mP, viewport,
79 result, tmp);
80
81 REQUIRE( true == res );
82 COMPARE_NARRAYS_EPS(expected.cbegin(), result.cbegin(), 3, 0.0001f);
83}
84
85TEST_CASE( "Test 11 Unproject Pick 2", "[unproject][mat4f][linear_algebra][math]" ) {
86 const Mat4f mMv({ 1, 0, 0, 0,
87 0, 1, 0, 0,
88 0, 0, 1, 0,
89 0, 0, -200, 1 });
90 const Mat4f mP({ 2.3464675f, 0, 0, 0,
91 0, 2.4142134f, 0, 0,
92 0, 0, -1.0002f, -1,
93 0, 0, -20.002f, 0 });
94 const Recti viewport(0, 0, 1000, 1000);
95 const float pick[] = { 250, 250, 0.5f };
96
97 const Vec3f expected(-4.2612f, -4.1417f, 180.002f );
98 Vec3f result;
99 Mat4f tmp;
100
101 // gluUnProject
102 bool res = Mat4f::mapWinToObj(pick[0], pick[1], pick[2],
103 mMv, mP, viewport,
104 result, tmp);
105
106 REQUIRE( true == res );
107 COMPARE_NARRAYS_EPS(expected.cbegin(), result.cbegin(), 3, 0.0001f);
108}
109
#define COMPARE_NARRAYS_EPS(lhs, rhs, len, eps)
Definition: catch2_ext.hpp:102
Basic 4x4 value_type matrix implementation using fields for intensive use-cases (host operations).
Definition: mat4f.hpp:112
Rectangle with x, y, width and height integer components.
Definition: recti.hpp:43
value_type x
Definition: vec3f.hpp:72
constexpr const_iterator cbegin() const noexcept
Definition: vec3f.hpp:106
value_type y
Definition: vec3f.hpp:73
value_type z
Definition: vec3f.hpp:74
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition: backtrace.hpp:32
TEST_CASE("Test 01 Unproject NaN", "[unproject][mat4f][linear_algebra][math]")
static const float NaN