Plasma Engine  2.0
Loading...
Searching...
No Matches
Camera.h
1#pragma once
2
3#include <Core/CoreDLL.h>
4#include <Core/World/CoordinateSystem.h>
5#include <Foundation/Math/Mat4.h>
6#include <Foundation/Reflection/Reflection.h>
7#include <Foundation/Types/SharedPtr.h>
8#include <Foundation/Types/UniquePtr.h>
9
11struct PL_CORE_DLL plCameraMode
12{
13 using StorageType = plInt8;
14
25};
26
27PL_DECLARE_REFLECTABLE_TYPE(PL_CORE_DLL, plCameraMode);
28
32enum class plCameraEye
33{
34 Left,
35 Right,
36 // Two eyes should be enough for everyone.
37};
38
40class PL_CORE_DLL plCamera
41{
42public:
43 plCamera();
44
48 void SetCoordinateSystem(plBasisAxis::Enum forwardAxis, plBasisAxis::Enum rightAxis, plBasisAxis::Enum axis);
49
51 void SetCoordinateSystem(const plSharedPtr<plCoordinateSystemProvider>& pProvider);
52
54 plVec3 GetPosition(plCameraEye eye = plCameraEye::Left) const;
55
57 plVec3 GetDirForwards(plCameraEye eye = plCameraEye::Left) const;
58
60 plVec3 GetDirUp(plCameraEye eye = plCameraEye::Left) const;
61
63 plVec3 GetDirRight(plCameraEye eye = plCameraEye::Left) const;
64
68 plAngle GetFovX(float fAspectRatioWidthDivHeight) const;
69
73 plAngle GetFovY(float fAspectRatioWidthDivHeight) const;
74
78 float GetDimensionX(float fAspectRatioWidthDivHeight) const;
79
83 float GetDimensionY(float fAspectRatioWidthDivHeight) const;
84
88 plVec3 GetCenterPosition() const;
89
93 plVec3 GetCenterDirForwards() const;
94
98 plVec3 GetCenterDirUp() const;
99
103 plVec3 GetCenterDirRight() const;
104
106 float GetNearPlane() const;
107
109 float GetFarPlane() const;
110
115 void SetCameraMode(plCameraMode::Enum mode, float fFovOrDim, float fNearPlane, float fFarPlane);
116
121 void SetStereoProjection(const plMat4& mProjectionLeftEye, const plMat4& mProjectionRightEye, float fAspectRatioWidthDivHeight);
122
124 float GetFovOrDim() const;
125
127 plCameraMode::Enum GetCameraMode() const;
128
129 bool IsPerspective() const;
130
131 bool IsOrthographic() const;
132
134 bool IsStereoscopic() const;
135
139 void SetViewMatrix(const plMat4& mLookAtMatrix, plCameraEye eye = plCameraEye::Left);
140
144 void LookAt(const plVec3& vCameraPos, const plVec3& vTargetPos, const plVec3& vUp);
145
149 void MoveLocally(float fForward, float fRight, float fUp);
150
154 void MoveGlobally(float fForward, float fRight, float fUp);
155
160 void RotateLocally(plAngle forwardAxis, plAngle rightAxis, plAngle axis);
161
166 void RotateGlobally(plAngle forwardAxis, plAngle rightAxis, plAngle axis);
167
171 const plMat4& GetViewMatrix(plCameraEye eye = plCameraEye::Left) const;
172
177 void GetProjectionMatrix(float fAspectRatioWidthDivHeight, plMat4& out_mProjectionMatrix, plCameraEye eye = plCameraEye::Left,
179
180 float GetExposure() const;
181 void SetExposure(float fExposure);
182
183 float GetAperture() const;
184 void SetAperture(float fAperture);
185
186 float GetShutterSpeed() const;
187 void SetShutterSpeed(float fShutterSpeed);
188
189 float GetISO() const;
190 void SetISO(float fISO);
191
192 float GetFocusDistance() const;
193 void SetFocusDistance(float fFocusDistance);
194
199 plUInt32 GetSettingsModificationCounter() const { return m_uiSettingsModificationCounter; }
200
205 plUInt32 GetOrientationModificationCounter() const { return m_uiOrientationModificationCounter; }
206
207private:
209 void CameraOrientationChanged(bool bPosition, bool bRotation) { ++m_uiOrientationModificationCounter; }
210
212 void CameraSettingsChanged();
213
216 void ClampRotationAngles(bool bLocalSpace, plAngle& forwardAxis, plAngle& rightAxis, plAngle& upAxis);
217
218 plVec3 InternalGetPosition(plCameraEye eye = plCameraEye::Left) const;
219 plVec3 InternalGetDirForwards(plCameraEye eye = plCameraEye::Left) const;
220 plVec3 InternalGetDirUp(plCameraEye eye = plCameraEye::Left) const;
221 plVec3 InternalGetDirRight(plCameraEye eye = plCameraEye::Left) const;
222
223 float m_fNearPlane = 0.1f;
224 float m_fFarPlane = 1000.0f;
225
227
228 float m_fFovOrDim = 90.0f;
229
230 float m_fShutterSpeed = 1.0f;
231 float m_fExposure = 1.0f;
232 float m_fAperture = 1.0f;
233 float m_fISO = 100.0f;
234 float m_fFocusDistance = 1.0f;
235
236 plVec3 m_vCameraPosition[2];
237 plMat4 m_mViewMatrix[2];
238
241 float m_fAspectOfPrecomputedStereoProjection = -1.0;
242 plMat4 m_mStereoProjectionMatrix[2];
243
244 plUInt32 m_uiSettingsModificationCounter = 0;
245 plUInt32 m_uiOrientationModificationCounter = 0;
246
247 plSharedPtr<plCoordinateSystemProvider> m_pCoordinateSystem;
248
249 plVec3 MapExternalToInternal(const plVec3& v) const;
250 plVec3 MapInternalToExternal(const plVec3& v) const;
251};
252
253
254#include <Core/Graphics/Implementation/Camera_inl.h>
Float wrapper struct for a safe usage and conversions of angles.
Definition Angle.h:10
A camera class that stores the orientation and some basic camera settings.
Definition Camera.h:41
plUInt32 GetSettingsModificationCounter() const
Returns a counter that is increased every time the camera settings are modified.
Definition Camera.h:199
plUInt32 GetOrientationModificationCounter() const
Returns a counter that is increased every time the camera orientation is modified.
Definition Camera.h:205
A Shared ptr manages a shared object and destroys that object when no one references it anymore....
Definition SharedPtr.h:10
Enum
An enum that allows to select on of the six main axis (positive / negative)
Definition Declarations.h:242
Specifies in which mode this camera is configured.
Definition Camera.h:12
Enum
Definition Camera.h:16
@ PerspectiveFixedFovY
Perspective camera, the fov for Y is fixed, X depends on the aspect ratio.
Definition Camera.h:19
@ PerspectiveFixedFovX
Perspective camera, the fov for X is fixed, Y depends on the aspect ratio.
Definition Camera.h:18
@ Stereo
A stereo camera with view/projection matrices provided by an HMD.
Definition Camera.h:22
@ OrthoFixedWidth
Orthographic camera, the width is fixed, the height depends on the aspect ratio.
Definition Camera.h:20
@ OrthoFixedHeight
Orthographic camera, the height is fixed, the width depends on the aspect ratio.
Definition Camera.h:21
@ None
Not initialized.
Definition Camera.h:17
Enum
Definition Declarations.h:79
static PL_FOUNDATION_DLL Enum Default
Holds the default value for the projection depth range on each platform. This can be overridden by re...
Definition Declarations.h:87