Skylicht Engine
Loading...
Searching...
No Matches
CEditorCamera.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#include "Utils/CActivator.h"
28#include "CCamera.h"
29#include "Components/CComponentSystem.h"
30
31namespace Skylicht
32{
35 class SKYLICHT_API CEditorCamera :
36 public CComponentSystem,
37 public IEventReceiver
38 {
39 public:
44 {
45 Default,
48 };
49
50 protected:
53
56
59
62
64 gui::ICursorControl* m_cursorControl;
65
67 core::position2df m_centerCursor;
68
70 core::position2df m_cursorPos;
71
74 bool m_ctrlKeyDown;
75 bool m_shiftKeyDown;
76
79 bool m_rightMousePress;
80 bool m_midMousePress;
81
84 bool m_mayaRightMousePress;
85
88 float m_wheel;
89
92
95
96 public:
97 CEditorCamera();
98
99 virtual ~CEditorCamera();
100
101 virtual void initComponent();
102
103 virtual void updateComponent();
104
105 virtual void endUpdate();
106
107 virtual bool OnEvent(const SEvent& event);
108
109 DECLARE_GETTYPENAME(CEditorCamera)
110
111 public:
116 inline void setRotateSpeed(float speed)
117 {
118 m_rotateSpeed = speed;
119 }
120
125 inline void setMoveSpeed(float speed)
126 {
127 m_moveSpeed = speed;
128 }
129
134 inline float getMoveSpeed()
135 {
136 return m_moveSpeed;
137 }
138
143 inline float getRotateSpeed()
144 {
145 return m_rotateSpeed;
146 }
147
152 inline float getZoomSpeed()
153 {
154 return m_zoomSpeed;
155 }
156
161 inline void setZoomSpeed(float z)
162 {
163 m_zoomSpeed = z;
164 }
165
171 {
172 return m_camera;
173 }
174
180 {
181 m_controlStyle = style;
182 }
183
189 {
190 return m_controlStyle;
191 }
192
198 {
199 return m_rightMousePress;
200 }
201
206 inline bool isLeftMousePressed()
207 {
208 return m_leftMousePress;
209 }
210
215 void setPivotRotate(const core::vector3df& pos);
216
221 inline void setPivotRotateDistance(float d)
222 {
224 }
225
226 protected:
227
232 void fixVector(core::vector3df& v);
233
240 void updateInputRotate(core::vector3df& relativeRotation, f32 timeDiff, bool useCenterPivot = false);
241
247 void updateInputOffset(core::vector3df& offsetPosition, f32 timeDiff);
248
255 void updateInputZoom(f32 timeDiff, core::vector3df& pos, const core::vector3df& moveDir);
256 };
257}
This is an object class used to set up the camera, including its position, viewing angle,...
Definition CCamera.h:70
void setControlStyle(EControlStyle style)
Sets the active control style (Maya, Blender, etc.).
Definition CEditorCamera.h:179
gui::ICursorControl * m_cursorControl
Cursor control service for retrieving mouse position.
Definition CEditorCamera.h:64
void updateInputOffset(core::vector3df &offsetPosition, f32 timeDiff)
Updates position offset (panning).
void updateInputZoom(f32 timeDiff, core::vector3df &pos, const core::vector3df &moveDir)
Updates zoom by moving the camera along its forward vector.
void setPivotRotateDistance(float d)
Directly sets the distance to the orbit pivot.
Definition CEditorCamera.h:221
void setMoveSpeed(float speed)
Sets the panning speed.
Definition CEditorCamera.h:125
bool isRightMousePressed()
Checks if the right mouse button is currently held.
Definition CEditorCamera.h:197
bool m_altKeyDown
Modifier key states.
Definition CEditorCamera.h:73
bool isLeftMousePressed()
Checks if the left mouse button is currently held.
Definition CEditorCamera.h:206
CCamera * m_camera
Pointer to the CCamera component.
Definition CEditorCamera.h:52
bool m_leftMousePress
Basic mouse button states.
Definition CEditorCamera.h:78
f32 m_moveSpeed
Panning/Movement sensitivity.
Definition CEditorCamera.h:55
bool m_mayaLeftMousePress
Specialized Maya mouse button states.
Definition CEditorCamera.h:83
void setZoomSpeed(float z)
Sets the zooming speed.
Definition CEditorCamera.h:161
float getRotateSpeed()
Gets the current orbit rotation speed.
Definition CEditorCamera.h:143
void updateInputRotate(core::vector3df &relativeRotation, f32 timeDiff, bool useCenterPivot=false)
Updates horizontal and vertical orbit rotation.
float getZoomSpeed()
Gets the zooming speed.
Definition CEditorCamera.h:152
core::position2df m_cursorPos
Current normalized cursor position.
Definition CEditorCamera.h:70
float m_pivotRotateDistance
Distance from the pivot point for orbit rotation.
Definition CEditorCamera.h:91
CCamera * getCamera()
Gets the attached camera component.
Definition CEditorCamera.h:170
float getMoveSpeed()
Gets the current panning speed.
Definition CEditorCamera.h:134
core::position2df m_centerCursor
Normalized cursor position at start of interaction.
Definition CEditorCamera.h:67
bool m_mouseWhell
Mouse wheel state and delta.
Definition CEditorCamera.h:87
EControlStyle getControlStyle()
Gets the current control style.
Definition CEditorCamera.h:188
void setRotateSpeed(float speed)
Sets the orbit rotation speed.
Definition CEditorCamera.h:116
EControlStyle m_controlStyle
Active control style.
Definition CEditorCamera.h:94
f32 m_zoomSpeed
Zooming sensitivity.
Definition CEditorCamera.h:61
void fixVector(core::vector3df &v)
Cleans up tiny vector components to prevent floating point drift.
EControlStyle
Supported control styles for the editor camera.
Definition CEditorCamera.h:44
@ Blender
Alt-based navigation (Alt+LMB Rotate, Alt+MMB Pan, Alt+RMB Zoom).
Definition CEditorCamera.h:47
@ Maya
Standard WASD/Mouse controls.
Definition CEditorCamera.h:46
f32 m_rotateSpeed
Orbit/Rotation sensitivity.
Definition CEditorCamera.h:58
void setPivotRotate(const core::vector3df &pos)
Sets the orbit pivot point and calculates distance.
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29