SpiecsEngine
 
Loading...
Searching...
No Matches
Camera.cpp
Go to the documentation of this file.
1/**
2* @file Camera.cpp.
3* @brief The Camera Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
8#include "Camera.h"
9#include "Core/Math/Math.h"
10#include "Render/FrameInfo.h"
11#include "Slate/SlateInfoBar.h"
12
13namespace Spices {
14
15 void Camera::SetPerspective(float fov, float nearPlane, float aspectRatio)
16 {
18
20
24 }
25
26 void Camera::SetPerspective(float aspectRatio)
27 {
29
31
33 }
34
35 void Camera::SetOrthographic(float left, float right, float top, float bottom, float nearPlane, float farPlane)
36 {
38
40
47 }
48
50 {
52
54
55 if (m_StableFrames > 100)
56 {
57 SlateInfoBar::Create<float>("Refrush frame", [=]() -> float {
58 return static_cast<float>(this->m_StableFrames) / 100.0f;
59 }, [=](SlateInfoBar* that) {
60 return std::any_cast<float>(that->GetRate()) >= 1.0f;
61 });
62 }
63
65 }
66
67 const glm::mat4 Camera::GetPMatrix() const
68 {
70
71 switch (m_ProjectionType)
72 {
73 case ProjectionType::Perspective:
74 return PerspectiveMatrix(
75 m_PerspectiveParam.fov ,
76 m_PerspectiveParam.nearPlane ,
77 100000000.0f,
78 m_PerspectiveParam.aspectRatio
79 );
80 case ProjectionType::Orthographic:
81 return OtrhographicMatrix(
82 m_OrthographicParam.left ,
83 m_OrthographicParam.right ,
84 m_OrthographicParam.top ,
85 m_OrthographicParam.bottom ,
86 m_OrthographicParam.nearPlane ,
87 m_OrthographicParam.farPlane
88 );
89 }
90
91 return glm::mat4(1.0f);
92 }
93
95 {
97
98 switch (m_ProjectionType)
99 {
100 case ProjectionType::Perspective:
101 m_ProjectionMatrix = PerspectiveMatrixInverseZ(
102 m_PerspectiveParam.fov ,
103 m_PerspectiveParam.nearPlane ,
104 m_PerspectiveParam.aspectRatio
105 );
106 break;
107 case ProjectionType::Orthographic:
108 m_ProjectionMatrix = OtrhographicMatrix(
109 m_OrthographicParam.left ,
110 m_OrthographicParam.right ,
111 m_OrthographicParam.top ,
112 m_OrthographicParam.bottom ,
113 m_OrthographicParam.nearPlane ,
114 m_OrthographicParam.farPlane
115 );
116 break;
117 }
118 }
119}
#define SPICES_PROFILE_ZONE
unsigned int m_StableFrames
Camera Stable Frames Number.
Definition Camera.h:174
void CalculatePMatrixReverseZ()
Calculate Projection Matrix by parameter.
Definition Camera.cpp:94
const glm::mat4 GetPMatrix() const
Get camera projection matrix.
Definition Camera.cpp:67
OrthographicParam m_OrthographicParam
Camera OrthographicParam.
Definition Camera.h:184
void SetOrthographic(float left, float right, float top, float bottom, float nearPlane, float farPlane)
Set ProjectionMatrix by using orthographic type.
Definition Camera.cpp:35
void SetPerspective(float aspectRatio)
Set ProjectionMatrix by using perspective type with one param.
Definition Camera.cpp:26
void SetPerspective(float fov, float nearPlane, float aspectRatio=1.777f)
Set ProjectionMatrix by using perspective type.
Definition Camera.cpp:15
void ResetStableFrames()
Reset m_StableFrames to 0.
Definition Camera.cpp:49
ProjectionType m_ProjectionType
Definition Camera.h:169
PerspectiveParam m_PerspectiveParam
Camera PerspectiveParam.
Definition Camera.h:179
Camera Class. This class just encapsulate Projection Matrix.
Definition Camera.h:59
static FrameInfo & Get()
Get FrameInfo.
Definition FrameInfo.cpp:14
RendererType m_RendererType
The renderer type of current world.
Definition FrameInfo.h:99
FrameInfo Class. This class defines the FrameInfo data.
Definition FrameInfo.h:32
RendererType
Definition FrameInfo.h:22
ProjectionType
This Struct defines camera projection type.
Definition Camera.h:18
@ Orthographic
orthographic
Definition Camera.h:27
@ Perspective
perspective
Definition Camera.h:22