reference

This documentation is automatically generated from the openFrameworks source code using doxygen and refers to the most recent release, version 0.12.0.

ofEasyCam.h
Go to the documentation of this file.
1#pragma once
2
3#include "ofCamera.h"
4#include "ofEvents.h"
5#include "ofRectangle.h"
6
7#define GLM_FORCE_CTOR_INIT
8#include "glm/gtc/quaternion.hpp"
9
11class ofEasyCam : public ofCamera {
12public:
15
17 ofEasyCam();
18
22
23 virtual void begin(const ofRectangle & viewport);
24 virtual void begin(){
26 }
27
29 void reset();
30
34
37 void setTarget(const glm::vec3& target);
38
41 void setTarget(ofNode& target);
42
45 const ofNode& getTarget() const;
46
50
53 void setDistance(float distance);
54
57 float getDistance() const;
58
65 void setDrag(float drag);
66
69 float getDrag() const;
70
77 void setAutoDistance(bool bAutoDistance);
78
79 void setEvents(ofCoreEvents & events);
80
87 void setRotationSensitivity(float x, float y, float z);
88 void setRotationSensitivity(const glm::vec3& sensitivity);
89
92 void setTranslationSensitivity(float x, float y, float z);
93 void setTranslationSensitivity(const glm::vec3& sensitivity);
100 void setTranslationKey(char key);
101
104 char getTranslationKey() const;
105
109
111 void enableMouseInput();
112
114 void disableMouseInput();
115
119 bool getMouseInputEnabled() const;
120
123
126
130 bool getMouseMiddleButtonEnabled() const;
131
133
139 void setRelativeYAxis(bool relative=true);
140
143 bool getRelativeYAxis() const;
144
147 void setUpAxis(const glm::vec3 & up);
148
150 const glm::vec3 & getUpAxis() const;
151
152 void enableInertia();
153 void disableInertia();
154
156 bool getInertiaEnabled() const;
157
160 void setControlArea(const ofRectangle & controlArea);
161
164 void clearControlArea();
165
168
177
178 void addInteraction(TransformType type, int mouseButton, int key = -1);
179 void removeInteraction(TransformType type, int mouseButton, int key = -1);
180 bool hasInteraction(TransformType type, int mouseButton, int key = -1);
181 bool hasInteraction(int mouseButton, int key);
183protected:
184 virtual void onPositionChanged() ;
185private:
186 void setDistance(float distance, bool save);
187
188 ofNode target;
189
190 bool bEnableMouseMiddleButton = true;
191 bool bApplyInertia = false;
192
193 bool bInsideArcball = false;
194 bool bMouseInputEnabled = true;
195 bool bDistanceSet = false;
196 bool bAutoDistance = true;
197 bool bEventsSet = false;
198 bool bIsScrolling = false;
199 float lastDistance = 0.f;
200
201
202 float drag = 0.9f;
203
206 glm::vec3 rot;
208 glm::vec3 translate;
209
214 glm::vec3 sensitivityTranslate;
215 glm::vec3 sensitivityRot;
216 float sensitivityScroll = 1.0f;
217
219 glm::vec2 prevMouse;
221 glm::vec2 mouseVel;
222
223 void updateRotation();
224 void updateTranslation();
225 void update(ofEventArgs & args);
226 void mousePressed(ofMouseEventArgs & mouse);
227 void mouseReleased(ofMouseEventArgs & mouse);
228 void mouseScrolled(ofMouseEventArgs & mouse);
229 void updateMouse(const glm::vec2 & mouse);
231 glm::vec3 up() const;
232
234 char doTranslationKey = 'm';
235
237 unsigned long lastTap = 0;
238
240 glm::quat curRot;
241
245
246 glm::vec3 lastPressAxisX;
247 glm::vec3 lastPressAxisY;
248 glm::vec3 lastPressAxisZ;
249 glm::vec3 lastPressPosition;
250 glm::quat lastPressOrientation;
251 glm::vec2 lastPressMouse;
252
254
256 ofRectangle viewport;
257
259 ofRectangle controlArea;
260
261 ofEventListeners listeners;
262 ofCoreEvents * events = nullptr;
263
264 bool bRelativeYAxis = false;
265 bool doInertia = false;
266 glm::vec3 upAxis{0,1,0};
267
268 glm::vec2 mouseAtScroll;
269
270 TransformType currentTransformType;
272 struct interaction{
273 interaction():mouseButton(0), key(-1), transformType(TRANSFORM_NONE){}
274 interaction(TransformType type, int _mouseButton, int _key = -1):mouseButton(_mouseButton), key(_key), transformType(type){}
275 int mouseButton;
276 int key;
277 TransformType transformType;
278 };
279 std::vector<interaction> interactions;
280};
A basic camera object for interacting with objects in 3D space.
Definition ofCamera.h:13
ofRectangle getViewport() const
Definition ofCamera.cpp:232
Definition ofEvents.h:326
A super simple camera for interacting with objects in 3D space.
Definition ofEasyCam.h:11
bool getRelativeYAxis() const
Definition ofEasyCam.cpp:250
void disableInertia()
Definition ofEasyCam.cpp:270
char getTranslationKey() const
Get the current translation key code.
Definition ofEasyCam.cpp:142
void setRelativeYAxis(bool relative=true)
Definition ofEasyCam.cpp:245
void disableMouseInput()
Disable mouse camera control.
Definition ofEasyCam.cpp:163
void setRotationSensitivity(float x, float y, float z)
Set the input sensitivity of the rotation. X and Y axes - when the value is 1.0, moving the mouse fro...
Definition ofEasyCam.cpp:204
float getDrag() const
Get the camera's drag coefficient.
Definition ofEasyCam.cpp:132
void setEvents(ofCoreEvents &events)
Definition ofEasyCam.cpp:180
void setDrag(float drag)
Set the camera's drag coefficient.
Definition ofEasyCam.cpp:127
void setDistance(float distance)
Set the camera's distance to the target.
Definition ofEasyCam.cpp:98
virtual void begin()
Begins rendering with the camera.
Definition ofEasyCam.h:24
bool getInertiaEnabled() const
Determine if intertia is enabled.
Definition ofEasyCam.cpp:275
void setUpAxis(const glm::vec3 &up)
Definition ofEasyCam.cpp:255
virtual void onPositionChanged()
Classes extending ofNode can override this method to get notified when the position changed.
Definition ofEasyCam.cpp:514
void clearControlArea()
Definition ofEasyCam.cpp:350
void reset()
Reset the camera position and orientation.
Definition ofEasyCam.cpp:61
void enableMouseMiddleButton()
Enable the mouse's middle button for camera control.
Definition ofEasyCam.cpp:217
void setTranslationKey(char key)
Set the key used to switch between camera rotation and translation.
Definition ofEasyCam.cpp:137
ofRectangle getControlArea() const
Returns the area bounds used for mouse control.
Definition ofEasyCam.cpp:355
void removeInteraction(TransformType type, int mouseButton, int key=-1)
Definition ofEasyCam.cpp:488
bool getMouseInputEnabled() const
Determine if mouse camera control is enabled.
Definition ofEasyCam.cpp:175
const ofNode & getTarget() const
Get the camera's target node reference.
Definition ofEasyCam.cpp:93
void setTranslationSensitivity(float x, float y, float z)
Set the input sensitivity of the translation.
Definition ofEasyCam.cpp:212
const glm::vec3 & getUpAxis() const
Get the up axis.
Definition ofEasyCam.cpp:260
void enableMouseInput()
Enable mouse camera control.
Definition ofEasyCam.cpp:147
void setAutoDistance(bool bAutoDistance)
Enable or disable camera autodistance.
Definition ofEasyCam.cpp:119
void addInteraction(TransformType type, int mouseButton, int key=-1)
Definition ofEasyCam.cpp:480
float getDistance() const
Get the distance to the target.
Definition ofEasyCam.cpp:114
bool getMouseMiddleButtonEnabled() const
Determine if the middle mouse button is enabled.
Definition ofEasyCam.cpp:227
void setTarget(const glm::vec3 &target)
Set the camera's target.
Definition ofEasyCam.cpp:81
bool hasInteraction(TransformType type, int mouseButton, int key=-1)
Definition ofEasyCam.cpp:501
ofEasyCam()
Create a default camera.
Definition ofEasyCam.cpp:18
void disableMouseMiddleButton()
Disable the mouse's middle button for camera control.
Definition ofEasyCam.cpp:222
TransformType
Transformation types available for mouse interaction.
Definition ofEasyCam.h:170
@ TRANSFORM_NONE
Definition ofEasyCam.h:171
@ TRANSFORM_ROTATE
Definition ofEasyCam.h:172
@ TRANSFORM_SCALE
Definition ofEasyCam.h:175
@ TRANSFORM_TRANSLATE_XY
Definition ofEasyCam.h:173
@ TRANSFORM_TRANSLATE_Z
Definition ofEasyCam.h:174
void setControlArea(const ofRectangle &controlArea)
Definition ofEasyCam.cpp:345
void removeAllInteractions()
Definition ofEasyCam.cpp:510
void enableInertia()
Definition ofEasyCam.cpp:265
Definition ofEvents.h:119
Definition ofEvent.h:411
Definition ofEvents.h:176
A generic 3d object in space with transformation (position, rotation, scale).
Definition ofNode.h:14
A class representing a 2D rectangle.
Definition ofRectangle.h:87