NcEngine
Camera.h
1#pragma once
2
4
5#include "ncmath/Geometry.h"
6
7#include "DirectXMath.h"
8
9namespace nc
10{
13{
15 float fov = 1.0472f;
16
18 float nearClip = 0.1f;
19
21 float farClip = 400.0f;
22};
23
26{
27 Vector3 nearPoint = Vector3::Zero();
28 Vector3 farPoint = Vector3::Zero();
29};
30
32class Camera : public FreeComponent
33{
34 public:
40 Camera(Entity self, const CameraProperties& properties = {}) noexcept;
41
46 auto ViewMatrix() const noexcept -> DirectX::FXMMATRIX { return m_view; }
47
52 auto ProjectionMatrix() const noexcept -> DirectX::FXMMATRIX { return m_projection; }
53
58 auto InverseProjectionMatrix() const noexcept -> DirectX::FXMMATRIX { return m_inverseProjection; }
59
61 auto CastToNearAndFarPlanes(const Vector2& normalizedDeviceCoords) const -> NearFarPoints;
62
64 auto GetProperties() const -> const CameraProperties& { return m_properties; };
65
70 auto CalculateFrustum() const noexcept -> Frustum;
71
73 virtual void UpdateViewMatrix(DirectX::FXMMATRIX transformationMatrix);
74
80 virtual void UpdateProjectionMatrix(float width, float height);
81
86 virtual void EnableUpdate() noexcept {}
87
92 virtual void DisableUpdate() noexcept {}
93
94 private:
95 DirectX::XMMATRIX m_view;
96 DirectX::XMMATRIX m_projection;
97 DirectX::XMMATRIX m_inverseProjection;
98 CameraProperties m_properties;
99};
100} // namespace nc
Basic camera component.
Definition: Camera.h:33
Camera(Entity self, const CameraProperties &properties={}) noexcept
Construct a new Camera object.
virtual void EnableUpdate() noexcept
Enable execution of the Run() method in thhe derived class.
Definition: Camera.h:86
auto InverseProjectionMatrix() const noexcept -> DirectX::FXMMATRIX
Get the camera's inverse projection matrix.
Definition: Camera.h:58
auto ProjectionMatrix() const noexcept -> DirectX::FXMMATRIX
Get the camera's projection matrix.
Definition: Camera.h:52
auto GetProperties() const -> const CameraProperties &
Get the camera properties.
Definition: Camera.h:64
auto CalculateFrustum() const noexcept -> Frustum
Calculate the camera's viewport.
auto ViewMatrix() const noexcept -> DirectX::FXMMATRIX
Get the camera's view matrix.
Definition: Camera.h:46
virtual void DisableUpdate() noexcept
Disable execution of the Run() method in the derived class.
Definition: Camera.h:92
auto CastToNearAndFarPlanes(const Vector2 &normalizedDeviceCoords) const -> NearFarPoints
Unproject 2D normalized device coordinates into 3D points on the near and far planes.
virtual void UpdateViewMatrix(DirectX::FXMMATRIX transformationMatrix)
Construct a new view matrix based on the current transform.
virtual void UpdateProjectionMatrix(float width, float height)
Construct a new projection matrix based on input values.
Identifies an object in the registry.
Definition: Entity.h:18
Base class for free components.
Definition: Component.h:51
Properties for controlling a camera's frustum.
Definition: Camera.h:13
float fov
Camera field of view in radians.
Definition: Camera.h:15
float nearClip
Distance to near clipping plane. Must be greater than 0.
Definition: Camera.h:18
float farClip
Distance to far clipping plane. Must be greater than nearClip.
Definition: Camera.h:21
Definition: Geometry.h:52
Two points lying on a Camera's near and far planes.
Definition: Camera.h:26
A two component vector.
Definition: Vector.h:13
A three component vector.
Definition: Vector.h:29