Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
camera.h
1 #pragma once
2 
3 #include <DirectXMath.h>
4 
5 namespace blowbox
6 {
13  class Camera
14  {
15  public:
16  Camera();
17  virtual ~Camera();
18 
23  void Translate(const DirectX::XMFLOAT3& translation);
24 
29  void Rotate(const DirectX::XMFLOAT3& rotation);
30 
35  void SetPosition(const DirectX::XMFLOAT3& position);
36 
41  void SetRotation(const DirectX::XMFLOAT3& rotation);
42 
44  const DirectX::XMFLOAT3& GetPosition() const;
46  const DirectX::XMFLOAT3& GetRotation() const;
47 
52  void SetNearPlane(float near_plane);
53 
58  void SetFarPlane(float far_plane);
59 
61  float GetNearPlane() const;
63  float GetFarPlane() const;
64 
66  const DirectX::XMMATRIX& GetViewMatrix();
67 
69  const DirectX::XMMATRIX& GetProjectionMatrix();
70 
71  protected:
73  void UpdateViewMatrix();
74 
76  virtual void UpdateProjectionMatrix() = 0;
77 
78  protected:
79  DirectX::XMFLOAT3 position_;
80  DirectX::XMFLOAT3 rotation_;
81 
82  DirectX::XMMATRIX view_;
83  DirectX::XMMATRIX projection_;
84  bool view_dirty_;
86 
87  float near_plane_;
88  float far_plane_;
89 
90  private:
91  DirectX::XMFLOAT3 translation_acculumator_;
92  };
93 }
void Translate(const DirectX::XMFLOAT3 &translation)
Translates the camera in a given direction relative to its current orientation.
Definition: camera.cc:27
DirectX::XMFLOAT3 translation_acculumator_
Accumulator for how much the camera should be translated relative to its current orientation.
Definition: camera.h:91
const DirectX::XMMATRIX & GetViewMatrix()
Definition: camera.cc:97
void Rotate(const DirectX::XMFLOAT3 &rotation)
Rotates the camera by a certain rotation relative to its current rotation.
Definition: camera.cc:36
void SetFarPlane(float far_plane)
Sets the far plane of the camera.
Definition: camera.cc:78
A camera through which the scene is rendered.
Definition: camera.h:13
DirectX::XMFLOAT3 position_
The position of the camera.
Definition: camera.h:79
const DirectX::XMMATRIX & GetProjectionMatrix()
Definition: camera.cc:108
void SetPosition(const DirectX::XMFLOAT3 &position)
Sets the position of the camera in world space.
Definition: camera.cc:45
void SetRotation(const DirectX::XMFLOAT3 &rotation)
Sets the rotation of the camera in world space.
Definition: camera.cc:52
float GetFarPlane() const
Definition: camera.cc:91
const DirectX::XMFLOAT3 & GetPosition() const
Definition: camera.cc:59
virtual void UpdateProjectionMatrix()=0
(Re)-calculates the projection matrix of the camera.
DirectX::XMMATRIX projection_
The projection matrix of the camera.
Definition: camera.h:83
float GetNearPlane() const
Definition: camera.cc:85
DirectX::XMFLOAT3 rotation_
The rotation of the camera.
Definition: camera.h:80
float near_plane_
The near plane z-value of the camera.
Definition: camera.h:87
bool view_dirty_
Whether the view matrix has to be updated before it can be used again.
Definition: camera.h:84
void UpdateViewMatrix()
(Re)-calculates the view matrix of the camera.
Definition: camera.cc:119
DirectX::XMMATRIX view_
The view matrix of the camera.
Definition: camera.h:82
The main Blowbox namespace.
Definition: image.cc:8
const DirectX::XMFLOAT3 & GetRotation() const
Definition: camera.cc:65
float far_plane_
The far plane z-value of the camera.
Definition: camera.h:88
bool projection_dirty_
Whether the projection matrix has to be updated before it can be used again.
Definition: camera.h:85
void SetNearPlane(float near_plane)
Sets the near plane of the camera.
Definition: camera.cc:71