-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.cpp
More file actions
48 lines (43 loc) · 1.21 KB
/
Camera.cpp
File metadata and controls
48 lines (43 loc) · 1.21 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
#include "Camera.h"
#include "imgui-1.88/imgui.h"
DirectX::XMMATRIX Camera::GetMatrix() const noexcept {
// The camera position
const auto pos = DirectX::XMVector3Transform(
// r away from the origin
DirectX::XMVectorSet(0.0, 0.0, -r, 0.0f),
// Movement around the origin
DirectX::XMMatrixRotationRollPitchYaw(phi, -theta, 0.0f)
);
return DirectX::XMMatrixLookAtLH(
// Points the camera towards the origin
pos, DirectX::XMVectorZero(),
DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f)
// Custom Rotation added on top
) * DirectX::XMMatrixRotationRollPitchYaw(
pitch, -yaw, roll
);
}
void Camera::SpawnControlWindow() noexcept {
if (ImGui::Begin("Camera")) {
ImGui::Text("Position");
ImGui::SliderFloat("R", &r, 0.0f, 80.0f, "%.1f");
ImGui::SliderAngle("Theta", &theta, -180.0f, 180.0f);
ImGui::SliderAngle("Phi", &phi, -89.0f, 89.0f);
ImGui::Text("Orientation");
ImGui::SliderAngle("Roll", &roll, -180.0f, 180.0f);
ImGui::SliderAngle("Pitch", &pitch, -180.0f, 180.0f);
ImGui::SliderAngle("Yaw", &yaw, -180.0f, 180.0f);
if (ImGui::Button("Reset")){
Reset();
}
}
ImGui::End();
}
void Camera::Reset() noexcept {
r = 20.0f;
theta = 0.0f;
phi = 0.0f;
pitch = 0.0f;
yaw = 0.0f;
roll = 0.0f;
}