forked from vixorien/D3D11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.h
71 lines (62 loc) · 2 KB
/
Camera.h
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
#pragma once
#include <memory>
#include <DirectXMath.h>
#include "Input.h"
#include "Transform.h"
class Camera
{
public:
// Constructors
Camera(const char* _name, std::shared_ptr<Transform> _transform, float _aspect);
Camera(const char* _name, std::shared_ptr<Transform> _transform, float _aspect, float _fov);
Camera(const char* _name, std::shared_ptr<Transform> _transform, float _aspect, bool _isOrthographic);
Camera(const char* _name, std::shared_ptr<Transform> _transform, float _aspect, bool _isOrthographic, float _orthoWidth);
// Getters
std::shared_ptr<Transform> GetTransform();
const char* GetName();
float GetFov();
float GetOrthographicWidth();
float GetMoveSpeed();
float GetLookSpeed();
float GetNearClip();
float GetFarClip();
bool GetProjectionMode();
DirectX::XMFLOAT4X4 GetViewMatrix();
DirectX::XMFLOAT4X4 GetProjectionMatrix();
// Setters
void SetAspect(float _aspect);
void SetFov(float _fov);
void SetOrthographicWidth(float _orthoWidth);
void SetMoveSpeed(float _speed);
void SetLookSpeed(float _speed);
void SetNearClip(float _distance);
void SetFarClip(float _distance);
void SetProjectionMode(bool _isOrthographic);
void ToggleProjectionMode();
void Update(float dt);
private:
std::shared_ptr<Transform> transform;
DirectX::XMFLOAT4X4 view;
DirectX::XMFLOAT4X4 projection;
// Name for UI
const char* name;
// Aspect Ratio
float aspect;
// (Perspective Camera Only) Field of View, in radians
float fov;
// (Orthographic Camera Only) Width of the orthographic camera, in units
float orthoWidth;
// Whether the camera uses an orthographic projection instead of a perspective projection
bool isOrthographic;
// Near and far clip planes
float nearDist;
float farDist;
// Move speed in units per second
float moveSpeed;
// Move speed in milliradians per pixel
float lookSpeed;
// Called in Update()
void UpdateViewMatrix();
// Called whenever aspect ratio, FOV, orthographic width, near clip plane, or far clip plane are changed
void UpdateProjectionMatrix();
};