SpiecsEngine
 
Loading...
Searching...
No Matches
Spices::CameraController Class Reference

CameraController Class. This class inherit from NativeScriptComponent. It receives Mouse Event and Key Event to control the Camera movement which defined by it's owner. More...

#include <CameraController.h>

Inheritance diagram for Spices::CameraController:
Spices::NativeScriptComponent Spices::Component

Public Member Functions

 CameraController ()=default
 Constructor Function.
 
virtual ~CameraController () override=default
 Destructor Function.
 
virtual void OnSerialize () override
 The interface inherited from Component, which is used for serialize this class.
 
virtual void OnDeSerialize () override
 The interface inherited from Component, which is used for deserialize this class.
 
virtual void OnConstruction () override
 The interface inherited from NativeScriptComponent, which is called on this attached to an entity. We get the camera we want control here. We get the camera transform component here.
 
virtual void OnTick (TimeStep &ts) override
 The interface inherited from NativeScriptComponent, which is called every engine loop frame. We implemented mainly camera control here, the reason is query input has better performance than event.
 
virtual void OnEvent (Event &e) override
 The interface inherited from NativeScriptComponent, which is called on the global event function pointer called.
 
glm::vec3 GetUpDirection () const
 Get Camera Up(y) Direction.
 
glm::vec3 GetRightDirection () const
 Get Camera Right(x) Direction.
 
glm::vec3 GetForwardDirection () const
 Get Camera Forward(z) Direction.
 
glm::quat GetOrientation () const
 Get Camera quaternion rotation.
 
virtual void OnComponentAdded (const entt::entity &entity) override final
 This interface defines the behaves on specific component added. Init with variable.
 
virtual void DrawThis ()
 This interface defines how to draw this component to property panel.
 

Protected Attributes

entt::entity m_Owner { entt::null }
 This component's Owner entity.
 

Private Member Functions

bool OnKeyPressed (KeyPressedEvent &e)
 Event OnKeyPressed. We do nothing here.
 
bool OnMouseScroll (MouseScrolledEvent &e)
 Event OnMouseScroll. Scale the camera.
 
bool OnSlateResized (SlateResizeEvent &e)
 Event OnWindowResized. Reset Camera aspect ratio.
 
void MousePan (const glm::vec2 &delta)
 Calculate Camera Drag.
 
void MouseRotate (const glm::vec2 &delta) const
 Calculate Camera Rotate.
 
void MouseZoom (const float &delta)
 Calculate Camera Zoom.
 
std::pair< float, float > PanSpeed () const
 Calculate Camera Drag speed.
 
float RotationSpeed () const
 Calculate Camera Rotate speed.
 
float ZoomSpeed () const
 Calculate Camera Zoom speed.
 
void UpdateView () const
 Setting camera transform component position. We already set rotation in MouseRotate().
 
glm::vec3 CalculatePosition () const
 Calculate camera transform component position using the class member parameters.
 

Private Attributes

std::shared_ptr< Cameram_Camera
 The camera smart pointer get from owner's camera component.
 
TransformComponentm_CameraTranComp = nullptr
 The camera transform component pointer get from owner's transform component.
 
uint32_t m_ViewportWidth = 1920
 The Viewport size.
 
uint32_t m_ViewportHeight = 1080
 
float m_ZoomLevel = 1.0f
 Zoom Level, for orthographic type camera.
 
float m_Distance = 10.0f
 The camera spring arm. Init with 10.
 
glm::vec2 m_InitialMousePosition = { 0.0f, 0.0f }
 The mouse position. Init with 0.
 
glm::vec3 m_FocalPoint = { 0.0f, 0.0f, 0.0f }
 The focus point. Init with 0.
 
std::shared_ptr< NativeScriptComponentm_RealNScriptComp
 Real component.
 

Detailed Description

CameraController Class. This class inherit from NativeScriptComponent. It receives Mouse Event and Key Event to control the Camera movement which defined by it's owner.

Definition at line 22 of file CameraController.h.


The documentation for this class was generated from the following files: