SleakEngine 1.0.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
CameraController.hpp
Go to the documentation of this file.
1#ifndef _CAMERACONTROLLERCOMPONENT_HPP_
2#define _CAMERACONTROLLERCOMPONENT_HPP_
3
4#include <ECS/Component.hpp>
5#include <Math/Vector.hpp>
6#include <Camera/Camera.hpp>
7#include <Memory/RefPtr.hpp>
8#include <Core/OSDef.hpp>
9
10namespace Sleak {
11 /// Base for components that drive a Camera GameObject from input.
12 /// Concrete controllers (first-person, free-look) implement UpdateInput/UpdateCamera.
13 /// @ingroup scene
14 class ENGINE_API CameraController : public Component {
15 public:
17 ~CameraController() override = default;
18
19 virtual bool Initialize() {
20 bIsInitialized = true;
21
22 camera = GetCamera();
23
24 return true;
25 }
26
27 virtual void Update(float deltaTime) = 0;
28
29 /// Shows or hides the OS cursor and, typically, toggles relative mouse mode.
30 virtual void ToggleCursor(bool enable) = 0;
31
32 virtual void SetEnabled(bool enabled) {isEnabled = enabled;}
33 virtual bool IsEnabled() const {return isEnabled;}
34 virtual void SetSensitivity(float sensitivity) {this->sensitivity = sensitivity;}
35 virtual float GetSensitivity() const {return sensitivity;}
36
37 /// Casts the owning GameObject to Camera; valid only when attached to one.
39 return dynamic_cast<Camera*>(owner);
40 }
41
42 protected:
43 /// Applies accumulated input to the camera's position/orientation.
44 virtual void UpdateCamera(float deltaTime) = 0;
45 /// Polls raw input devices and updates translation/rotation input state.
46 virtual void UpdateInput(float deltaTime) = 0;
47
48 float sensitivity = 0.0f;
49 bool isEnabled = true;
50
54
55 Camera* camera = nullptr;
56 };
57}
58
59#endif
virtual void SetEnabled(bool enabled)
virtual bool IsEnabled() const
~CameraController() override=default
Camera * GetCamera()
Casts the owning GameObject to Camera; valid only when attached to one.
CameraController(GameObject *object)
virtual void ToggleCursor(bool enable)=0
Shows or hides the OS cursor and, typically, toggles relative mouse mode.
virtual void UpdateCamera(float deltaTime)=0
Applies accumulated input to the camera's position/orientation.
virtual void Update(float deltaTime)=0
virtual void UpdateInput(float deltaTime)=0
Polls raw input devices and updates translation/rotation input state.
virtual void SetSensitivity(float sensitivity)
virtual bool Initialize()
One-time setup, called after the component is attached and the owner is initialized.
virtual float GetSensitivity() const
GameObject * owner
Definition Component.hpp:81
Component(GameObject *object)
Definition Component.hpp:61
Root namespace for everything the engine exposes.
Definition Camera.hpp:10