Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
Muto::OrthographicCameraController Class Reference

#include <OrthographicCameraController.h>

Public Member Functions

bool CanRotate () const
 
float GetAspectRatio () const
 
OrthographicCameraBounds GetBounds () const
 
OrthographicCamera & GetCamera ()
 
const OrthographicCamera & GetCamera () const
 
float GetMoveSpeed () const
 
glm::vec3 GetPosition () const
 
float GetRotation () const
 
float GetRotationSpeed () const
 
float GetZoomLevel () const
 
void OnEvent (Event &e)
 
void OnImGuiRender ()
 TODO: move to an editor component that can be attached to any system (EditorAbstractionComp)
 
void OnResize (float width, float height)
 
void OnUpdate (Timestep ts)
 
 OrthographicCameraController (float aspectRatio, bool rotation=false)
 
void SetAspectRatio (float aspectRatio)
 
void SetCanRotate (bool canRotate)
 
void SetMoveSpeed (float speed)
 
void SetPosition (float x, float y)
 
void SetRotation (float rotation)
 
void SetRotationSpeed (float speed)
 
void SetZoomLevel (float level)
 

Private Member Functions

void CalculateView ()
 
bool OnMouseScrolled (MouseScrolledEvent &e)
 
void OnUpdateBounds ()
 
bool OnWindowResized (WindowResizeEvent &e)
 
void UpdateCameraBounds ()
 

Private Attributes

OrthographicCamera camera
 
float m_AspectRatio
 
OrthographicCameraBounds m_Bounds
 
float m_CameraMoveSpeed = 5.0f
 
glm::vec3 m_CameraPosition = { 0.0f, 0.0f, 0.0f }
 
float m_CameraRotation = 0.0f
 
float m_CameraRotationSpeed = 180.0f
 
bool m_Rotation = true
 
float m_ZoomLevel = 1.0f
 

Constructor & Destructor Documentation

◆ OrthographicCameraController()

Muto::OrthographicCameraController::OrthographicCameraController ( float  aspectRatio,
bool  rotation = false 
)
17 {
18
19 }
bool m_Rotation
Definition OrthographicCameraController.h:77
OrthographicCameraBounds m_Bounds
Definition OrthographicCameraController.h:75
float m_ZoomLevel
Definition OrthographicCameraController.h:73
float m_AspectRatio
Definition OrthographicCameraController.h:72
OrthographicCamera camera
Definition OrthographicCameraController.h:74
constexpr Scope< T > CreateScope(Args &&... args)
Creates a Scope (unique_ptr) for the given type and constructor arguments.
Definition Defines_Macros.h:51

References m_AspectRatio, m_Bounds, m_Rotation, m_ZoomLevel, and OrthographicCameraController().

Referenced by OrthographicCameraController().

Member Function Documentation

◆ CalculateView()

void Muto::OrthographicCameraController::CalculateView ( )
private
96 {
99 }
void UpdateCameraBounds()
Definition OrthographicCameraController.cpp:81
void SetProjection(float left, float right, float bottom, float top)
Definition OrthographicCamera.cpp:15
float Left
Definition OrthographicCameraController.h:20
float Right
Definition OrthographicCameraController.h:20
float Top
Definition OrthographicCameraController.h:21
float Bottom
Definition OrthographicCameraController.h:21

References UpdateCameraBounds().

Referenced by OnMouseScrolled(), OnResize(), SetAspectRatio(), and SetZoomLevel().

◆ CanRotate()

bool Muto::OrthographicCameraController::CanRotate ( ) const
inline
57{ return m_Rotation; }

References m_Rotation.

Referenced by OnImGuiRender().

◆ GetAspectRatio()

float Muto::OrthographicCameraController::GetAspectRatio ( ) const
124 {
125 return m_AspectRatio;
126 }

References m_AspectRatio.

◆ GetBounds()

OrthographicCameraBounds Muto::OrthographicCameraController::GetBounds ( ) const
inline
40{ return m_Bounds; }

References m_Bounds.

◆ GetCamera() [1/2]

OrthographicCamera & Muto::OrthographicCameraController::GetCamera ( )
inline
38{ return camera; }

◆ GetCamera() [2/2]

const OrthographicCamera & Muto::OrthographicCameraController::GetCamera ( ) const
inline
39{ return camera; }

◆ GetMoveSpeed()

float Muto::OrthographicCameraController::GetMoveSpeed ( ) const
inline
46{ return m_CameraMoveSpeed; }
float m_CameraMoveSpeed
Definition OrthographicCameraController.h:80

References m_CameraMoveSpeed.

Referenced by OnImGuiRender().

◆ GetPosition()

glm::vec3 Muto::OrthographicCameraController::GetPosition ( ) const
inline
42{ return m_CameraPosition; }
glm::vec3 m_CameraPosition
Definition OrthographicCameraController.h:78

◆ GetRotation()

float Muto::OrthographicCameraController::GetRotation ( ) const
inline
49{ return m_CameraRotation; }
float m_CameraRotation
Definition OrthographicCameraController.h:79

References m_CameraRotation.

Referenced by OnImGuiRender().

◆ GetRotationSpeed()

float Muto::OrthographicCameraController::GetRotationSpeed ( ) const
inline
52{ return m_CameraRotationSpeed; }
float m_CameraRotationSpeed
Definition OrthographicCameraController.h:80

References m_CameraRotationSpeed.

Referenced by OnImGuiRender().

◆ GetZoomLevel()

float Muto::OrthographicCameraController::GetZoomLevel ( ) const
inline
61{ return m_ZoomLevel; }

References m_ZoomLevel.

◆ OnEvent()

void Muto::OrthographicCameraController::OnEvent ( Event &  e)
48 {
50 EventDispatcher dispatcher(e);
53
54 }
#define MU_BIND_EVENT_FN(fn)
Binds a member function as an event handler.
Definition Defines_Macros.h:17
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
bool OnWindowResized(WindowResizeEvent &e)
Definition OrthographicCameraController.cpp:74
bool OnMouseScrolled(MouseScrolledEvent &e)
Definition OrthographicCameraController.cpp:65

References Muto::EventDispatcher::EventDispatcher(), OnMouseScrolled(), and OnWindowResized().

◆ OnImGuiRender()

void Muto::OrthographicCameraController::OnImGuiRender ( )

TODO: move to an editor component that can be attached to any system (EditorAbstractionComp)

137 {
138 //ImGui::Begin("Settings");
139
140 static float camPos[3] = { GetPosition().x, GetPosition().y, GetPosition().z };
141 if (ImGui::DragFloat3("Cam Pos", camPos, 0.1f)) {
142 SetPosition(camPos[0], camPos[1]);
143 }
144 static float camMoveSpeed = GetMoveSpeed();
145 if (ImGui::DragFloat("Cam Speed", &camMoveSpeed, 0.1f)) {
147 }
148 ImGui::Separator();
149 static bool rotate = CanRotate();
150 if (ImGui::Checkbox("Rotate?", &rotate)) {
152 }
153 ImGui::Separator();
154 static float camRot = GetRotation();
155 if (ImGui::DragFloat("Cam Rotation", &camRot, 0.1f)) {
157 }
158 static float camRotSpeed = GetRotationSpeed();
159 if (ImGui::DragFloat("Cam Rot Speed", &camRotSpeed, 1.0f)) {
161 }
162 //ImGui::End();
163
164 }
glm::vec3 GetPosition() const
Definition OrthographicCameraController.h:42
float GetRotation() const
Definition OrthographicCameraController.h:49
float GetRotationSpeed() const
Definition OrthographicCameraController.h:52
void SetRotationSpeed(float speed)
Definition OrthographicCameraController.cpp:118
void SetPosition(float x, float y)
Definition OrthographicCameraController.cpp:101
void SetRotation(float rotation)
Definition OrthographicCameraController.cpp:112
float GetMoveSpeed() const
Definition OrthographicCameraController.h:46
void SetMoveSpeed(float speed)
Definition OrthographicCameraController.cpp:107
void SetCanRotate(bool canRotate)
Definition OrthographicCameraController.h:58
bool CanRotate() const
Definition OrthographicCameraController.h:57

References CanRotate(), GetMoveSpeed(), GetRotation(), GetRotationSpeed(), SetCanRotate(), SetMoveSpeed(), SetPosition(), SetRotation(), and SetRotationSpeed().

◆ OnMouseScrolled()

bool Muto::OrthographicCameraController::OnMouseScrolled ( MouseScrolledEvent &  e)
private
66 {
68 m_ZoomLevel -= e.GetYOffset() * 0.25f;
69 m_ZoomLevel = std::max(m_ZoomLevel, 0.25f);
71 return false;
72 }
void CalculateView()
Definition OrthographicCameraController.cpp:95

References CalculateView(), Muto::MouseScrolledEvent::GetYOffset(), and m_ZoomLevel.

Referenced by OnEvent().

◆ OnResize()

void Muto::OrthographicCameraController::OnResize ( float  width,
float  height 
)
57 {
61
62 }

References CalculateView(), and m_AspectRatio.

Referenced by OnWindowResized().

◆ OnUpdate()

void Muto::OrthographicCameraController::OnUpdate ( Timestep  ts)
22 {
24
29
34
35 if (m_Rotation)
36 {
41
43 }
45 }
static bool IsKeyPressed(int keycode)
Checks if the specified key is currently pressed.
Definition WindowsInput.cpp:9
void SetPosition(const glm::vec3 &position)
Definition OrthographicCamera.h:21
void SetRotation(float rotation)
Definition OrthographicCamera.h:24
@ A
Definition KeyCodes.h:41
@ E
Definition KeyCodes.h:45
@ S
Definition KeyCodes.h:59
@ W
Definition KeyCodes.h:63
@ Q
Definition KeyCodes.h:57
@ D
Definition KeyCodes.h:44

References Muto::Key::E, Muto::Input::IsKeyPressed(), m_CameraRotation, m_CameraRotationSpeed, m_Rotation, and Muto::Key::Q.

◆ OnUpdateBounds()

void Muto::OrthographicCameraController::OnUpdateBounds ( )
private
91 {
92 // Nothing for now
93 }

Referenced by UpdateCameraBounds().

◆ OnWindowResized()

bool Muto::OrthographicCameraController::OnWindowResized ( WindowResizeEvent &  e)
private
75 {
77 OnResize((float)e.GetWidth(), (float)e.GetHeight());
78 return false;
79 }
void OnResize(float width, float height)
Definition OrthographicCameraController.cpp:56

References Muto::WindowResizeEvent::GetHeight(), Muto::WindowResizeEvent::GetWidth(), and OnResize().

Referenced by OnEvent().

◆ SetAspectRatio()

void Muto::OrthographicCameraController::SetAspectRatio ( float  aspectRatio)
129 {
132 }

References CalculateView(), and m_AspectRatio.

◆ SetCanRotate()

void Muto::OrthographicCameraController::SetCanRotate ( bool  canRotate)
inline

References m_Rotation.

Referenced by OnImGuiRender().

◆ SetMoveSpeed()

void Muto::OrthographicCameraController::SetMoveSpeed ( float  speed)
108 {
110 }

References m_CameraMoveSpeed.

Referenced by OnImGuiRender().

◆ SetPosition()

void Muto::OrthographicCameraController::SetPosition ( float  x,
float  y 
)
102 {
103 m_CameraPosition = { x, y, 0.0f };
105 }

Referenced by OnImGuiRender().

◆ SetRotation()

void Muto::OrthographicCameraController::SetRotation ( float  rotation)

References m_CameraRotation.

Referenced by OnImGuiRender().

◆ SetRotationSpeed()

void Muto::OrthographicCameraController::SetRotationSpeed ( float  speed)
119 {
121 }

References m_CameraRotationSpeed.

Referenced by OnImGuiRender().

◆ SetZoomLevel()

void Muto::OrthographicCameraController::SetZoomLevel ( float  level)
inline

◆ UpdateCameraBounds()

Member Data Documentation

◆ camera

OrthographicCamera Muto::OrthographicCameraController::camera
private

◆ m_AspectRatio

float Muto::OrthographicCameraController::m_AspectRatio
private

◆ m_Bounds

OrthographicCameraBounds Muto::OrthographicCameraController::m_Bounds
private

◆ m_CameraMoveSpeed

float Muto::OrthographicCameraController::m_CameraMoveSpeed = 5.0f
private

Referenced by GetMoveSpeed(), and SetMoveSpeed().

◆ m_CameraPosition

glm::vec3 Muto::OrthographicCameraController::m_CameraPosition = { 0.0f, 0.0f, 0.0f }
private
78{ 0.0f, 0.0f, 0.0f };

◆ m_CameraRotation

float Muto::OrthographicCameraController::m_CameraRotation = 0.0f
private

Referenced by GetRotation(), OnUpdate(), and SetRotation().

◆ m_CameraRotationSpeed

float Muto::OrthographicCameraController::m_CameraRotationSpeed = 180.0f
private

◆ m_Rotation

bool Muto::OrthographicCameraController::m_Rotation = true
private

◆ m_ZoomLevel

float Muto::OrthographicCameraController::m_ZoomLevel = 1.0f
private

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