Skip to content

Commit a7f4dbe

Browse files
committed
Adjust camera common header's namespaces
1 parent adfd43e commit a7f4dbe

File tree

1 file changed

+76
-80
lines changed

1 file changed

+76
-80
lines changed

examples_tests/common/Camera.hpp

Lines changed: 76 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@
1111
#include <fstream>
1212
#include <chrono>
1313

14-
using namespace nbl;
15-
using namespace core;
16-
using namespace ui;
17-
1814
class Camera {
1915
public:
20-
Camera( const core::vectorSIMDf& position,
21-
const core::vectorSIMDf& lookat,
22-
const core::matrix4SIMD& projection,
16+
Camera(const nbl::core::vectorSIMDf& position,
17+
const nbl::core::vectorSIMDf& lookat,
18+
const nbl::core::matrix4SIMD& projection,
2319
float moveSpeed = 1.0f,
2420
float rotateSpeed = 1.0f,
25-
const core::vectorSIMDf& upVec = core::vectorSIMDf(0.0f, 1.0f, 0.0f),
26-
const core::vectorSIMDf& backupUpVec = core::vectorSIMDf(0.5f, 1.0f, 0.0f)
21+
const nbl::core::vectorSIMDf& upVec = nbl::core::vectorSIMDf(0.0f, 1.0f, 0.0f),
22+
const nbl::core::vectorSIMDf& backupUpVec = nbl::core::vectorSIMDf(0.5f, 1.0f, 0.0f)
2723
)
2824
: position(position)
2925
, target(lookat)
@@ -42,90 +38,90 @@ class Camera {
4238

4339
public:
4440

45-
inline const core::matrix4SIMD& getProjectionMatrix() const { return projMatrix; }
46-
inline const core::matrix3x4SIMD & getViewMatrix() const { return viewMatrix; }
47-
inline const core::matrix4SIMD & getConcatenatedMatrix() const { return concatMatrix; }
41+
inline const nbl::core::matrix4SIMD& getProjectionMatrix() const { return projMatrix; }
42+
inline const nbl::core::matrix3x4SIMD & getViewMatrix() const { return viewMatrix; }
43+
inline const nbl::core::matrix4SIMD & getConcatenatedMatrix() const { return concatMatrix; }
4844

49-
inline void setProjectionMatrix(const core::matrix4SIMD& projection) {
45+
inline void setProjectionMatrix(const nbl::core::matrix4SIMD& projection) {
5046
projMatrix = projection;
51-
leftHanded = core::determinant(projMatrix) < 0.f;
52-
concatMatrix = core::matrix4SIMD::concatenateBFollowedByAPrecisely(projMatrix, core::matrix4SIMD(viewMatrix));
47+
leftHanded = nbl::core::determinant(projMatrix) < 0.f;
48+
concatMatrix = nbl::core::matrix4SIMD::concatenateBFollowedByAPrecisely(projMatrix, nbl::core::matrix4SIMD(viewMatrix));
5349
}
5450

55-
inline void setPosition(const core::vectorSIMDf& pos) {
51+
inline void setPosition(const nbl::core::vectorSIMDf& pos) {
5652
position.set(pos);
5753
recomputeViewMatrix();
5854
}
5955

60-
inline const core::vectorSIMDf& getPosition() const { return position; }
56+
inline const nbl::core::vectorSIMDf& getPosition() const { return position; }
6157

62-
inline void setTarget(const core::vectorSIMDf& pos) {
58+
inline void setTarget(const nbl::core::vectorSIMDf& pos) {
6359
target.set(pos);
6460
recomputeViewMatrix();
6561
}
6662

67-
inline const core::vectorSIMDf& getTarget() const { return target; }
63+
inline const nbl::core::vectorSIMDf& getTarget() const { return target; }
6864

69-
inline void setUpVector(const core::vectorSIMDf& up) {
65+
inline void setUpVector(const nbl::core::vectorSIMDf& up) {
7066
upVector = up;
7167
}
7268

73-
inline void setBackupUpVector(const core::vectorSIMDf& up) {
69+
inline void setBackupUpVector(const nbl::core::vectorSIMDf& up) {
7470
backupUpVector = up;
7571
}
7672

77-
inline const core::vectorSIMDf& getUpVector() const { return upVector; }
73+
inline const nbl::core::vectorSIMDf& getUpVector() const { return upVector; }
7874

79-
inline const core::vectorSIMDf& getBackupUpVector() const { return backupUpVector; }
75+
inline const nbl::core::vectorSIMDf& getBackupUpVector() const { return backupUpVector; }
8076

8177
inline void recomputeViewMatrix() {
82-
core::vectorSIMDf pos = position;
83-
core::vectorSIMDf localTarget = core::normalize(target - pos);
78+
nbl::core::vectorSIMDf pos = position;
79+
nbl::core::vectorSIMDf localTarget = nbl::core::normalize(target - pos);
8480

8581
// if upvector and vector to the target are the same, we have a
8682
// problem. so solve this problem:
87-
core::vectorSIMDf up = core::normalize(upVector);
88-
core::vectorSIMDf cross = core::cross(localTarget, up);
89-
bool upVectorNeedsChange = core::lengthsquared(cross)[0] == 0;
83+
nbl::core::vectorSIMDf up = nbl::core::normalize(upVector);
84+
nbl::core::vectorSIMDf cross = nbl::core::cross(localTarget, up);
85+
bool upVectorNeedsChange = nbl::core::lengthsquared(cross)[0] == 0;
9086
if (upVectorNeedsChange)
9187
{
92-
up = core::normalize(backupUpVector);
88+
up = nbl::core::normalize(backupUpVector);
9389
}
9490

9591
if (leftHanded)
96-
viewMatrix = core::matrix3x4SIMD::buildCameraLookAtMatrixLH(pos, target, up);
92+
viewMatrix = nbl::core::matrix3x4SIMD::buildCameraLookAtMatrixLH(pos, target, up);
9793
else
98-
viewMatrix = core::matrix3x4SIMD::buildCameraLookAtMatrixRH(pos, target, up);
99-
concatMatrix = core::matrix4SIMD::concatenateBFollowedByAPrecisely(projMatrix, core::matrix4SIMD(viewMatrix));
94+
viewMatrix = nbl::core::matrix3x4SIMD::buildCameraLookAtMatrixRH(pos, target, up);
95+
concatMatrix = nbl::core::matrix4SIMD::concatenateBFollowedByAPrecisely(projMatrix, nbl::core::matrix4SIMD(viewMatrix));
10096
}
10197

10298
inline bool getLeftHanded() const { return leftHanded; }
10399

104100
public:
105101

106-
void mouseProcess(const IMouseEventChannel::range_t& events)
102+
void mouseProcess(const nbl::ui::IMouseEventChannel::range_t& events)
107103
{
108104
for (auto eventIt=events.begin(); eventIt!=events.end(); eventIt++)
109105
{
110106
auto ev = *eventIt;
111107

112-
if(ev.type == ui::SMouseEvent::EET_CLICK && ev.clickEvent.mouseButton == ui::EMB_LEFT_BUTTON) {
113-
if(ev.clickEvent.action == ui::SMouseEvent::SClickEvent::EA_PRESSED) {
108+
if(ev.type == nbl::ui::SMouseEvent::EET_CLICK && ev.clickEvent.mouseButton == nbl::ui::EMB_LEFT_BUTTON) {
109+
if(ev.clickEvent.action == nbl::ui::SMouseEvent::SClickEvent::EA_PRESSED) {
114110
mouseDown = true;
115-
} else if (ev.clickEvent.action == ui::SMouseEvent::SClickEvent::EA_RELEASED) {
111+
} else if (ev.clickEvent.action == nbl::ui::SMouseEvent::SClickEvent::EA_RELEASED) {
116112
mouseDown = false;
117113
}
118114
}
119115

120-
if(ev.type == ui::SMouseEvent::EET_MOVEMENT && mouseDown) {
121-
core::vectorSIMDf pos = getPosition();
122-
core::vectorSIMDf localTarget = getTarget() - pos;
116+
if(ev.type == nbl::ui::SMouseEvent::EET_MOVEMENT && mouseDown) {
117+
nbl::core::vectorSIMDf pos = getPosition();
118+
nbl::core::vectorSIMDf localTarget = getTarget() - pos;
123119

124120
// Get Relative Rotation for localTarget in Radians
125121
float relativeRotationX, relativeRotationY;
126122
relativeRotationY = atan2(localTarget.X, localTarget.Z);
127-
const double z1 = core::sqrt(localTarget.X*localTarget.X + localTarget.Z*localTarget.Z);
128-
relativeRotationX = atan2(z1, localTarget.Y) - core::PI<float>()/2;
123+
const double z1 = nbl::core::sqrt(localTarget.X*localTarget.X + localTarget.Z*localTarget.Z);
124+
relativeRotationX = atan2(z1, localTarget.Y) - nbl::core::PI<float>()/2;
129125

130126
constexpr float RotateSpeedScale = 0.003f;
131127
relativeRotationX -= ev.movementEvent.relativeMovementY * rotateSpeed * RotateSpeedScale * -1.0f;
@@ -135,24 +131,24 @@ class Camera {
135131
else
136132
relativeRotationY += tmpYRot;
137133

138-
const double MaxVerticalAngle = core::radians<float>(88.0f);
134+
const double MaxVerticalAngle = nbl::core::radians<float>(88.0f);
139135
if (relativeRotationX > MaxVerticalAngle*2 &&
140-
relativeRotationX < 2*core::PI<float>()-MaxVerticalAngle)
136+
relativeRotationX < 2 * nbl::core::PI<float>()-MaxVerticalAngle)
141137
{
142-
relativeRotationX = 2*core::PI<float>()-MaxVerticalAngle;
138+
relativeRotationX = 2 * nbl::core::PI<float>()-MaxVerticalAngle;
143139
}
144140
else
145141
if (relativeRotationX > MaxVerticalAngle &&
146-
relativeRotationX < 2*core::PI<float>()-MaxVerticalAngle)
142+
relativeRotationX < 2 * nbl::core::PI<float>()-MaxVerticalAngle)
147143
{
148144
relativeRotationX = MaxVerticalAngle;
149145
}
150146

151-
localTarget.set(0,0, core::max(1.f, core::length(pos)[0]), 1.f);
147+
localTarget.set(0,0, nbl::core::max(1.f, nbl::core::length(pos)[0]), 1.f);
152148

153-
core::matrix3x4SIMD mat;
149+
nbl::core::matrix3x4SIMD mat;
154150
{
155-
mat.setRotation(core::quaternion(relativeRotationX, relativeRotationY, 0));
151+
mat.setRotation(nbl::core::quaternion(relativeRotationX, relativeRotationY, 0));
156152
}
157153
mat.transformVect(localTarget);
158154

@@ -161,7 +157,7 @@ class Camera {
161157
}
162158
}
163159

164-
void keyboardProcess(const IKeyboardEventChannel::range_t& events)
160+
void keyboardProcess(const nbl::ui::IKeyboardEventChannel::range_t& events)
165161
{
166162
for(uint32_t k = 0; k < Keys::EKA_COUNT; ++k) {
167163
perActionDt[k] = 0.0;
@@ -188,38 +184,38 @@ class Camera {
188184
auto timeDiff = std::chrono::duration_cast<std::chrono::milliseconds>(nextPresentationTimeStamp - ev.timeStamp).count();
189185
assert(timeDiff >= 0);
190186

191-
if(ev.keyCode == ui::EKC_UP_ARROW || ev.keyCode == ui::EKC_W) {
192-
if(ev.action == ui::SKeyboardEvent::ECA_PRESSED && keysDown[Keys::EKA_MOVE_FORWARD] == false) {
187+
if(ev.keyCode == nbl::ui::EKC_UP_ARROW || ev.keyCode == nbl::ui::EKC_W) {
188+
if(ev.action == nbl::ui::SKeyboardEvent::ECA_PRESSED && keysDown[Keys::EKA_MOVE_FORWARD] == false) {
193189
perActionDt[Keys::EKA_MOVE_FORWARD] += timeDiff;
194190
keysDown[Keys::EKA_MOVE_FORWARD] = true;
195-
} else if(ev.action == ui::SKeyboardEvent::ECA_RELEASED) {
191+
} else if(ev.action == nbl::ui::SKeyboardEvent::ECA_RELEASED) {
196192
keysDown[Keys::EKA_MOVE_FORWARD] = false;
197193
}
198194
}
199195

200-
if(ev.keyCode == ui::EKC_DOWN_ARROW || ev.keyCode == ui::EKC_S) {
201-
if(ev.action == ui::SKeyboardEvent::ECA_PRESSED && keysDown[Keys::EKA_MOVE_BACKWARD] == false) {
196+
if(ev.keyCode == nbl::ui::EKC_DOWN_ARROW || ev.keyCode == nbl::ui::EKC_S) {
197+
if(ev.action == nbl::ui::SKeyboardEvent::ECA_PRESSED && keysDown[Keys::EKA_MOVE_BACKWARD] == false) {
202198
perActionDt[Keys::EKA_MOVE_BACKWARD] += timeDiff;
203199
keysDown[Keys::EKA_MOVE_BACKWARD] = true;
204-
} else if(ev.action == ui::SKeyboardEvent::ECA_RELEASED) {
200+
} else if(ev.action == nbl::ui::SKeyboardEvent::ECA_RELEASED) {
205201
keysDown[Keys::EKA_MOVE_BACKWARD] = false;
206202
}
207203
}
208204

209-
if(ev.keyCode == ui::EKC_LEFT_ARROW || ev.keyCode == ui::EKC_A) {
210-
if(ev.action == ui::SKeyboardEvent::ECA_PRESSED && keysDown[Keys::EKA_MOVE_LEFT] == false) {
205+
if(ev.keyCode == nbl::ui::EKC_LEFT_ARROW || ev.keyCode == nbl::ui::EKC_A) {
206+
if(ev.action == nbl::ui::SKeyboardEvent::ECA_PRESSED && keysDown[Keys::EKA_MOVE_LEFT] == false) {
211207
perActionDt[Keys::EKA_MOVE_LEFT] += timeDiff;
212208
keysDown[Keys::EKA_MOVE_LEFT] = true;
213-
} else if(ev.action == ui::SKeyboardEvent::ECA_RELEASED) {
209+
} else if(ev.action == nbl::ui::SKeyboardEvent::ECA_RELEASED) {
214210
keysDown[Keys::EKA_MOVE_LEFT] = false;
215211
}
216212
}
217213

218-
if(ev.keyCode == ui::EKC_RIGHT_ARROW || ev.keyCode == ui::EKC_D) {
219-
if(ev.action == ui::SKeyboardEvent::ECA_PRESSED && keysDown[Keys::EKA_MOVE_RIGHT] == false) {
214+
if(ev.keyCode == nbl::ui::EKC_RIGHT_ARROW || ev.keyCode == nbl::ui::EKC_D) {
215+
if(ev.action == nbl::ui::SKeyboardEvent::ECA_PRESSED && keysDown[Keys::EKA_MOVE_RIGHT] == false) {
220216
perActionDt[Keys::EKA_MOVE_RIGHT] += timeDiff;
221217
keysDown[Keys::EKA_MOVE_RIGHT] = true;
222-
} else if(ev.action == ui::SKeyboardEvent::ECA_RELEASED) {
218+
} else if(ev.action == nbl::ui::SKeyboardEvent::ECA_RELEASED) {
223219
keysDown[Keys::EKA_MOVE_RIGHT] = false;
224220
}
225221
}
@@ -239,12 +235,12 @@ class Camera {
239235
}
240236

241237
void endInputProcessing(std::chrono::microseconds _nextPresentationTimeStamp) {
242-
core::vectorSIMDf pos = getPosition();
243-
core::vectorSIMDf localTarget = getTarget() - pos;
238+
nbl::core::vectorSIMDf pos = getPosition();
239+
nbl::core::vectorSIMDf localTarget = getTarget() - pos;
244240

245-
core::vectorSIMDf movedir = localTarget;
241+
nbl::core::vectorSIMDf movedir = localTarget;
246242
movedir.makeSafe3D();
247-
movedir = core::normalize(movedir);
243+
movedir = nbl::core::normalize(movedir);
248244

249245
constexpr float MoveSpeedScale = 0.02f;
250246

@@ -256,21 +252,21 @@ class Camera {
256252

257253
// if upvector and vector to the target are the same, we have a
258254
// problem. so solve this problem:
259-
core::vectorSIMDf up = core::normalize(upVector);
260-
core::vectorSIMDf cross = core::cross(localTarget, up);
261-
bool upVectorNeedsChange = core::lengthsquared(cross)[0] == 0;
255+
nbl::core::vectorSIMDf up = nbl::core::normalize(upVector);
256+
nbl::core::vectorSIMDf cross = nbl::core::cross(localTarget, up);
257+
bool upVectorNeedsChange = nbl::core::lengthsquared(cross)[0] == 0;
262258
if (upVectorNeedsChange)
263259
{
264-
up = core::normalize(backupUpVector);
260+
up = nbl::core::normalize(backupUpVector);
265261
}
266262

267-
core::vectorSIMDf strafevect = localTarget;
263+
nbl::core::vectorSIMDf strafevect = localTarget;
268264
if (leftHanded)
269-
strafevect = core::cross(strafevect, up);
265+
strafevect = nbl::core::cross(strafevect, up);
270266
else
271-
strafevect = core::cross(up, strafevect);
267+
strafevect = nbl::core::cross(up, strafevect);
272268

273-
strafevect = core::normalize(strafevect);
269+
strafevect = nbl::core::normalize(strafevect);
274270

275271
pos += strafevect * perActionDt[Keys::EKA_MOVE_LEFT] * moveSpeed * MoveSpeedScale;
276272

@@ -293,16 +289,16 @@ class Camera {
293289
}
294290

295291
private:
296-
core::vectorSIMDf position;
297-
core::vectorSIMDf target;
298-
core::vectorSIMDf upVector;
299-
core::vectorSIMDf backupUpVector;
292+
nbl::core::vectorSIMDf position;
293+
nbl::core::vectorSIMDf target;
294+
nbl::core::vectorSIMDf upVector;
295+
nbl::core::vectorSIMDf backupUpVector;
300296

301-
core::matrix3x4SIMD viewMatrix;
302-
core::matrix4SIMD concatMatrix;
297+
nbl::core::matrix3x4SIMD viewMatrix;
298+
nbl::core::matrix4SIMD concatMatrix;
303299

304300
// actual projection matrix used
305-
core::matrix4SIMD projMatrix;
301+
nbl::core::matrix4SIMD projMatrix;
306302

307303
bool leftHanded;
308304

0 commit comments

Comments
 (0)