-
-
Notifications
You must be signed in to change notification settings - Fork 442
Expand file tree
/
Copy pathTestSDKCamera.cxx
More file actions
223 lines (192 loc) · 7.67 KB
/
Copy pathTestSDKCamera.cxx
File metadata and controls
223 lines (192 loc) · 7.67 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include "PseudoUnitTest.h"
#include "TestSDKHelpers.h"
#include <camera.h>
#include <engine.h>
#include <log.h>
#include <options.h>
#include <window.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <sstream>
#include <vector>
#include <utility>
int TestSDKCamera([[maybe_unused]] int argc, [[maybe_unused]] char* argv[])
{
PseudoUnitTest test;
f3d::log::setVerboseLevel(f3d::log::VerboseLevel::DEBUG);
f3d::engine eng = f3d::engine::create(true);
f3d::window& win = eng.getWindow();
f3d::camera& cam = win.getCamera();
// check coordinates conversion
f3d::point3_t point = { 0.1, 0.1, 0.1 };
f3d::point3_t pointDC = win.getDisplayFromWorld(point);
test("coordinates conversion", point, approx(win.getWorldFromDisplay(pointDC)));
// Test position
f3d::point3_t testPos = { 0., 0., 10. };
f3d::point3_t pos = cam.setPosition(testPos).getPosition();
test("set/get position", pos, testPos);
// Test focal point
f3d::point3_t testFoc = { 0., 0., -1. };
f3d::point3_t foc = cam.setFocalPoint(testFoc).getFocalPoint();
test("set/get focal point", foc, testFoc);
// Test view up
f3d::vector3_t testUp = { 1., 0., 0. };
f3d::vector3_t up = cam.setViewUp(testUp).getViewUp();
test("set/get view up", up, testUp);
// Test view angle
f3d::angle_deg_t testAngle = 20;
f3d::angle_deg_t angle = cam.setViewAngle(testAngle).getViewAngle();
test("set/get view angle", angle, testAngle);
// Test azimuth
cam.azimuth(90);
f3d::point3_t expectedPos = { 0., -11., -1. };
f3d::point3_t expectedFoc = { 0., 0., -1. };
f3d::vector3_t expectedUp = { 1., 0., 0. };
pos = cam.getPosition();
foc = cam.getFocalPoint();
up = cam.getViewUp();
test("azimuth method position", pos, approx(expectedPos));
test("azimuth method focal point", foc, approx(expectedFoc));
test("azimuth method up", up, approx(expectedUp));
// Test roll
cam.roll(90);
expectedUp = { 0., 0., -1. };
pos = cam.getPosition();
foc = cam.getFocalPoint();
up = cam.getViewUp();
test("roll method position", pos, approx(expectedPos));
test("roll method focal point", foc, approx(expectedFoc));
test("roll method up", up, approx(expectedUp));
// Test yaw
cam.yaw(90);
expectedFoc = { 11., -11., -1. };
pos = cam.getPosition();
foc = cam.getFocalPoint();
up = cam.getViewUp();
test("yaw method position", pos, approx(expectedPos));
test("yaw method focal point", foc, approx(expectedFoc));
test("yaw method up", up, approx(expectedUp));
// Test elevation
cam.elevation(90);
expectedPos = { 11., -11., -12. };
expectedUp = { 1., 0., 0. };
pos = cam.getPosition();
foc = cam.getFocalPoint();
up = cam.getViewUp();
test("elevation method position", pos, approx(expectedPos));
test("elevation method focal point", foc, approx(expectedFoc));
test("elevation method up", up, approx(expectedUp));
// Test pitch
cam.pitch(90);
expectedFoc = { 22., -11., -12. };
expectedUp = { 0., 0., -1. };
pos = cam.getPosition();
foc = cam.getFocalPoint();
up = cam.getViewUp();
test("pitch method position", pos, approx(expectedPos));
test("pitch method focal point", foc, approx(expectedFoc));
test("pitch method up", up, approx(expectedUp));
// Test dolly
cam.dolly(10);
expectedPos = { 20.9, -11., -12. };
pos = cam.getPosition();
foc = cam.getFocalPoint();
up = cam.getViewUp();
test("dolly method position", pos, approx(expectedPos));
test("dolly method focal point", foc, approx(expectedFoc));
test("dolly method up", up, approx(expectedUp));
cam.setPosition({ 1, 2, 3 });
cam.setFocalPoint({ 1, 2, 13 });
cam.setViewUp({ 0, 1, 0 });
cam.pan(1, 2);
test("pos after pan", cam.getPosition(), { 0, 4, 3 });
test("foc after pan", cam.getFocalPoint(), { 0, 4, 13 });
test("up after pan", cam.getViewUp(), { 0, 1, 0 });
cam.setPosition({ 1, 2, 3 });
cam.setFocalPoint({ 1, -2, 3 });
cam.setViewUp({ 0, 0, 1 });
cam.pan(3, 4, 5);
test("pos after pan", cam.getPosition(), { -2, -3, 7 });
test("foc after pan", cam.getFocalPoint(), { -2, -7, 7 });
test("up after pan", cam.getViewUp(), { 0, 0, 1 });
cam.setPosition({ 1, 2, 3 });
cam.setFocalPoint({ 1, 2, 13 });
cam.setViewUp({ 0, 1, 0 });
cam.setViewAngle(25);
cam.zoom(1.5);
test("pos after zoom", cam.getPosition(), { 1, 2, 3 });
test("foc after zoom", cam.getFocalPoint(), { 1, 2, 13 });
test("up after zoom", cam.getViewUp(), { 0, 1, 0 });
test("angle after zoom", cam.getViewAngle(), 25 / 1.5);
cam.setPosition({ 1, 0, 0 });
cam.setFocalPoint({ 0, 0, 0 });
cam.setViewUp({ 1, 0, 0 });
test("pos when cross product of pos->foc and up is 0 - test 1", cam.getPosition(), { 1, 0, 0 });
test("foc when cross product of pos->foc and up is 0 - test 1", cam.getFocalPoint(), { 0, 0, 0 });
test("up when cross product of pos->foc and up is 0 - test 1", cam.getViewUp(), { 0, 1, 0 });
cam.setPosition({ 0, 1, 0 });
cam.setFocalPoint({ 0, 0, 0 });
cam.setViewUp({ 0, 1, 0 });
test("pos when cross product of pos->foc and up is 0 - test 2", cam.getPosition(), { 0, 1, 0 });
test("foc when cross product of pos->foc and up is 0 - test 2", cam.getFocalPoint(), { 0, 0, 0 });
test("up when cross product of pos->foc and up is 0 - test 2", cam.getViewUp(), { 1, 0, 0 });
cam.setPosition({ 0, 0, 1 });
cam.setFocalPoint({ 0, 0, 0 });
cam.setViewUp({ 0, 0, 1 });
test("pos when cross product of pos->foc and up is 0 - test 3", cam.getPosition(), { 0, 0, 1 });
test("foc when cross product of pos->foc and up is 0 - test 3", cam.getFocalPoint(), { 0, 0, 0 });
test("up when cross product of pos->foc and up is 0 - test 3", cam.getViewUp(), { 1, 0, 0 });
cam.setPosition({ 5, 0, 0 });
cam.setFocalPoint({ 1, 0, 0 });
cam.setViewUp({ 1, 0, 0 });
test("pos when cross product of pos->foc and up is 0 - test 4", cam.getPosition(), { 5, 0, 0 });
test("foc when cross product of pos->foc and up is 0 - test 4", cam.getFocalPoint(), { 1, 0, 0 });
test("up when cross product of pos->foc and up is 0 - test 4", cam.getViewUp(), { 0, 1, 0 });
// -------------------------------------------------------------------------
// New Camera Parameter Getter Unit Tests
// -------------------------------------------------------------------------
cam.setPosition({ 0., -10., 0. });
cam.setFocalPoint({ 0., 0., 0. });
test("Distance: 10", cam.getDistance(), approx(10.0));
cam.setPosition({ -10., 0., 0. });
cam.setFocalPoint({ 0., 0., 0. });
cam.setViewUp({ 0., 1., 0. });
test("Azimuth (Y-up): environment forward (+X)", cam.getWorldAzimuth(), approx(90.0));
// Equivalence matrix tests (setter/getter verification)
std::vector<f3d::direction_t> up_directions = {
{ 0, 0, +1 },
{ 0, +1, 0 },
{ +1, 0, 0 },
{ 0, 0, -1 },
{ 0, -1, 0 },
{ -1, 0, 0 },
{ -1, +2, +3 },
{ +4, -5, -6 },
};
const std::vector<std::pair<double, double>> azimuths_elevations = {
{ 0, 0 },
{ +12, +34 },
{ +12, -34 },
{ -12, +34 },
{ -12, -34 },
};
for (const auto up_dir : up_directions)
{
for (auto [a, e] : azimuths_elevations)
{
f3d::engine matrix_eng = f3d::engine::create(true);
f3d::window& matrix_win = matrix_eng.getWindow();
f3d::camera& matrix_cam = matrix_win.getCamera();
f3d::options& opt = matrix_eng.getOptions();
opt.scene.up_direction = up_dir;
matrix_win.render();
matrix_cam.azimuth(a).elevation(e);
const std::string title = " after .azimuth(" + f3d::options::format(a) + ").elevation(" +
f3d::options::format(e) + ") with up = " + f3d::options::format(up_dir);
test("azimuth " + title, matrix_cam.getWorldAzimuth(), approx(a, 1e-10));
test("elevation" + title, matrix_cam.getWorldElevation(), approx(e, 1e-10));
}
}
return test.result();
}