Skylicht Engine
Loading...
Searching...
No Matches
CCamera.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "Utils/CActivator.h"
28#include "Components/CComponentSystem.h"
29#include "Transform/CTransform.h"
30
31namespace Skylicht
32{
69 class SKYLICHT_API CCamera : public CComponentSystem
70 {
71 public:
83
84 protected:
87
90
93
95 float m_fov;
96
98 float m_aspect;
99
102
105 float m_orthoUIW;
106 float m_orthoUIH;
107
110
113
115 core::vector3df m_up;
116
118 SViewFrustum m_viewArea;
119
121 core::dimension2du m_screenSize;
122
125
128
131
132 public:
133 CCamera();
134
135 virtual ~CCamera();
136
137 virtual void initComponent();
138
139 virtual void updateComponent();
140
144 virtual void endUpdate();
145
146 public:
147
153
159 {
160 return m_projectionType;
161 }
162
167 const core::matrix4& getProjectionMatrix() const;
168
173 const core::matrix4& getViewMatrix() const;
174
180 void setViewMatrix(const core::matrix4& view, const core::vector3df& position);
181
186 void setProjectionMatrix(const core::matrix4& prj);
187
192 void setPosition(const core::vector3df& position);
193
198 core::vector3df getPosition();
199
204 void copyProjection(CCamera* target);
205
212 void lookAt(const core::vector3df& position, const core::vector3df& target, const core::vector3df& up);
213
219 void lookAt(const core::vector3df& target, const core::vector3df& up);
220
225 void setUpVector(const core::vector3df& up);
226
231 void setLookVector(core::vector3df look);
232
237 inline const core::vector3df& getUpVector()
238 {
239 return m_up;
240 }
241
246 core::vector3df getLookVector();
247
252 inline void setNearValue(float f)
253 {
254 m_nearValue = f;
255 m_projectionChanged = true;
256 }
257
262 inline float getNearValue()
263 {
264 return m_nearValue;
265 }
266
271 inline void setFarValue(float f)
272 {
273 m_farValue = f;
274 m_projectionChanged = true;
275 }
276
281 inline float getFarValue()
282 {
283 return m_farValue;
284 }
285
290 inline void setFOV(float fov)
291 {
292 m_fov = fov;
293 m_projectionChanged = true;
294 }
295
300 inline float getFOV()
301 {
302 return m_fov;
303 }
304
309 inline void setOrthoScale(float s)
310 {
311 m_orthoScale = s;
312 }
313
318 inline float getOrthoScale()
319 {
320 return m_orthoScale;
321 }
322
328 inline void setOrthoUISize(float w, float h)
329 {
330 m_orthoUIH = h;
331 m_orthoUIW = w;
332 }
333
338 inline void enableCustomOrthoUISize(bool b)
339 {
341 }
342
347 inline void setAspect(float f)
348 {
349 m_aspect = f;
350 m_projectionChanged = true;
351 }
352
357 inline float getAspect()
358 {
359 if (m_aspect > 0)
360 return m_aspect;
361
362 return m_viewportAspect;
363 }
364
369 inline u32 getCullingMask()
370 {
371 return m_cullingMask;
372 }
373
378 inline void setCullingMask(u32 mask)
379 {
380 m_cullingMask = mask;
381 }
382
387
392
397 const SViewFrustum& getViewFrustum()
398 {
399 return m_viewArea;
400 }
401
406 inline void setInputReceiver(bool b)
407 {
408 m_inputReceiver = b;
409 }
410
416 {
417 return m_inputReceiver;
418 }
419
424 inline void setUseScaledTime(bool b)
425 {
426 m_useScaledTime = b;
427 }
428
433 inline bool isUseScaledTime()
434 {
435 return m_useScaledTime;
436 }
437
438 DECLARE_GETTYPENAME(CCamera)
439 };
440}
This is an object class used to set up the camera, including its position, viewing angle,...
Definition CCamera.h:70
const core::matrix4 & getProjectionMatrix() const
Returns the calculated projection matrix.
SViewFrustum m_viewArea
Internal view frustum data (planes, matrices).
Definition CCamera.h:118
void lookAt(const core::vector3df &position, const core::vector3df &target, const core::vector3df &up)
Configures the camera to look at a target from a specific position.
bool m_useScaledTime
Whether to use scaled or unscaled time for updates.
Definition CCamera.h:130
bool m_customOrthoSize
Whether a custom orthographic size is used for OrthoUI.
Definition CCamera.h:104
bool m_inputReceiver
Whether this camera receives input events.
Definition CCamera.h:124
void setOrthoScale(float s)
Sets the scale for orthographic projection.
Definition CCamera.h:309
const core::vector3df & getUpVector()
Gets the current 'up' vector.
Definition CCamera.h:237
float m_orthoScale
Scale factor for orthographic projection.
Definition CCamera.h:112
const SViewFrustum & getViewFrustum()
Gets the view frustum (planes and matrices).
Definition CCamera.h:397
float getFOV()
Gets the vertical FOV.
Definition CCamera.h:300
float getFarValue()
Gets the far clipping plane distance.
Definition CCamera.h:281
void setCullingMask(u32 mask)
Sets the bitmask for entity culling.
Definition CCamera.h:378
bool isInputReceiverEnabled()
Checks if the camera is receiving input.
Definition CCamera.h:415
u32 getCullingMask()
Gets the bitmask used for culling entities.
Definition CCamera.h:369
void setAspect(float f)
Sets the aspect ratio. Set to -1 to auto-calculate from viewport.
Definition CCamera.h:347
float m_viewportAspect
Actual viewport aspect ratio from render target.
Definition CCamera.h:101
float m_fov
Field of View in degrees.
Definition CCamera.h:95
void setProjectionType(ECameraProjection projection)
Sets the projection mode.
void setFarValue(float f)
Sets the far clipping plane distance.
Definition CCamera.h:271
float m_farValue
Far clipping plane distance.
Definition CCamera.h:92
core::dimension2du m_screenSize
Last known screen size.
Definition CCamera.h:121
void setInputReceiver(bool b)
Enables or disables input reception for this camera.
Definition CCamera.h:406
void setPosition(const core::vector3df &position)
Sets the world position of the camera.
void recalculateViewMatrix()
Forces recalculation of the view matrix.
void setFOV(float fov)
Sets the vertical Field of View (FOV).
Definition CCamera.h:290
ECameraProjection m_projectionType
Current projection mode.
Definition CCamera.h:86
core::vector3df getPosition()
Gets the current world position of the camera.
float getOrthoScale()
Gets the orthographic scale factor.
Definition CCamera.h:318
void copyProjection(CCamera *target)
Copies all projection parameters from another camera.
void setUpVector(const core::vector3df &up)
Sets the 'up' vector for view matrix calculation.
void recalculateProjectionMatrix()
Forces recalculation of the projection matrix.
u32 m_cullingMask
Bitmask for layer-based culling.
Definition CCamera.h:127
core::vector3df getLookVector()
Gets the current forward viewing direction.
void enableCustomOrthoUISize(bool b)
Enables or disables custom OrthoUI sizing.
Definition CCamera.h:338
float getNearValue()
Gets the near clipping plane distance.
Definition CCamera.h:262
virtual void endUpdate()
Finalizes transform and recalculates matrices. Called at the end of the frame update.
ECameraProjection getProjectionType()
Gets the current projection mode.
Definition CCamera.h:158
void setNearValue(float f)
Sets the near clipping plane distance.
Definition CCamera.h:252
const core::matrix4 & getViewMatrix() const
Returns the calculated view matrix.
float m_nearValue
Near clipping plane distance.
Definition CCamera.h:89
ECameraProjection
Supported projection modes for the camera.
Definition CCamera.h:76
@ Perspective
Custom frustum projection.
Definition CCamera.h:79
@ Custom
Screen-space orthographic projection for UI.
Definition CCamera.h:81
@ OrthoUI
Standard perspective projection.
Definition CCamera.h:80
@ Frustum
Orthographic projection (for 2D or stylized 3D).
Definition CCamera.h:78
float getAspect()
Gets the effective aspect ratio.
Definition CCamera.h:357
bool isUseScaledTime()
Checks if the camera uses scaled time.
Definition CCamera.h:433
void setOrthoUISize(float w, float h)
Sets a custom viewport size for OrthoUI projection.
Definition CCamera.h:328
bool m_projectionChanged
Flag indicating the projection matrix needs recalculation.
Definition CCamera.h:109
void setLookVector(core::vector3df look)
Rotates the camera to point in a specific direction.
void setViewMatrix(const core::matrix4 &view, const core::vector3df &position)
Manually sets the view matrix and camera position.
float m_aspect
Aspect ratio (width/height).
Definition CCamera.h:98
void setUseScaledTime(bool b)
Sets whether camera updates should use the engine's time scale.
Definition CCamera.h:424
void setProjectionMatrix(const core::matrix4 &prj)
Manually sets the projection matrix. Switches mode to 'Custom'.
void lookAt(const core::vector3df &target, const core::vector3df &up)
Configures the camera to look at a target from its current position.
core::vector3df m_up
Current 'up' vector for the view matrix.
Definition CCamera.h:115
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29