-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.h
132 lines (97 loc) · 4.1 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
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
#pragma once
#define ASPECT_RATIO (float(FRAME_BUFFER_WIDTH) / float(FRAME_BUFFER_HEIGHT))
#define FIRST_PERSON_CAMERA 0x01
#define SPACESHIP_CAMERA 0x02
#define THIRD_PERSON_CAMERA 0x03
struct VS_CB_CAMERA_INFO
{
XMFLOAT4X4 m_xmf4x4View;
XMFLOAT4X4 m_xmf4x4Projection;
XMFLOAT3 m_xmf3CameraPosition;
};
class CPlayer;
class CCamera
{
protected:
XMFLOAT3 m_xmf3Position;
XMFLOAT3 m_xmf3Right;
XMFLOAT3 m_xmf3Up;
XMFLOAT3 m_xmf3Look;
float m_fPitch;
float m_fRoll;
float m_fYaw;
DWORD m_nMode;
XMFLOAT3 m_xmf3LookAtWorld;
XMFLOAT3 m_xmf3Offset;
float m_fTimeLag;
XMFLOAT4X4 m_xmf4x4View;
XMFLOAT4X4 m_xmf4x4Projection;
D3D12_VIEWPORT m_d3dViewport;
D3D12_RECT m_d3dScissorRect;
CPlayer *m_pPlayer;
ID3D12Resource *m_pd3dcbCamera = NULL;
VS_CB_CAMERA_INFO *m_pcbMappedCamera = NULL;
public:
CCamera();
CCamera(CCamera *pCamera);
virtual ~CCamera();
virtual void CreateShaderVariables(ID3D12Device *pd3dDevice, ID3D12GraphicsCommandList *pd3dCommandList);
virtual void ReleaseShaderVariables();
virtual void UpdateShaderVariables(ID3D12GraphicsCommandList *pd3dCommandList);
virtual void SetViewportsAndScissorRects(ID3D12GraphicsCommandList *pd3dCommandList);
void GenerateViewMatrix();
void GenerateViewMatrix(XMFLOAT3 xmf3Position, XMFLOAT3 xmf3LookAt, XMFLOAT3 xmf3Up);
void RegenerateViewMatrix();
void GenerateProjectionMatrix(float fNearPlaneDistance, float fFarPlaneDistance, float fAspectRatio, float fFOVAngle);
void SetViewport(int xTopLeft, int yTopLeft, int nWidth, int nHeight, float fMinZ = 0.0f, float fMaxZ = 1.0f);
void SetScissorRect(LONG xLeft, LONG yTop, LONG xRight, LONG yBottom);
void SetPlayer(CPlayer *pPlayer) { m_pPlayer = pPlayer; }
CPlayer *GetPlayer() { return(m_pPlayer); }
void SetMode(DWORD nMode) { m_nMode = nMode; }
DWORD GetMode() { return(m_nMode); }
void SetPosition(XMFLOAT3 xmf3Position) { m_xmf3Position = xmf3Position; }
XMFLOAT3& GetPosition() { return(m_xmf3Position); }
void SetLookAtPosition(XMFLOAT3 xmf3LookAtWorld) { m_xmf3LookAtWorld = xmf3LookAtWorld; }
XMFLOAT3& GetLookAtPosition() { return(m_xmf3LookAtWorld); }
XMFLOAT3& GetRightVector() { return(m_xmf3Right); }
XMFLOAT3& GetUpVector() { return(m_xmf3Up); }
XMFLOAT3& GetLookVector() { return(m_xmf3Look); }
float& GetPitch() { return(m_fPitch); }
float& GetRoll() { return(m_fRoll); }
float& GetYaw() { return(m_fYaw); }
// void SetOffset(XMFLOAT3 xmf3Offset) { m_xmf3Offset = xmf3Offset; }
void SetOffset(XMFLOAT3 xmf3Offset) { m_xmf3Offset = xmf3Offset; m_xmf3Position.x += xmf3Offset.x; m_xmf3Position.y += xmf3Offset.y; m_xmf3Position.z += xmf3Offset.z; }
XMFLOAT3& GetOffset() { return(m_xmf3Offset); }
void SetTimeLag(float fTimeLag) { m_fTimeLag = fTimeLag; }
float GetTimeLag() { return(m_fTimeLag); }
XMFLOAT4X4 GetViewMatrix() { return(m_xmf4x4View); }
XMFLOAT4X4 GetProjectionMatrix() { return(m_xmf4x4Projection); }
D3D12_VIEWPORT GetViewport() { return(m_d3dViewport); }
D3D12_RECT GetScissorRect() { return(m_d3dScissorRect); }
virtual void Move(const XMFLOAT3& xmf3Shift) { m_xmf3Position.x += xmf3Shift.x; m_xmf3Position.y += xmf3Shift.y; m_xmf3Position.z += xmf3Shift.z; }
virtual void Rotate(float fPitch = 0.0f, float fYaw = 0.0f, float fRoll = 0.0f) { }
virtual void Update(XMFLOAT3& xmf3LookAt, float fTimeElapsed) { }
virtual void SetLookAt(XMFLOAT3& xmf3LookAt) { }
};
class CSpaceShipCamera : public CCamera
{
public:
CSpaceShipCamera(CCamera *pCamera);
virtual ~CSpaceShipCamera() { }
virtual void Rotate(float fPitch = 0.0f, float fYaw = 0.0f, float fRoll = 0.0f);
};
class CFirstPersonCamera : public CCamera
{
public:
CFirstPersonCamera(CCamera *pCamera);
virtual ~CFirstPersonCamera() { }
virtual void Rotate(float fPitch = 0.0f, float fYaw = 0.0f, float fRoll = 0.0f);
};
class CThirdPersonCamera : public CCamera
{
public:
CThirdPersonCamera(CCamera *pCamera);
virtual ~CThirdPersonCamera() { }
virtual void Update(XMFLOAT3& xmf3LookAt, float fTimeElapsed);
virtual void SetLookAt(XMFLOAT3& vLookAt);
};