Visualization Library 2.0.0-b3

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Public Types | Public Member Functions | Protected Attributes | List of all members
vl::TrackballManipulator Class Reference

This class lets you rotate a Camera or a Transform node using a virtual trackball. More...

#include <TrackballManipulator.hpp>

+ Inheritance diagram for vl::TrackballManipulator:

Public Types

enum  ETrackballMode { NoMode, RotationMode, TranslationMode, ZoomMode }
 

Public Member Functions

 TrackballManipulator ()
 Constructor. More...
 
virtual void mouseDownEvent (EMouseButton, int x, int y)
 Event generated when one of the mouse buttons is pressed. More...
 
virtual void mouseUpEvent (EMouseButton, int x, int y)
 Event generated when one of the mouse buttons is released. More...
 
virtual void mouseMoveEvent (int x, int y)
 Event generated when the mouse moves. More...
 
virtual void enableEvent (bool enabled)
 Event generated whenever setEnabled() is called. More...
 
virtual void initEvent ()
 Event generated when the bound OpenGLContext bocomes initialized or when the event listener is bound to an initialized OpenGLContext. More...
 
virtual void destroyEvent ()
 Event generated right before the bound OpenGLContext is destroyed. More...
 
virtual void updateEvent ()
 Event generated when the bound OpenGLContext does not have any other message to process and OpenGLContext::continuousUpdate() is set to true or somebody calls OpenGLContext::update(). More...
 
virtual void addedListenerEvent (OpenGLContext *)
 Event generated whenever a listener is bound to an OpenGLContext context. More...
 
virtual void removedListenerEvent (OpenGLContext *)
 Event generated whenever a listener is unbound from an OpenGLContext context. More...
 
virtual void mouseWheelEvent (int)
 Event generated when the mouse wheel rotated. More...
 
virtual void keyPressEvent (unsigned short, EKey)
 Event generated when a key is pressed. More...
 
virtual void keyReleaseEvent (unsigned short, EKey)
 Event generated when a key is released. More...
 
virtual void resizeEvent (int, int)
 Event generated when the bound OpenGLContext is resized. More...
 
virtual void fileDroppedEvent (const std::vector< String > &)
 Event generated when one or more files are dropped on the bound OpenGLContext's area. More...
 
virtual void visibilityEvent (bool)
 Event generated when the bound OpenGLContext is shown or hidden. More...
 
void setCamera (Camera *camera)
 The camera through which the trackball manipulator is used. More...
 
Cameracamera ()
 The camera through which the trackball manipulator is used. More...
 
void setPivot (vec3 pivot)
 The center point around which the camera will rotate. More...
 
vec3 pivot () const
 The center point around which the camera will rotate. More...
 
void setTransform (Transform *tr)
 If NULL the trackball will manipulate the camera transform, if non NULL the trackball will manipulate the specified transform. More...
 
Transformtransform ()
 If NULL the trackball will manipulate the camera transform, if non NULL the trackball will manipulate the specified transform. More...
 
int rotationButton () const
 Mouse button used to rotate. More...
 
void setRotationButton (int mouse_button)
 Mouse button used to rotate. More...
 
int zoomButton () const
 Mouse button used to zoom. More...
 
void setZoomButton (int mouse_button)
 Mouse button used to zoom. More...
 
int translationButton () const
 Mouse button used to translate the view. More...
 
void setTranslationButton (int mouse_button)
 Mouse button used to translate the view. More...
 
float rotationSpeed () const
 Rotation speed multiplicative factor (default = 1). More...
 
void setRotationSpeed (float speed)
 Rotation speed multiplicative factor (default = 1). More...
 
float zoomSpeed () const
 Zoom speed multiplicative factor (default = 1). More...
 
void setZoomSpeed (float speed)
 Zoom speed multiplicative factor (default = 1). More...
 
float translationSpeed () const
 Translation speed multiplicative factor (default = 1). More...
 
void setTranslationSpeed (float speed)
 Translation speed multiplicative factor (default = 1). More...
 
void adjustView (const AABB &aabb, const vec3 &dir, const vec3 &up, real bias=1.0f)
 Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB. See also Camera::adjustView(). More...
 
void adjustView (ActorCollection &actors, const vec3 &dir, const vec3 &up, real bias=1.0f)
 Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB containing the Actors. See also Camera::adjustView(). More...
 
void adjustView (SceneManager *scene, const vec3 &dir, const vec3 &up, real bias=1.0f)
 Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB containing the given scene manager. See also Camera::adjustView(). More...
 
void adjustView (Rendering *rendering, const vec3 &dir, const vec3 &up, real bias=1.0f)
 Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB containing all the scene managers part of the given rendering. See also Camera::adjustView(). More...
 
mat4 trackballRotation (int x, int y)
 
vec3 computeVector (int x, int y)
 
ETrackballMode mode () const
 Returns the current trackball manipulator state. More...
 
- Public Member Functions inherited from vl::UIEventListener
 UIEventListener ()
 Constructor. More...
 
virtual void setEnabled (bool enabled)
 Enables or disables a UIEventListener. More...
 
bool isEnabled () const
 Returns whether the UIEventListener is currently enabled or not. More...
 
OpenGLContextopenglContext ()
 Returns the OpenGLContext to which this UIEventListener is bound or NULL if no context is bound. More...
 
const OpenGLContextopenglContext () const
 Returns the OpenGLContext to which this UIEventListener is bound or NULL if no context is bound. More...
 
- Public Member Functions inherited from vl::Object
 Object ()
 Constructor. More...
 
 Object (const Object &other)
 Copy constructor: copies the name, ref count mutex and user data. More...
 
Objectoperator= (const Object &other)
 Copy operator: copies the object's name, ref count mutex and user data. More...
 
const std::string & objectName () const
 The name of the object, by default set to the object's class name. More...
 
void setObjectName (const char *name)
 The name of the object, by default set to the object's class name in debug builds. More...
 
void setObjectName (const std::string &name)
 The name of the object, by default set to the object's class name in debug builds. More...
 
void setRefCountMutex (IMutex *mutex)
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
IMutexrefCountMutex ()
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
const IMutexrefCountMutex () const
 The mutex used to protect the reference counting of an Object across multiple threads. More...
 
int referenceCount () const
 Returns the number of references of an object. More...
 
void incReference () const
 Increments the reference count of an object. More...
 
void decReference ()
 Decrements the reference count of an object and deletes it if both automaticDelete() is true the count reaches 0. More...
 
void setAutomaticDelete (bool autodel_on)
 If set to true the Object is deleted when its reference count reaches 0. More...
 
bool automaticDelete () const
 If set to true the Object is deleted when its reference count reaches 0. More...
 
template<class T >
T * as ()
 Casts an Object to the specified class. More...
 
template<class T >
const T * as () const
 Casts an Object to the specified class. More...
 

Protected Attributes

ref< CameramCamera
 
ivec2 mMouseStart
 
mat4 mStartMatrix
 
vec3 mPivot
 
vec3 mStartCameraPos
 
vec3 mStartPivot
 
ref< TransformmTransform
 
ETrackballMode mMode
 
int mRotationButton
 
int mTranslationButton
 
int mZoomButton
 
float mRotationSpeed
 
float mTranslationSpeed
 
float mZoomSpeed
 
- Protected Attributes inherited from vl::Object
std::string mObjectName
 
IMutexmRefCountMutex
 
int mReferenceCount
 
bool mAutomaticDelete
 

Additional Inherited Members

- Protected Member Functions inherited from vl::Object
virtual ~Object ()
 

Detailed Description

This class lets you rotate a Camera or a Transform node using a virtual trackball.

If you set a Transform node to manipulate, using the function setTransform(), the trackball will manipulate the given Transform (rotation only, panning and zooming will always affect the bound Camera). If no Transform is specified or a NULL one is passed to the function setTransform() then the trackball will manipulate the current camera.

Note
In any case, before using a TrackballManipulator you have to specify a Camera object using the function setCamera().
The Transform is expected to contain only rotation and translation information. Other transformations like shearing, scaling, projection, and so on can produce unspecified results.
See also
GhostCameraManipulator

Definition at line 61 of file TrackballManipulator.hpp.

Member Enumeration Documentation

◆ ETrackballMode

Enumerator
NoMode 
RotationMode 
TranslationMode 
ZoomMode 

Definition at line 66 of file TrackballManipulator.hpp.

Constructor & Destructor Documentation

◆ TrackballManipulator()

vl::TrackballManipulator::TrackballManipulator ( )
inline

Constructor.

Definition at line 70 of file TrackballManipulator.hpp.

Member Function Documentation

◆ addedListenerEvent()

virtual void vl::TrackballManipulator::addedListenerEvent ( OpenGLContext )
inlinevirtual

Event generated whenever a listener is bound to an OpenGLContext context.

Implements vl::UIEventListener.

Definition at line 93 of file TrackballManipulator.hpp.

◆ adjustView() [1/4]

void TrackballManipulator::adjustView ( const AABB aabb,
const vec3 dir,
const vec3 up,
real  bias = 1.0f 
)

Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB. See also Camera::adjustView().

Definition at line 217 of file TrackballManipulator.cpp.

References vl::Camera::adjustView(), camera(), vl::AABB::center(), vl::AABB::isNull(), setPivot(), and VL_CHECK.

Referenced by adjustView().

◆ adjustView() [2/4]

void TrackballManipulator::adjustView ( ActorCollection actors,
const vec3 dir,
const vec3 up,
real  bias = 1.0f 
)

Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB containing the Actors. See also Camera::adjustView().

Definition at line 226 of file TrackballManipulator.cpp.

References adjustView(), vl::Collection< T >::at(), vl::Actor::boundingBox(), vl::Actor::computeBounds(), vl::Transform::computeWorldMatrix(), vl::Collection< T >::empty(), vl::Actor::lod(), vl::Renderable::setBoundsDirty(), vl::Collection< T >::size(), and vl::Actor::transform().

◆ adjustView() [3/4]

void TrackballManipulator::adjustView ( SceneManager scene,
const vec3 dir,
const vec3 up,
real  bias = 1.0f 
)

Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB containing the given scene manager. See also Camera::adjustView().

Definition at line 244 of file TrackballManipulator.cpp.

References adjustView(), vl::SceneManager::extractVisibleActors(), and NULL.

◆ adjustView() [4/4]

void TrackballManipulator::adjustView ( Rendering rendering,
const vec3 dir,
const vec3 up,
real  bias = 1.0f 
)

Adjusts the camera position in order to nicely see the scene. It also position the rotation pivot to the center of the AABB containing all the scene managers part of the given rendering. See also Camera::adjustView().

Definition at line 251 of file TrackballManipulator.cpp.

References adjustView(), NULL, and vl::Rendering::sceneManagers().

◆ camera()

Camera* vl::TrackballManipulator::camera ( )
inline

The camera through which the trackball manipulator is used.

Definition at line 115 of file TrackballManipulator.hpp.

Referenced by adjustView(), computeVector(), mouseDownEvent(), mouseMoveEvent(), mouseUpEvent(), and trackballRotation().

◆ computeVector()

vec3 TrackballManipulator::computeVector ( int  x,
int  y 
)

◆ destroyEvent()

virtual void vl::TrackballManipulator::destroyEvent ( )
inlinevirtual

Event generated right before the bound OpenGLContext is destroyed.

Implements vl::UIEventListener.

Definition at line 89 of file TrackballManipulator.hpp.

◆ enableEvent()

void TrackballManipulator::enableEvent ( bool  enabled)
virtual

◆ fileDroppedEvent()

virtual void vl::TrackballManipulator::fileDroppedEvent ( const std::vector< String > &  files)
inlinevirtual

Event generated when one or more files are dropped on the bound OpenGLContext's area.

Implements vl::UIEventListener.

Definition at line 105 of file TrackballManipulator.hpp.

◆ initEvent()

virtual void vl::TrackballManipulator::initEvent ( )
inlinevirtual

Event generated when the bound OpenGLContext bocomes initialized or when the event listener is bound to an initialized OpenGLContext.

Implements vl::UIEventListener.

Definition at line 87 of file TrackballManipulator.hpp.

◆ keyPressEvent()

virtual void vl::TrackballManipulator::keyPressEvent ( unsigned  unicode_ch,
EKey  key 
)
inlinevirtual

Event generated when a key is pressed.

Implements vl::UIEventListener.

Definition at line 99 of file TrackballManipulator.hpp.

◆ keyReleaseEvent()

virtual void vl::TrackballManipulator::keyReleaseEvent ( unsigned  unicode_ch,
EKey  key 
)
inlinevirtual

Event generated when a key is released.

Implements vl::UIEventListener.

Definition at line 101 of file TrackballManipulator.hpp.

◆ mode()

ETrackballMode vl::TrackballManipulator::mode ( ) const
inline

Returns the current trackball manipulator state.

Definition at line 184 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), mouseMoveEvent(), and mouseUpEvent().

◆ mouseDownEvent()

void TrackballManipulator::mouseDownEvent ( EMouseButton  button,
int  x,
int  y 
)
virtual

◆ mouseMoveEvent()

void TrackballManipulator::mouseMoveEvent ( int  x,
int  y 
)
virtual

◆ mouseUpEvent()

void TrackballManipulator::mouseUpEvent ( EMouseButton  button,
int  x,
int  y 
)
virtual

Event generated when one of the mouse buttons is released.

Implements vl::UIEventListener.

Definition at line 88 of file TrackballManipulator.cpp.

References camera(), mMode, mode(), NoMode, NULL, rotationButton(), RotationMode, translationButton(), TranslationMode, zoomButton(), and ZoomMode.

◆ mouseWheelEvent()

virtual void vl::TrackballManipulator::mouseWheelEvent ( int  n)
inlinevirtual

Event generated when the mouse wheel rotated.

Implements vl::UIEventListener.

Definition at line 97 of file TrackballManipulator.hpp.

◆ pivot()

vec3 vl::TrackballManipulator::pivot ( ) const
inline

The center point around which the camera will rotate.

Definition at line 121 of file TrackballManipulator.hpp.

◆ removedListenerEvent()

virtual void vl::TrackballManipulator::removedListenerEvent ( OpenGLContext )
inlinevirtual

Event generated whenever a listener is unbound from an OpenGLContext context.

Implements vl::UIEventListener.

Definition at line 95 of file TrackballManipulator.hpp.

◆ resizeEvent()

virtual void vl::TrackballManipulator::resizeEvent ( int  x,
int  y 
)
inlinevirtual

Event generated when the bound OpenGLContext is resized.

Implements vl::UIEventListener.

Definition at line 103 of file TrackballManipulator.hpp.

◆ rotationButton()

int vl::TrackballManipulator::rotationButton ( ) const
inline

Mouse button used to rotate.

Definition at line 130 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseUpEvent().

◆ rotationSpeed()

float vl::TrackballManipulator::rotationSpeed ( ) const
inline

Rotation speed multiplicative factor (default = 1).

Definition at line 148 of file TrackballManipulator.hpp.

Referenced by trackballRotation().

◆ setCamera()

void vl::TrackballManipulator::setCamera ( Camera camera)
inline

The camera through which the trackball manipulator is used.

Definition at line 112 of file TrackballManipulator.hpp.

◆ setPivot()

void vl::TrackballManipulator::setPivot ( vec3  pivot)
inline

The center point around which the camera will rotate.

Definition at line 118 of file TrackballManipulator.hpp.

Referenced by adjustView().

◆ setRotationButton()

void vl::TrackballManipulator::setRotationButton ( int  mouse_button)
inline

Mouse button used to rotate.

Definition at line 133 of file TrackballManipulator.hpp.

◆ setRotationSpeed()

void vl::TrackballManipulator::setRotationSpeed ( float  speed)
inline

Rotation speed multiplicative factor (default = 1).

Definition at line 151 of file TrackballManipulator.hpp.

◆ setTransform()

void vl::TrackballManipulator::setTransform ( Transform tr)
inline

If NULL the trackball will manipulate the camera transform, if non NULL the trackball will manipulate the specified transform.

Definition at line 124 of file TrackballManipulator.hpp.

◆ setTranslationButton()

void vl::TrackballManipulator::setTranslationButton ( int  mouse_button)
inline

Mouse button used to translate the view.

Definition at line 145 of file TrackballManipulator.hpp.

◆ setTranslationSpeed()

void vl::TrackballManipulator::setTranslationSpeed ( float  speed)
inline

Translation speed multiplicative factor (default = 1).

Definition at line 163 of file TrackballManipulator.hpp.

◆ setZoomButton()

void vl::TrackballManipulator::setZoomButton ( int  mouse_button)
inline

Mouse button used to zoom.

Definition at line 139 of file TrackballManipulator.hpp.

◆ setZoomSpeed()

void vl::TrackballManipulator::setZoomSpeed ( float  speed)
inline

Zoom speed multiplicative factor (default = 1).

Definition at line 157 of file TrackballManipulator.hpp.

◆ trackballRotation()

mat4 TrackballManipulator::trackballRotation ( int  x,
int  y 
)

◆ transform()

Transform* vl::TrackballManipulator::transform ( )
inline

If NULL the trackball will manipulate the camera transform, if non NULL the trackball will manipulate the specified transform.

Definition at line 127 of file TrackballManipulator.hpp.

◆ translationButton()

int vl::TrackballManipulator::translationButton ( ) const
inline

Mouse button used to translate the view.

Definition at line 142 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseUpEvent().

◆ translationSpeed()

float vl::TrackballManipulator::translationSpeed ( ) const
inline

Translation speed multiplicative factor (default = 1).

Definition at line 160 of file TrackballManipulator.hpp.

Referenced by mouseMoveEvent().

◆ updateEvent()

virtual void vl::TrackballManipulator::updateEvent ( )
inlinevirtual

Event generated when the bound OpenGLContext does not have any other message to process and OpenGLContext::continuousUpdate() is set to true or somebody calls OpenGLContext::update().

Implements vl::UIEventListener.

Definition at line 91 of file TrackballManipulator.hpp.

◆ visibilityEvent()

virtual void vl::TrackballManipulator::visibilityEvent ( bool  visible)
inlinevirtual

Event generated when the bound OpenGLContext is shown or hidden.

Implements vl::UIEventListener.

Definition at line 107 of file TrackballManipulator.hpp.

◆ zoomButton()

int vl::TrackballManipulator::zoomButton ( ) const
inline

Mouse button used to zoom.

Definition at line 136 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseUpEvent().

◆ zoomSpeed()

float vl::TrackballManipulator::zoomSpeed ( ) const
inline

Zoom speed multiplicative factor (default = 1).

Definition at line 154 of file TrackballManipulator.hpp.

Referenced by mouseMoveEvent().

Member Data Documentation

◆ mCamera

ref<Camera> vl::TrackballManipulator::mCamera
protected

Definition at line 187 of file TrackballManipulator.hpp.

◆ mMode

ETrackballMode vl::TrackballManipulator::mMode
protected

Definition at line 194 of file TrackballManipulator.hpp.

Referenced by enableEvent(), mouseDownEvent(), and mouseUpEvent().

◆ mMouseStart

ivec2 vl::TrackballManipulator::mMouseStart
protected

Definition at line 188 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), mouseMoveEvent(), and trackballRotation().

◆ mPivot

vec3 vl::TrackballManipulator::mPivot
protected

Definition at line 190 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseMoveEvent().

◆ mRotationButton

int vl::TrackballManipulator::mRotationButton
protected

Definition at line 195 of file TrackballManipulator.hpp.

◆ mRotationSpeed

float vl::TrackballManipulator::mRotationSpeed
protected

Definition at line 198 of file TrackballManipulator.hpp.

◆ mStartCameraPos

vec3 vl::TrackballManipulator::mStartCameraPos
protected

Definition at line 191 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseMoveEvent().

◆ mStartMatrix

mat4 vl::TrackballManipulator::mStartMatrix
protected

Definition at line 189 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseMoveEvent().

◆ mStartPivot

vec3 vl::TrackballManipulator::mStartPivot
protected

Definition at line 192 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseMoveEvent().

◆ mTransform

ref<Transform> vl::TrackballManipulator::mTransform
protected

Definition at line 193 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), mouseMoveEvent(), and trackballRotation().

◆ mTranslationButton

int vl::TrackballManipulator::mTranslationButton
protected

Definition at line 196 of file TrackballManipulator.hpp.

◆ mTranslationSpeed

float vl::TrackballManipulator::mTranslationSpeed
protected

Definition at line 199 of file TrackballManipulator.hpp.

◆ mZoomButton

int vl::TrackballManipulator::mZoomButton
protected

Definition at line 197 of file TrackballManipulator.hpp.

◆ mZoomSpeed

float vl::TrackballManipulator::mZoomSpeed
protected

Definition at line 200 of file TrackballManipulator.hpp.


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