-
Notifications
You must be signed in to change notification settings - Fork 0
/
Camera.h
131 lines (103 loc) · 3.68 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
//--------------------------------------------------------------------------------------
// Camera.h
//
// The camera class encapsulates the camera's view and projection matrix
//--------------------------------------------------------------------------------------
#ifndef CAMERA_H_INCLUDED // Header guard - prevents file being included more than once (would cause errors)
#define CAMERA_H_INCLUDED
#include "Input.h"
//-----------------------------------------------------------------------------
// DirectX Camera Class Defintition
//-----------------------------------------------------------------------------
// Enum used to select whether camera should be adjusted for left or right eye
enum EStereoscopic
{
Monoscopic,
StereoscopicLeft,
StereoscopicRight
};
class CCamera
{
/////////////////////////////
// Private member variables
private:
// Postition and rotations for the camera (rarely scale cameras)
D3DXVECTOR3 m_Position;
D3DXVECTOR3 m_Rotation;
// Camera settings: field of view, aspect ratio, near and far clip plane distances. Note that the FOV angle is measured in radians (radians = degrees * PI/180)
float m_FOV;
float m_Aspect;
float m_NearClip;
float m_FarClip;
// Current view, projection and combined view-projection matrices (DirectX matrix type)
D3DXMATRIXA16 m_WorldMatrix; // Easiest to treat the camera like a model and give it a "world" matrix...
D3DXMATRIXA16 m_ViewMatrix; // ... the view matrix used in the pipeline is the inverse of its world matrix
D3DXMATRIXA16 m_ProjMatrix; // Projection matrix to set field of view and near/far clip distances
D3DXMATRIXA16 m_ViewProjMatrix; // Combine (multiply) the view and projection matrices together - saves a matrix multiply in the shader (optional optimisation)
/////////////////////////////
// Public member functions
public:
///////////////////////////////
// Constructors / Destructors
// Constructor - initialise all settings, sensible defaults provided for everything.
CCamera( D3DXVECTOR3 position = D3DXVECTOR3(0,0,0), D3DXVECTOR3 rotation = D3DXVECTOR3(0,0,0), float fov = D3DX_PI/4, float nearClip = 1.0f, float farClip = 50000.0f );
/////////////////////////////
// Data access
// Getters
D3DXVECTOR3 GetRotation()
{
return m_Rotation;
}
//***|3D|********************************/
// Camera matrix access / stereo offsets
// See .cpp file
D3DXVECTOR3 GetPosition( EStereoscopic stereo = Monoscopic, float interocular = 0.65f );
D3DXMATRIXA16 GetViewMatrix( EStereoscopic stereo = Monoscopic, float interocular = 0.65f );
D3DXMATRIXA16 GetProjectionMatrix( EStereoscopic stereo = Monoscopic, float interocular = 0.65f, float screenDistance = 20.0f );
//***************************************/
D3DXMATRIXA16 GetViewProjectionMatrix()
{
return m_ViewProjMatrix;
}
float GetFOV()
{
return m_FOV;
}
float GetNearClip()
{
return m_NearClip;
}
float GetFarClip()
{
return m_FarClip;
}
// Setters
void SetPosition( D3DXVECTOR3 position )
{
m_Position = position;
}
void SetRotation( D3DXVECTOR3 rotation )
{
m_Rotation = rotation;
}
void SetFOV( float fov )
{
m_FOV = fov;
}
void SetNearClip( float nearClip )
{
m_NearClip = nearClip;
}
void SetFarClip( float farClip )
{
m_FarClip = farClip;
}
/////////////////////////////
// Camera Usage
// Update the matrices used for the camera in the rendering pipeline
void UpdateMatrices();
// Control the camera's position and rotation using keys provided
void Control( float frameTime, EKeyCode turnUp, EKeyCode turnDown, EKeyCode turnLeft, EKeyCode turnRight,
EKeyCode moveForward, EKeyCode moveBackward, EKeyCode moveLeft, EKeyCode moveRight);
};
#endif // End of header guard - see top of file