2
3
4
5
9#include "World/Entity.h"
10#include "Render/FrameInfo.h"
11#include "Core/Input/Input.h"
12#include "Core/Input/MouseButtonCodes.h"
13#include "Systems/SlateSystem.h"
14#include "Core/Input/KeyCodes.h"
22 Entity entity( m_Owner, FrameInfo::Get().m_World.get());
24 m_Camera = entity.GetComponent<CameraComponent>().GetCamera();
31 m_Camera->IncreaseStableFrames();
34
35
36 if (!SlateSystem::GetRegister()->GetViewPort()->IsHovered())
return;
40 const glm::vec2& mouse { Input::GetMouseX(), Input::GetMouseY() };
41 const glm::vec2 delta = (mouse - m_InitialMousePosition) * 0.003f;
42 m_InitialMousePosition = mouse;
47 m_Camera->ResetStableFrames();
52 m_Camera->ResetStableFrames();
57 m_Camera->ResetStableFrames();
84 if (!SlateSystem::GetRegister()->GetViewPort()->IsHovered())
return false;
93 if (m_Camera->GetProjectionType() == ProjectionType::Orthographic)
95 m_Camera->SetOrthographic(-ratio * m_ZoomLevel, ratio * m_ZoomLevel, -m_ZoomLevel, m_ZoomLevel, 0.001f, 100000.0f);
100 m_Camera->ResetStableFrames();
112 switch (m_Camera->GetProjectionType())
114 case ProjectionType::Perspective:
115 m_Camera->SetPerspective(ratio);
117 case ProjectionType::Orthographic:
118 m_Camera->SetOrthographic(-ratio * m_ZoomLevel, ratio * m_ZoomLevel, -m_ZoomLevel, m_ZoomLevel, 0.001f, 100000.0f);
122 m_Camera->ResetStableFrames();
131 m_FocalPoint += -GetRightDirection() * delta.x * xSpeed * m_Distance;
132 m_FocalPoint += -GetUpDirection() * delta.y * ySpeed * m_Distance;
139 glm::vec3 rot = m_CameraTranComp->GetRotation();
140 const float yawSign = GetUpDirection().y < 0 ? -1.0f : 1.0f;
142 rot.y -= glm::degrees(yawSign * delta.x * RotationSpeed());
143 rot.x += glm::degrees(delta.y * RotationSpeed());
145 m_CameraTranComp->SetRotation(rot);
155 m_FocalPoint += GetForwardDirection();
164 const float x = std::min(
static_cast<
float>(
m_ViewportWidth) / 1000.0f, 2.4f);
165 float xFactor = 0.0366f * (x * x) - 0.1778f * x + 0.3021f;
167 const float y = std::min(
static_cast<
float>(
m_ViewportHeight) / 1000.0f, 2.4f);
168 float yFactor = 0.0366f * (y * y) - 0.1778f * y + 0.3021f;
170 return { xFactor, yFactor };
185 distance = std::max(distance, 0.0f);
186 float speed = distance * distance;
187 speed = std::min(speed, 100.0f);
195 const glm::vec3 pos = CalculatePosition();
196 m_CameraTranComp->SetPosition(pos);
204 return m_FocalPoint - GetForwardDirection() * m_Distance;
211 return glm::rotate(GetOrientation(), glm::vec3(0.0f, -1.0f, 0.0f));
218 return glm::rotate(GetOrientation(), glm::vec3(1.0f, 0.0f, 0.0f));
225 return glm::rotate(GetOrientation(), glm::vec3(0.0f, 0.0f, 1.0f));
232 const glm::vec3& rot = m_CameraTranComp->GetRotation();
233 return glm::quat({ glm::radians(rot.x), glm::radians(rot.y), glm::radians(rot.z) });
#define BIND_EVENT_FN(x)
Bind Event.
#define SPICES_PROFILE_ZONE
virtual void OnEvent(Event &e) override
The interface inherited from NativeScriptComponent, which is called on the global event function poin...
glm::vec3 GetForwardDirection() const
Get Camera Forward(z) Direction.
uint32_t m_ViewportWidth
The Viewport size.
glm::vec3 GetUpDirection() const
Get Camera Up(y) Direction.
bool OnKeyPressed(KeyPressedEvent &e)
Event OnKeyPressed. We do nothing here.
bool OnMouseScroll(MouseScrolledEvent &e)
Event OnMouseScroll. Scale the camera.
void MousePan(const glm::vec2 &delta)
Calculate Camera Drag.
void MouseZoom(const float &delta)
Calculate Camera Zoom.
void UpdateView() const
Setting camera transform component position. We already set rotation in MouseRotate().
std::pair< float, float > PanSpeed() const
Calculate Camera Drag speed.
glm::quat GetOrientation() const
Get Camera quaternion rotation.
void MouseRotate(const glm::vec2 &delta) const
Calculate Camera Rotate.
virtual void OnConstruction() override
The interface inherited from NativeScriptComponent, which is called on this attached to an entity....
bool OnSlateResized(SlateResizeEvent &e)
Event OnWindowResized. Reset Camera aspect ratio.
uint32_t m_ViewportHeight
float ZoomSpeed() const
Calculate Camera Zoom speed.
float m_Distance
The camera spring arm. Init with 10.
glm::vec3 GetRightDirection() const
Get Camera Right(x) Direction.
TransformComponent * m_CameraTranComp
The camera transform component pointer get from owner's transform component.
glm::vec3 CalculatePosition() const
Calculate camera transform component position using the class member parameters.
virtual void OnTick(TimeStep &ts) override
The interface inherited from NativeScriptComponent, which is called every engine loop frame....
float RotationSpeed() const
Calculate Camera Rotate speed.
float m_ZoomLevel
Zoom Level, for orthographic type camera.
CameraController Class. This class inherit from NativeScriptComponent. It receives Mouse Event and Ke...
Entity Class. This class defines the specific behaves of Entity.
EventDispatcher(Event &event)
Constructor Function.
This Class store a Specific Event type first and Dispatch a event handle function to it.
This Class is the basic Event Class. Inherit from it and create specific event class.
This Class is inherited from KeyEvent Class.
const uint32_t & GetHeight() const
Get New Viewport Height.
const uint32_t & GetWidth() const
Get New Viewport Width.
This Class is inherited from Event Class. Called by Viewport Resize.
This Class handles our engine time step during frames. Global Unique.