ezEngine  Milestone 9
Camera.h
1 #pragma once
2 
3 #include <Core/CoreDLL.h>
4 #include <Foundation/Math/Mat4.h>
6 
8 struct EZ_CORE_DLL ezCameraMode
9 {
10  typedef ezInt8 StorageType;
11 
12  enum Enum
13  {
14  None,
20  Default = PerspectiveFixedFovY
21  };
22 };
23 
25 
29 enum class EZ_CORE_DLL ezCameraEye
30 {
31  Left,
32  Right,
33  // Two eyes should be enough for everyone.
34 };
35 
37 class EZ_CORE_DLL ezCamera
38 {
39 public:
40  ezCamera();
41 
43  ezVec3 GetPosition(ezCameraEye eye = ezCameraEye::Left) const;
44 
46  ezVec3 GetDirForwards(ezCameraEye eye = ezCameraEye::Left) const;
47 
49  ezVec3 GetDirUp(ezCameraEye eye = ezCameraEye::Left) const;
50 
52  ezVec3 GetDirRight(ezCameraEye eye = ezCameraEye::Left) const;
53 
57  ezAngle GetFovX(float fAspectRatioWidthDivHeight) const;
58 
62  ezAngle GetFovY(float fAspectRatioWidthDivHeight) const;
63 
67  float GetDimensionX(float fAspectRatioWidthDivHeight) const;
68 
72  float GetDimensionY(float fAspectRatioWidthDivHeight) const;
73 
77  ezVec3 GetCenterPosition() const;
78 
82  ezVec3 GetCenterDirForwards() const;
83 
87  ezVec3 GetCenterDirUp() const;
88 
92  ezVec3 GetCenterDirRight() const;
93 
95  float GetNearPlane() const;
96 
98  float GetFarPlane() const;
99 
104  void SetCameraMode(ezCameraMode::Enum Mode, float fFovOrDim, float fNearPlane, float fFarPlane);
105 
110  void SetStereoProjection(const ezMat4& mProjectionLeftEye, const ezMat4& mProjectionRightEye, float fAspectRatioWidthDivHeight);
111 
112 
114  float GetFovOrDim() const;
115 
117  ezCameraMode::Enum GetCameraMode() const;
118  bool IsPerspective() const;
119  bool IsOrthographic() const;
121  bool IsStereoscopic() const;
122 
126  void SetViewMatrix(const ezMat4& mLookAtMatrix, ezCameraEye eye = ezCameraEye::Left);
127 
131  void LookAt(const ezVec3& vCameraPos, const ezVec3& vTargetPos, const ezVec3& vUp);
132 
136  ezVec3 MoveLocally(float fForward, float fRight, float fUp);
137 
141  void MoveGlobally(const ezVec3& vMove);
142 
147  void RotateLocally(ezAngle X, ezAngle Y, ezAngle Z);
148 
153  void RotateGlobally(ezAngle X, ezAngle Y, ezAngle Z);
154 
156  const ezMat4& GetViewMatrix(ezCameraEye eye = ezCameraEye::Left) const;
157 
162  void GetProjectionMatrix(float fAspectRatioWidthDivHeight, ezMat4& out_projectionMatrix, ezCameraEye eye = ezCameraEye::Left,
164 
165  float GetExposure() const;
166  void SetExposure(float fExposure);
167 
172  ezUInt32 GetSettingsModificationCounter() const { return m_uiSettingsModificationCounter; }
173 
178  ezUInt32 GetOrientationModificationCounter() const { return m_uiOrientationModificationCounter; }
179 
180 private:
182  void CameraOrientationChanged(bool bPosition, bool bRotation) { ++m_uiOrientationModificationCounter; }
183 
185  void CameraSettingsChanged();
186 
189  void ClampRotationAngles(bool bLocalSpace, ezAngle& X, ezAngle& Y, ezAngle& Z);
190 
191  float m_fNearPlane;
192  float m_fFarPlane;
193 
194  ezCameraMode::Enum m_Mode;
195 
196  float m_fFovOrDim;
197 
198  float m_fExposure;
199 
200  ezVec3 m_vCameraPosition[2];
201  ezMat4 m_mViewMatrix[2];
202 
205  float m_fAspectOfPrecomputedStereoProjection = -1.0;
206  ezMat4 m_mStereoProjectionMatrix[2];
207 
208  ezUInt32 m_uiSettingsModificationCounter;
209  ezUInt32 m_uiOrientationModificationCounter;
210 };
211 
212 
213 #include <Core/Graphics/Implementation/Camera_inl.h>
214 
A camera class that stores the orientation and some basic camera settings.
Definition: Camera.h:37
Perspective camera, the fov for X is fixed, Y depends on the aspect ratio.
Definition: Camera.h:15
static Enum Default
Holds the default value for the projection depth range on each platform. This can be overridden by re...
Definition: Declarations.h:61
Not initialized.
Definition: Camera.h:14
Specifies in which mode this camera is configured.
Definition: Camera.h:8
Orthographic camera, the height is fixed, the width depends on the aspect ratio.
Definition: Camera.h:18
Perspective camera, the fov for Y is fixed, X depends on the aspect ratio.
Definition: Camera.h:16
ezUInt32 GetSettingsModificationCounter() const
Returns a counter that is increased every time the camera settings are modified.
Definition: Camera.h:172
Enum
Definition: Camera.h:12
Orthographic camera, the width is fixed, the height depends on the aspect ratio.
Definition: Camera.h:17
#define EZ_DECLARE_REFLECTABLE_TYPE(Linkage, TYPE)
Declares a type to be statically reflectable. Insert this into the header of a type to enable reflect...
Definition: StaticRTTI.h:123
A stereo camera with view/projection matrices provided by an HMD.
Definition: Camera.h:19
Float wrapper struct for a safe usage and conversions of angles.
Definition: Angle.h:8
ezUInt32 GetOrientationModificationCounter() const
Returns a counter that is increased every time the camera orientation is modified.
Definition: Camera.h:178
Enum
Definition: Declarations.h:53