BRE12
Camera.h
1 #pragma once
2 
3 #include <DirectXMath.h>
4 
5 #include <MathUtils\MathUtils.h>
6 
7 namespace BRE {
8 
9 class Camera {
10 public:
11  Camera() = default;
12  ~Camera() = default;
13  Camera(const Camera&) = delete;
14  const Camera& operator=(const Camera&) = delete;
15  Camera(Camera&&) = delete;
16  Camera& operator=(Camera&&) = delete;
17 
18  __forceinline DirectX::XMFLOAT3 GetPosition3f() const noexcept
19  {
20  return mPosition;
21  }
22  __forceinline DirectX::XMFLOAT4 GetPosition4f() const noexcept
23  {
24  return DirectX::XMFLOAT4(mPosition.x, mPosition.y, mPosition.z, 1.0f);
25  }
26  __forceinline void SetPosition(const DirectX::XMFLOAT3& v) noexcept
27  {
28  mPosition = v;
29  }
30 
31  void SetFrustum(const float verticalFieldOfView,
32  const float aspectRatio,
33  const float nearPlaneZ,
34  const float farPlaneZ) noexcept;
35 
36  void SetLookAndUpVectors(const DirectX::XMFLOAT3& cameraPosition,
37  const DirectX::XMFLOAT3& targetPosition,
38  const DirectX::XMFLOAT3& upVector) noexcept;
39 
40  __forceinline const DirectX::XMFLOAT4X4& GetViewMatrix() const noexcept
41  {
42  return mViewMatrix;
43  }
44  __forceinline const DirectX::XMFLOAT4X4& GetInverseViewMatrix() const noexcept
45  {
46  return mInverseViewMatrix;
47  }
48  __forceinline DirectX::XMMATRIX GetInverseViewXMMatrix() const noexcept
49  {
50  return DirectX::XMLoadFloat4x4(&GetInverseViewMatrix());
51  }
52  __forceinline const DirectX::XMFLOAT4X4& GetProjectionMatrix() const noexcept
53  {
54  return mProjectionMatrix;
55  }
56  __forceinline const DirectX::XMFLOAT4X4& GetInverseProjectionMatrix() const noexcept
57  {
58  return mInverseProjectionMatrix;
59  }
60 
61  // If distance is positive, then we
62  // will strafe left / walk forward.
63  // Otherwise, we will strafe right / walk backward.
64  void Strafe(const float distance) noexcept;
65  void Walk(const float distance) noexcept;
66 
67  void Pitch(const float angleInRadians) noexcept;
68  void RotateY(const float angleInRadians) noexcept;
69 
70  void UpdateViewMatrix() noexcept;
71 
72 private:
73  DirectX::XMFLOAT3 mPosition = { 0.0f, 0.0f, 0.0f };
74  DirectX::XMFLOAT3 mRightVector = { 1.0f, 0.0f, 0.0f };
75  DirectX::XMFLOAT3 mUpVector = { 0.0f, 1.0f, 0.0f };
76  DirectX::XMFLOAT3 mLookVector = { 0.0f, 0.0f, 1.0f };
77  DirectX::XMFLOAT3 mVelocityVector{ 0.0f, 0.0f, 0.0f };
78 
79  DirectX::XMFLOAT4X4 mViewMatrix{ MathUtils::GetIdentity4x4Matrix() };
80  DirectX::XMFLOAT4X4 mInverseViewMatrix{ MathUtils::GetIdentity4x4Matrix() };
81  DirectX::XMFLOAT4X4 mProjectionMatrix{ MathUtils::GetIdentity4x4Matrix() };
82  DirectX::XMFLOAT4X4 mInverseProjectionMatrix{ MathUtils::GetIdentity4x4Matrix() };
83 };
84 }
Definition: Camera.cpp:8
Definition: Camera.h:9