Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
GhostCameraManipulator.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef GhostCameraManipulator_INCLUDE_ONCE
33 #define GhostCameraManipulator_INCLUDE_ONCE
34 
36 
37 namespace vl
38 {
39  class Camera;
40  //------------------------------------------------------------------------------
41  // GhostCameraManipulator
42  //------------------------------------------------------------------------------
56  {
58 
59  public:
62 
63  // --- UIEventListener ---
64 
65  virtual void mouseMoveEvent(int x, int y);
66 
67  void enableEvent(bool enabled);
68 
69  virtual void updateEvent();
70 
71  virtual void initEvent() {}
72 
73  virtual void destroyEvent() {}
74 
76 
78 
79  virtual void mouseUpEvent(EMouseButton, int, int) {}
80 
81  virtual void mouseDownEvent(EMouseButton, int, int) {}
82 
83  virtual void mouseWheelEvent(int) {}
84 
85  virtual void keyPressEvent(unsigned short, EKey) {}
86 
87  virtual void keyReleaseEvent(unsigned short, EKey) {}
88 
89  virtual void resizeEvent(int, int) {}
90 
91  virtual void fileDroppedEvent(const std::vector<String>&) {}
92 
93  virtual void visibilityEvent(bool) {}
94 
95  // --- --- ---
96 
98  void setCamera(Camera* camera);
99 
101  Camera* camera();
102 
104  const Camera* camera() const;
105 
107  void setKeysForward(EKey key, EKey modifier = Key_None) { mKeysForward[0] = key; mKeysForward[1] = modifier; };
108 
110  void setKeysBackward(EKey key, EKey modifier = Key_None) { mKeysBackward[0] = key; mKeysBackward[1] = modifier; };
111 
113  void setKeysLeft(EKey key, EKey modifier = Key_None) { mKeysLeft[0] = key; mKeysLeft[1] = modifier; };
114 
116  void setKeysRight(EKey key, EKey modifier = Key_None) { mKeysRight[0] = key; mKeysRight[1] = modifier; };
117 
119  void setKeysUp(EKey key, EKey modifier = Key_None) { mKeysUp[0] = key; mKeysUp[1] = modifier; };
120 
122  void setKeysDown(EKey key, EKey modifier = Key_None) { mKeysDown[0] = key; mKeysDown[1] = modifier; };
123 
125  void setRotationSpeed(real speed) { mRotationSpeed = speed; }
126 
128  real rotationSpeed() const { return mRotationSpeed; }
129 
131  void setMovementSpeed(real speed) { mMovementSpeed = speed; }
132 
134  real movementSpeed() const { return mMovementSpeed; }
135 
136  protected:
137  void setPosition(vec3 position) { mPosition = position; }
138 
139  const vec3& position() const { return mPosition; }
140 
141  void setXDegrees(real degree) { mXDegrees = degree; }
142 
143  real xDegrees() { return mXDegrees; }
144 
145  void setYDegrees(real degree) { mYDegrees = degree; }
146 
147  real yDegrees() { return mYDegrees; }
148 
149  protected:
152  real mLastTime;
155  real mXDegrees;
156  real mYDegrees;
157  EKey mKeysForward[2];
158  EKey mKeysBackward[2];
159  EKey mKeysUp[2];
160  EKey mKeysDown[2];
161  EKey mKeysLeft[2];
162  EKey mKeysRight[2];
163  };
164 }
165 
166 #endif
void setKeysBackward(EKey key, EKey modifier=Key_None)
Key bindings to move backward (default = Key_S).
void setKeysUp(EKey key, EKey modifier=Key_None)
Key bindings to move up (default = Key_W + Key_Shift).
The UIEventListener class listens to the events emitted by an OpenGLContext.
virtual void removedListenerEvent(OpenGLContext *)
Event generated whenever a listener is unbound from an OpenGLContext context.
virtual void mouseDownEvent(EMouseButton, int, int)
Event generated when one of the mouse buttons is pressed.
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
void setKeysLeft(EKey key, EKey modifier=Key_None)
Key bindings to move left (default = Key_A).
void setKeysDown(EKey key, EKey modifier=Key_None)
Key bindings to move down (default = Key_S + Key_Shift).
void setMovementSpeed(real speed)
The camera translation speed (default = 50).
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
virtual void destroyEvent()
Event generated right before the bound OpenGLContext is destroyed.
real movementSpeed() const
The camera translation speed (default = 50).
Visualization Library main namespace.
virtual void addedListenerEvent(OpenGLContext *)
Event generated whenever a listener is bound to an OpenGLContext context.
virtual void fileDroppedEvent(const std::vector< String > &)
Event generated when one or more files are dropped on the bound OpenGLContext&#39;s area.
Simple class representing quantities in degrees, converts automatically to vl::radian and real...
Definition: std_types.hpp:92
virtual void initEvent()
Event generated when the bound OpenGLContext bocomes initialized or when the event listener is bound ...
virtual void visibilityEvent(bool)
Event generated when the bound OpenGLContext is shown or hidden.
EMouseButton
virtual void keyReleaseEvent(unsigned short, EKey)
Event generated when a key is released.
The GhostCameraManipulator class is an UIEventListener that controls the position and orientation of ...
virtual void resizeEvent(int, int)
Event generated when the bound OpenGLContext is resized.
virtual void mouseUpEvent(EMouseButton, int, int)
Event generated when one of the mouse buttons is released.
void setKeysForward(EKey key, EKey modifier=Key_None)
Key bindings to move forward (default = Key_W).
real rotationSpeed() const
The camera rotation speed (default = 0.5).
void setKeysRight(EKey key, EKey modifier=Key_None)
Key bindings to move right (default = Key_D).
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
virtual void mouseWheelEvent(int)
Event generated when the mouse wheel rotated.
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
Definition: Camera.hpp:50
void setRotationSpeed(real speed)
The camera rotation speed (default = 0.5).
virtual void keyPressEvent(unsigned short, EKey)
Event generated when a key is pressed.