Visualization Library 2.1.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
TrackballManipulator.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 TrackballManipulator_INCLUDE_ONCE
33 #define TrackballManipulator_INCLUDE_ONCE
34 
36 #include <vlGraphics/Camera.hpp>
37 #include <vlCore/Vector3.hpp>
38 
39 namespace vl
40 {
41  class Transform;
42  class Rendering;
43  class SceneManager;
44  class ActorCollection;
45 
46  //------------------------------------------------------------------------------
47  // TrackballManipulator
48  //------------------------------------------------------------------------------
62  {
64 
65  public:
66  typedef enum { NoMode, RotationMode, TranslationMode, ZoomMode } ETrackballMode;
67 
68  public:
70  TrackballManipulator(): mMode(NoMode),
71  mRotationButton(LeftButton), mTranslationButton(MiddleButton), mZoomButton(RightButton),
72  mRotationSpeed(1.0f), mTranslationSpeed(1.0f), mZoomSpeed(1.0f)
73  {
74  VL_DEBUG_SET_OBJECT_NAME()
75  }
76 
77  // --- UIEventListener ---
78 
79  virtual void mouseDownEvent(EMouseButton, int x, int y);
80 
81  virtual void mouseUpEvent(EMouseButton, int x, int y);
82 
83  virtual void mouseMoveEvent(int x, int y);
84 
85  virtual void enableEvent(bool enabled);
86 
87  virtual void initEvent() {}
88 
89  virtual void destroyEvent() {}
90 
91  virtual void updateEvent() {}
92 
94 
96 
97  virtual void mouseWheelEvent(int) {}
98 
99  virtual void keyPressEvent(unsigned short, EKey) {}
100 
101  virtual void keyReleaseEvent(unsigned short, EKey) {}
102 
103  virtual void resizeEvent(int, int) {}
104 
105  virtual void fileDroppedEvent(const std::vector<String>&) {}
106 
107  virtual void visibilityEvent(bool) {}
108 
109  // --- user methods ---
110 
112  void setCamera(Camera* camera) { mCamera = camera; }
113 
115  Camera* camera() { return mCamera.get(); }
116 
118  void setPivot(vec3 pivot) { mPivot = pivot; }
119 
121  vec3 pivot() const { return mPivot; }
122 
124  void setTransform(Transform* tr) { mTransform = tr; }
125 
127  Transform* transform() { return mTransform.get(); }
128 
130  int rotationButton() const { return mRotationButton; }
131 
133  void setRotationButton(int mouse_button) { mRotationButton = mouse_button; }
134 
136  int zoomButton() const { return mZoomButton; }
137 
139  void setZoomButton(int mouse_button) { mZoomButton = mouse_button; }
140 
142  int translationButton() const { return mTranslationButton; }
143 
145  void setTranslationButton(int mouse_button) { mTranslationButton = mouse_button; }
146 
148  float rotationSpeed() const { return mRotationSpeed; }
149 
151  void setRotationSpeed(float speed) { mRotationSpeed = speed; }
152 
154  float zoomSpeed() const { return mZoomSpeed; }
155 
157  void setZoomSpeed(float speed) { mZoomSpeed = speed; }
158 
160  float translationSpeed() const { return mTranslationSpeed; }
161 
163  void setTranslationSpeed(float speed) { mTranslationSpeed = speed; }
164 
166  void adjustView(const AABB& aabb, const vec3& dir, const vec3& up, real bias=1.0f);
167 
169  void adjustView(ActorCollection& actors, const vec3& dir, const vec3& up, real bias=1.0f);
170 
172  void adjustView(SceneManager* scene, const vec3& dir, const vec3& up, real bias=1.0f);
173 
175  void adjustView(Rendering* rendering, const vec3& dir, const vec3& up, real bias=1.0f);
176 
177  // --- Advanced methods ---
178 
179  mat4 trackballRotation(int x, int y);
180 
181  vec3 computeVector(int x, int y);
182 
184  ETrackballMode mode() const { return mMode; }
185 
186  protected:
194  ETrackballMode mMode;
200  float mZoomSpeed;
201  };
202 }
203 
204 #endif
vec3 pivot() const
The center point around which the camera will rotate.
int rotationButton() const
Mouse button used to rotate.
virtual void initEvent()
Event generated when the bound OpenGLContext bocomes initialized or when the event listener is bound ...
Implements a 4x4 matrix transform used to define the position and orientation of an Actor...
Definition: Transform.hpp:72
The UIEventListener class listens to the events emitted by an OpenGLContext.
void setRotationButton(int mouse_button)
Mouse button used to rotate.
virtual void fileDroppedEvent(const std::vector< String > &)
Event generated when one or more files are dropped on the bound OpenGLContext&#39;s area.
ETrackballMode mode() const
Returns the current trackball manipulator state.
This class lets you rotate a Camera or a Transform node using a virtual trackball.
Transform * transform()
If NULL the trackball will manipulate the camera transform, if non NULL the trackball will manipulate...
Represents an OpenGL context, possibly a widget or a pbuffer, which can also respond to keyboard...
virtual void visibilityEvent(bool)
Event generated when the bound OpenGLContext is shown or hidden.
virtual void destroyEvent()
Event generated right before the bound OpenGLContext is destroyed.
void setCamera(Camera *camera)
The camera through which the trackball manipulator is used.
void setRotationSpeed(float speed)
Rotation speed multiplicative factor (default = 1).
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
Visualization Library main namespace.
int translationButton() const
Mouse button used to translate the view.
void setTransform(Transform *tr)
If NULL the trackball will manipulate the camera transform, if non NULL the trackball will manipulate...
The AABB class implements an axis-aligned bounding box using vl::real precision.
Definition: AABB.hpp:44
void setTranslationButton(int mouse_button)
Mouse button used to translate the view.
virtual void resizeEvent(int, int)
Event generated when the bound OpenGLContext is resized.
The SceneManager class is the base class for all the scene managers.
EMouseButton
virtual void addedListenerEvent(OpenGLContext *)
Event generated whenever a listener is bound to an OpenGLContext context.
The Rendering class collects all the information to perform the rendering of a scene.
Definition: Rendering.hpp:68
float rotationSpeed() const
Rotation speed multiplicative factor (default = 1).
Defined as a simple subclass of Collection<Actor>, see Collection for more information.
Definition: Actor.hpp:479
float translationSpeed() const
Translation speed multiplicative factor (default = 1).
float zoomSpeed() const
Zoom speed multiplicative factor (default = 1).
virtual void updateEvent()
Event generated when the bound OpenGLContext does not have any other message to process and OpenGLCon...
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
Represents a virtual camera defining, among other things, the point of view from which scenes can be ...
Definition: Camera.hpp:49
void setPivot(vec3 pivot)
The center point around which the camera will rotate.
void setTranslationSpeed(float speed)
Translation speed multiplicative factor (default = 1).
virtual void keyReleaseEvent(unsigned short, EKey)
Event generated when a key is released.
virtual void mouseWheelEvent(int)
Event generated when the mouse wheel rotated.
int zoomButton() const
Mouse button used to zoom.
virtual void removedListenerEvent(OpenGLContext *)
Event generated whenever a listener is unbound from an OpenGLContext context.
void setZoomSpeed(float speed)
Zoom speed multiplicative factor (default = 1).
void setZoomButton(int mouse_button)
Mouse button used to zoom.
Camera * camera()
The camera through which the trackball manipulator is used.
virtual void keyPressEvent(unsigned short, EKey)
Event generated when a key is pressed.