61 LK_DECLARE_MULTICAST_DELEGATE(FCameraProjectionChanged,
const ECameraProjection);
62 LK_DECLARE_MULTICAST_DELEGATE(FCameraActivityChanged,
LCamera*,
const bool);
65 LK_DECLARE_MULTICAST_DELEGATE(FCameraInputModified);
69 LCamera(
const glm::mat4& InProjection);
70 LCamera(
const float InDegFov,
const float InWidth,
const float InHeight,
71 const float InNearP,
const float InFarP);
74 virtual ECameraType GetType()
const {
return ECameraType::None; }
75 FORCEINLINE ECameraProjection GetProjectionType()
const {
return ProjectionType; }
77 FORCEINLINE
bool IsActive()
const {
return bIsActive; }
79 FORCEINLINE
void SetPerspective(
const float InVerticalFovDeg,
const float InNearClip = 0.1f,
const float InFarClip = 1000.0f)
81 if ((ProjectionType != ECameraProjection::Perspective)
82 || (DegPerspectiveFov != InVerticalFovDeg)
83 || (PerspectiveNear != InNearClip)
84 || (PerspectiveFar != InFarClip))
86 ProjectionType = ECameraProjection::Perspective;
87 DegPerspectiveFov = InVerticalFovDeg;
88 PerspectiveNear = InNearClip;
89 PerspectiveFar = InFarClip;
91 OnCameraProjectionChanged.Broadcast(ECameraProjection::Perspective);
95 FORCEINLINE
void SetOrthographic(
const float InWidth,
const float InHeight,
const float InNearClip = -1.0f,
const float InFarClip = 1.0f)
97 if ((ProjectionType != ECameraProjection::Perspective)
98 || (OrthographicNear != InNearClip)
99 || (OrthographicFar != InFarClip))
101 ProjectionType = ECameraProjection::Orthographic;
102 OrthographicNear = InNearClip;
103 OrthographicFar = InFarClip;
105 OnCameraProjectionChanged.Broadcast(ECameraProjection::Orthographic);
109 FORCEINLINE
void SetProjectionType(ECameraProjection InProjection)
111 if (ProjectionType != InProjection)
113 ProjectionType = InProjection;
114 OnCameraProjectionChanged.Broadcast(ProjectionType);
118 FORCEINLINE
void SetPitch(
const float InPitch) { Pitch = InPitch; }
119 FORCEINLINE
float GetPitch()
const {
return Pitch; }
120 FORCEINLINE
float GetPitchDelta()
const {
return PitchDelta; }
122 FORCEINLINE
void SetYaw(
const float InYaw) { Yaw = InYaw; }
123 FORCEINLINE
float GetYaw()
const {
return Yaw; }
124 FORCEINLINE
float GetYawDelta()
const {
return YawDelta; }
126 FORCEINLINE
void SetActive(
const bool InActive)
128 if (bIsActive != InActive)
130 bIsActive = InActive;
135 FORCEINLINE
const glm::mat4& GetViewMatrix()
const {
return ViewMatrix; }
136 FORCEINLINE
const glm::mat4& GetProjectionMatrix()
const {
return ProjectionMatrix; }
137 FORCEINLINE glm::mat4 GetViewProjection()
const {
return GetProjectionMatrix() * ViewMatrix; }
138 FORCEINLINE
float GetRotation() {
return glm::radians(Rotation); }
139 FORCEINLINE
float GetRotationSpeed()
const {
return RotationSpeed; }
141 FORCEINLINE
const glm::vec3& GetOrigin()
const {
return Origin; }
142 FORCEINLINE
const glm::vec3& GetFocalPoint()
const {
return FocalPoint; }
143 FORCEINLINE
const glm::vec3& GetDirection()
const {
return Direction; }
145 FORCEINLINE
float GetPerspectiveNearClip()
const {
return PerspectiveNear; }
146 FORCEINLINE
float GetPerspectiveFarClip()
const {
return PerspectiveFar; }
147 FORCEINLINE
void SetPerspectiveNearClip(
const float InNearClip) { PerspectiveNear = InNearClip; }
148 FORCEINLINE
void SetPerspectiveFarClip(
const float InFarClip) { PerspectiveFar = InFarClip; }
150 FORCEINLINE
float GetOrthographicSize()
const {
return OrthographicSize; }
151 FORCEINLINE
float GetOrthographicNearClip()
const {
return OrthographicNear; }
152 FORCEINLINE
float GetOrthographicFarClip()
const {
return OrthographicFar; }
153 FORCEINLINE
void SetOrthographicNearClip(
const float InNearClip) { OrthographicNear = InNearClip; }
154 FORCEINLINE
void SetOrthographicFarClip(
const float InFarClip) { OrthographicFar = InFarClip; }
156 FORCEINLINE
void SetProjectionMatrix(
const glm::mat4& InProjection) { ProjectionMatrix = InProjection; }
157 FORCEINLINE
void SetPerspectiveProjectionMatrix(
const float InRadFov,
159 const float InHeight,
163 LK_CORE_ASSERT((InWidth > 0) && (InHeight > 0),
"Cannot set projection matrix with invalid arguments");
164 ProjectionMatrix = glm::perspectiveFov(InRadFov, InWidth, InHeight, InNearP, InFarP);
167 FORCEINLINE
void SetOrthoProjectionMatrix(
const float InWidth,
const float InHeight,
const float InNearP,
const float InFarP)
169 LK_CORE_ASSERT((InWidth > 0) && (InHeight > 0));
170 ProjectionMatrix = glm::ortho(
171 -(InWidth * 0.50f), (InWidth * 0.50f),
172 -(InHeight * 0.50f), (InHeight * 0.50f),
176 template<enum EAngleUnit = EAngleUnit::Degree>
177 float GetPerspectiveFov()
const;
179 template<enum EAngleUnit = EAngleUnit::Degree>
180 float GetPerspectiveVerticalFov()
const;
182 FORCEINLINE glm::quat GetOrientation()
const
184 return glm::quat(glm::vec3(-Pitch - PitchDelta, -Yaw - YawDelta, 0.0f));
187 FORCEINLINE glm::vec3 GetUpDirection()
const
189 return glm::rotate(GetOrientation(), glm::vec3(0.0f, 1.0f, 0.0f));
192 FORCEINLINE glm::vec3 GetRightDirection()
const
194 return glm::rotate(GetOrientation(), glm::vec3(1.0f, 0.0f, 0.0f));
197 template<
typename TVector = glm::vec3>
198 TVector GetForwardDirection()
const
200 return TVector(glm::rotate(GetOrientation(), glm::vec3(0.0f, 0.0f, -1.0f)));
203 void SetMouseEnabled(
const bool InEnabled)
205 const bool MouseEnabled = (ModifierFlags & ECameraModifier::MouseEnabled);
206 if (MouseEnabled != InEnabled)
214 ModifierFlags |= ECameraModifier::MouseEnabled;
217 OnCameraInputModified.Broadcast();
221 void SetKeyboardEnabled(
const bool InEnabled)
223 const bool KeyboardEnabled = ModifierFlags & ECameraModifier::KeyboardEnabled;
224 if (KeyboardEnabled != InEnabled)
232 ModifierFlags |= ECameraModifier::KeyboardEnabled;
235 OnCameraInputModified.Broadcast();
247 FCameraProjectionChanged OnCameraProjectionChanged;
248 FCameraInputModified OnCameraInputModified;
250 bool bIsActive =
false;
251 ECameraProjection ProjectionType = ECameraProjection::Perspective;
253 int32_t ModifierFlags = 0;
254 static_assert(std::is_same_v<
decltype(ModifierFlags), std::underlying_type_t<ECameraModifier>>);
256 glm::vec3 Origin = { 0.0f, 0.0f, 0.0f };
257 glm::vec3 Direction{};
258 glm::vec3 FocalPoint{};
259 glm::vec3 PositionDelta = { 0.0f, 0.0f, 0.0f };
262 float PitchDelta = 0.0f;
264 float YawDelta = 0.0f;
266 float AspectRatio = (16.0f / 9.0f);
268 float DegPerspectiveFov = 45.0f;
269 float PerspectiveNear = 0.1f;
270 float PerspectiveFar = 1000.0f;
272 float OrthographicSize = 10.0f;
273 float OrthographicNear = -1.0f;
274 float OrthographicFar = 1.0f;
276 float Rotation = 0.0f;
277 float RotationSpeed = 0.280f;
279 glm::mat4 ViewMatrix = glm::mat4(1.0f);
280 glm::mat4 ProjectionMatrix = glm::mat4(1.0f);
283 friend class LEditorLayer;
284 friend class LSceneSerializer;