-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.h
More file actions
62 lines (48 loc) · 1.47 KB
/
Camera.h
File metadata and controls
62 lines (48 loc) · 1.47 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
#pragma once
#include "settings.h"
#include "ImGUI/imgui.h"
#include "Transform.h"
#include <DirectXMath.h>
#include <assimp/Importer.hpp>
#include <assimp/scene.h>
#include <assimp/postprocess.h>
namespace dx = DirectX;
class Camera
{
public:
Camera(const unsigned int width, const unsigned int height);
~Camera() = default;
#ifdef USE_IMGUI
void SpawnImGuiControl()
{
ImGui::Begin("Camera");
ImGui::SliderFloat3("Position", &mPos.m128_f32[0], -15, 15);
static float rot[3] = { 0.0f, 0.0f, 0.0f };
if (ImGui::SliderFloat3("Rotation", &rot[0], -180, 180))
{
mRotQuat = dx::XMQuaternionMultiply(dx::XMQuaternionMultiply(dx::XMQuaternionRotationAxis({ 1.0f, 0.0f, 0.0f }, -rot[0] * dx::XM_PI / 180.0f),
dx::XMQuaternionRotationAxis({ 0.0f, 1.0f, 0.0f }, -rot[1] * dx::XM_PI / 180.0f)),
dx::XMQuaternionRotationAxis({ 0.0f, 0.0f, 1.0f },- rot[2] * dx::XM_PI / 180.0f));
}
ImGui::SliderFloat("FOV", &mAngle, 0.1f, 3*dx::XM_PI/ 4.0f);
ImGui::End();
}
#endif
dx::XMMATRIX GetMatrix()
{
return dx::XMMatrixTranspose(
dx::XMMatrixTranslation(-mPos.m128_f32[0], -mPos.m128_f32[1], -mPos.m128_f32[2]) *
dx::XMMatrixRotationQuaternion(mRotQuat) *
dx::XMMatrixPerspectiveFovLH(mAngle, mAspectRation, mNear, mFar)
);
}
dx::XMVECTOR mPos = { 0.0f, 0.0f, 0.0f };
private:
float mNear = 0.1f;
float mFar = 100.0f;
float mAngle = 100.0f * dx::XM_PI / 180.0f;
float width;
float height;
float mAspectRation = width / height;
dx::XMVECTOR mRotQuat = { };
};