# Visualization Library

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

[Home] [Tutorials] [All Classes] [Grouped Classes]

Public Types | Public Member Functions | Protected Attributes

# 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:

List of all members.

## Public Types

enum | ETrackballMode { NoMode, RotationMode, TranslationMode, ZoomMode }

## Public Member Functions

virtual const char * | className ()
| Returns the name of the class.
| TrackballManipulator ()
| Constructor.
virtual void | mouseDownEvent (EMouseButton, int x, int y)
| Event generated when one of the mouse buttons is pressed.
virtual void | mouseUpEvent (EMouseButton, int x, int y)
| Event generated when one of the mouse buttons is released.
virtual void | mouseMoveEvent (int x, int y)
| Event generated when the mouse moves.
virtual void | enableEvent (bool enabled)
| Event generated whenever setEnabled() is called.
virtual void | initEvent ()
| Event generated when the bound OpenGLContext bocomes initialized or when the event listener is bound to an initialized OpenGLContext.
virtual void | destroyEvent ()
| Event generated right before the bound OpenGLContext is destroyed.
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().
virtual void | addedListenerEvent (OpenGLContext *)
| Event generated whenever a listener is bound to an OpenGLContext context.
virtual void | removedListenerEvent (OpenGLContext *)
| Event generated whenever a listener is unbound from an OpenGLContext context.
virtual void | mouseWheelEvent (int)
| Event generated when the mouse wheel rotated.
virtual void | keyPressEvent (unsigned short, EKey)
| Event generated when a key is pressed.
virtual void | keyReleaseEvent (unsigned short, EKey)
| Event generated when a key is released.
virtual void | resizeEvent (int, int)
| Event generated when the bound OpenGLContext is resized.
virtual void | fileDroppedEvent (const std::vector< String > &)
| Event generated when one or more files are dropped on the bound OpenGLContext's area.
virtual void | visibilityEvent (bool)
| Event generated when the bound OpenGLContext is shown or hidden.
void | setCamera (Camera *camera)
| The camera through which the trackball manipulator is used.
Camera * | camera ()
| The camera through which the trackball manipulator is used.
void | setPivot (vec3 pivot)
| The center point around which the camera will rotate.
vec3 | pivot () const
| The center point around which the camera will rotate.
void | setTransform (Transform *tr)
| If NULL the trackball will manipulate the camera transform, if non NULL the trackball will manipulate the specified transform.
Transform * | transform ()
| If NULL the trackball will manipulate the camera transform, if non NULL the trackball will manipulate the specified transform.
int | rotationButton () const
| Mouse button used to rotate.
void | setRotationButton (int mouse_button)
| Mouse button used to rotate.
int | zoomButton () const
| Mouse button used to zoom.
void | setZoomButton (int mouse_button)
| Mouse button used to zoom.
int | translationButton () const
| Mouse button used to translate the view.
void | setTranslationButton (int mouse_button)
| Mouse button used to translate the view.
float | rotationSpeed () const
| Rotation speed multiplicative factor (default = 1).
void | setRotationSpeed (float speed)
| Rotation speed multiplicative factor (default = 1).
float | zoomSpeed () const
| Zoom speed multiplicative factor (default = 1).
void | setZoomSpeed (float speed)
| Zoom speed multiplicative factor (default = 1).
float | translationSpeed () const
| Translation speed multiplicative factor (default = 1).
void | setTranslationSpeed (float speed)
| Translation speed multiplicative factor (default = 1).
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().
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 Actor[s]. See also Camera::adjustView().
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().
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().
mat4 | trackballRotation (int x, int y)
vec3 | computeVector (int x, int y)
ETrackballMode | mode () const
| Returns the current trackball manipulator state.

## Protected Attributes

ref< Camera > | mCamera
ivec2 | mMouseStart
mat4 | mStartMatrix
vec3 | mPivot
vec3 | mStartCameraPos
vec3 | mStartPivot
ref< Transform > | mTransform
ETrackballMode | mMode
int | mRotationButton
int | mTranslationButton
int | mZoomButton
float | mRotationSpeed
float | mTranslationSpeed
float | mZoomSpeed

## 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

enum vl::TrackballManipulator::ETrackballMode

Enumerator:

  NoMode |
  RotationMode |
  TranslationMode |
  ZoomMode |

Definition at line 64 of file TrackballManipulator.hpp.

## Constructor & Destructor Documentation

vl::TrackballManipulator::TrackballManipulator | ( | ) | `[inline]`

Constructor.

Definition at line 70 of file TrackballManipulator.hpp.

References VL_DEBUG_SET_OBJECT_NAME.

## Member Function Documentation

virtual const char* vl::TrackballManipulator::className | ( | ) | `[inline, virtual]`

Returns the name of the class.

Reimplemented from vl::UIEventListener.

Definition at line 67 of file TrackballManipulator.hpp.

void TrackballManipulator::mouseDownEvent | ( | EMouseButton | button,
|  | int | x,
|  | int | y
| ) |  | `[virtual]`

Event generated when one of the mouse buttons is pressed.

Implements vl::UIEventListener.

Definition at line 41 of file TrackballManipulator.cpp.

References camera(), vl::Matrix4< T_Scalar >::getT(), vl::Viewport::height(), vl::RenderTarget::height(), vl::Camera::inverseViewMatrix(), mMode, mMouseStart, mode(), mPivot, mStartCameraPos, mStartMatrix, mStartPivot, mTransform, NoMode, vl::UIEventListener::openglContext(), vl::OpenGLContext::renderTarget(), rotationButton(), RotationMode, translationButton(), TranslationMode, vl::Camera::viewport(), VL_CHECK, vl::Viewport::width(), vl::Vector2< T_Scalar >::x(), vl::Viewport::x(), vl::Vector2< T_Scalar >::y(), vl::Viewport::y(), zoomButton(), and ZoomMode.

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, rotationButton(), RotationMode, translationButton(), TranslationMode, zoomButton(), and ZoomMode.

void TrackballManipulator::mouseMoveEvent | ( | int | x,
|  | int | y
| ) |  | `[virtual]`

Event generated when the mouse moves.

Implements vl::UIEventListener.

Definition at line 108 of file TrackballManipulator.cpp.

References camera(), vl::distance(), vl::Matrix4< GLfloat >::getTranslation(), vl::Matrix4< T_Scalar >::getX(), vl::Matrix4< T_Scalar >::getY(), vl::Matrix4< T_Scalar >::getZ(), vl::Viewport::height(), vl::RenderTarget::height(), vl::Camera::inverseViewMatrix(), vl::length(), mMouseStart, mode(), mPivot, mStartCameraPos, mStartMatrix, mStartPivot, mTransform, NoMode, vl::UIEventListener::openglContext(), vl::OpenGLContext::renderTarget(), RotationMode, vl::Camera::setInverseViewMatrix(), vl::Matrix4< T_Scalar >::setT(), trackballRotation(), TranslationMode, translationSpeed(), vl::OpenGLContext::update(), vl::Camera::viewport(), VL_CHECK, vl::Vector2< T_Scalar >::x(), vl::Viewport::x(), vl::Vector2< T_Scalar >::y(), vl::Viewport::y(), ZoomMode, and zoomSpeed().

void TrackballManipulator::enableEvent | ( | bool | enabled ) | `[virtual]`

Event generated whenever setEnabled() is called.

Implements vl::UIEventListener.

Definition at line 253 of file TrackballManipulator.cpp.

References mMode, NoMode, vl::UIEventListener::openglContext(), vl::OpenGLContext::setContinuousUpdate(), and vl::OpenGLContext::setMouseVisible().

virtual void vl::TrackballManipulator::initEvent | ( | ) | `[inline, virtual]`

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.

virtual void vl::TrackballManipulator::destroyEvent | ( | ) | `[inline, virtual]`

Event generated right before the bound OpenGLContext is destroyed.

Implements vl::UIEventListener.

Definition at line 89 of file TrackballManipulator.hpp.

virtual void vl::TrackballManipulator::updateEvent | ( | ) | `[inline, virtual]`

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.

virtual void vl::TrackballManipulator::addedListenerEvent | ( | OpenGLContext * | ) | `[inline, virtual]`

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

Implements vl::UIEventListener.

Definition at line 93 of file TrackballManipulator.hpp.

virtual void vl::TrackballManipulator::removedListenerEvent | ( | OpenGLContext * | ) | `[inline, virtual]`

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

Implements vl::UIEventListener.

Definition at line 95 of file TrackballManipulator.hpp.

virtual void vl::TrackballManipulator::mouseWheelEvent | ( | int | n ) | `[inline, virtual]`

Event generated when the mouse wheel rotated.

Implements vl::UIEventListener.

Definition at line 97 of file TrackballManipulator.hpp.

virtual void vl::TrackballManipulator::keyPressEvent | ( | unsigned | unicode_ch,
|  | EKey | key
| ) |  | `[inline, virtual]`

Event generated when a key is pressed.

Implements vl::UIEventListener.

Definition at line 99 of file TrackballManipulator.hpp.

virtual void vl::TrackballManipulator::keyReleaseEvent | ( | unsigned | unicode_ch,
|  | EKey | key
| ) |  | `[inline, virtual]`

Event generated when a key is released.

Implements vl::UIEventListener.

Definition at line 101 of file TrackballManipulator.hpp.

virtual void vl::TrackballManipulator::resizeEvent | ( | int | x,
|  | int | y
| ) |  | `[inline, virtual]`

Event generated when the bound OpenGLContext is resized.

Implements vl::UIEventListener.

Definition at line 103 of file TrackballManipulator.hpp.

virtual void vl::TrackballManipulator::fileDroppedEvent | ( | const std::vector< String > & | files ) | `[inline, virtual]`

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.

virtual void vl::TrackballManipulator::visibilityEvent | ( | bool | visible ) | `[inline, virtual]`

Event generated when the bound OpenGLContext is shown or hidden.

Implements vl::UIEventListener.

Definition at line 107 of file TrackballManipulator.hpp.

void vl::TrackballManipulator::setCamera | ( | Camera * | camera ) | `[inline]`

The camera through which the trackball manipulator is used.

Definition at line 112 of file TrackballManipulator.hpp.

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().

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().

vec3 vl::TrackballManipulator::pivot | ( | ) | const`[inline]`

The center point around which the camera will rotate.

Definition at line 121 of file TrackballManipulator.hpp.

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.

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.

int vl::TrackballManipulator::rotationButton | ( | ) | const`[inline]`

Mouse button used to rotate.

Definition at line 130 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseUpEvent().

void vl::TrackballManipulator::setRotationButton | ( | int | mouse_button ) | `[inline]`

Mouse button used to rotate.

Definition at line 133 of file TrackballManipulator.hpp.

int vl::TrackballManipulator::zoomButton | ( | ) | const`[inline]`

Mouse button used to zoom.

Definition at line 136 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseUpEvent().

void vl::TrackballManipulator::setZoomButton | ( | int | mouse_button ) | `[inline]`

Mouse button used to zoom.

Definition at line 139 of file TrackballManipulator.hpp.

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().

void vl::TrackballManipulator::setTranslationButton | ( | int | mouse_button ) | `[inline]`

Mouse button used to translate the view.

Definition at line 145 of file TrackballManipulator.hpp.

float vl::TrackballManipulator::rotationSpeed | ( | ) | const`[inline]`

Rotation speed multiplicative factor (default = 1).

Definition at line 148 of file TrackballManipulator.hpp.

Referenced by trackballRotation().

void vl::TrackballManipulator::setRotationSpeed | ( | float | speed ) | `[inline]`

Rotation speed multiplicative factor (default = 1).

Definition at line 151 of file TrackballManipulator.hpp.

float vl::TrackballManipulator::zoomSpeed | ( | ) | const`[inline]`

Zoom speed multiplicative factor (default = 1).

Definition at line 154 of file TrackballManipulator.hpp.

Referenced by mouseMoveEvent().

void vl::TrackballManipulator::setZoomSpeed | ( | float | speed ) | `[inline]`

Zoom speed multiplicative factor (default = 1).

Definition at line 157 of file TrackballManipulator.hpp.

float vl::TrackballManipulator::translationSpeed | ( | ) | const`[inline]`

Translation speed multiplicative factor (default = 1).

Definition at line 160 of file TrackballManipulator.hpp.

Referenced by mouseMoveEvent().

void vl::TrackballManipulator::setTranslationSpeed | ( | float | speed ) | `[inline]`

Translation speed multiplicative factor (default = 1).

Definition at line 163 of file TrackballManipulator.hpp.

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(), setPivot(), and VL_CHECK.

Referenced by adjustView().

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 Actor[s]. See also Camera::adjustView().

Definition at line 225 of file TrackballManipulator.cpp.

References adjustView(), vl::Collection< T >::at(), vl::Actor::boundingBox(), vl::Actor::computeBounds(), vl::ITransform::computeWorldMatrix(), vl::Collection< T >::size(), and vl::Actor::transform().

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 238 of file TrackballManipulator.cpp.

References adjustView(), and vl::SceneManager::extractActors().

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 245 of file TrackballManipulator.cpp.

References adjustView(), vl::Collection< T >::at(), vl::SceneManager::extractActors(), vl::Rendering::sceneManagers(), and vl::Collection< T >::size().

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

Definition at line 170 of file TrackballManipulator.cpp.

References vl::acos(), camera(), vl::clamp(), computeVector(), vl::cross(), vl::dot(), vl::dRAD_TO_DEG, vl::Matrix4< T_Scalar >::get3x3(), vl::Matrix4< GLfloat >::getRotation(), vl::Camera::inverseViewMatrix(), mMouseStart, mTransform, vl::Vector3< T_Scalar >::normalize(), rotationSpeed(), VL_CHECK, vl::Vector2< T_Scalar >::x(), and vl::Vector2< T_Scalar >::y().

Referenced by mouseMoveEvent().

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

Definition at line 193 of file TrackballManipulator.cpp.

References camera(), vl::Viewport::height(), vl::Vector3< T_Scalar >::normalize(), vl::sqrt(), vl::Camera::viewport(), VL_CHECK, vl::Viewport::width(), vl::Vector3< T_Scalar >::x(), vl::Vector3< T_Scalar >::y(), and vl::Vector3< T_Scalar >::z().

Referenced by trackballRotation().

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().

## Member Data Documentation

ref<Camera> vl::TrackballManipulator::mCamera`[protected]`

Definition at line 187 of file TrackballManipulator.hpp.

ivec2 vl::TrackballManipulator::mMouseStart`[protected]`

Definition at line 188 of file TrackballManipulator.hpp.

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

mat4 vl::TrackballManipulator::mStartMatrix`[protected]`

Definition at line 189 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseMoveEvent().

vec3 vl::TrackballManipulator::mPivot`[protected]`

Definition at line 190 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseMoveEvent().

vec3 vl::TrackballManipulator::mStartCameraPos`[protected]`

Definition at line 191 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseMoveEvent().

vec3 vl::TrackballManipulator::mStartPivot`[protected]`

Definition at line 192 of file TrackballManipulator.hpp.

Referenced by mouseDownEvent(), and mouseMoveEvent().

ref<Transform> vl::TrackballManipulator::mTransform`[protected]`

Definition at line 193 of file TrackballManipulator.hpp.

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

ETrackballMode vl::TrackballManipulator::mMode`[protected]`

Definition at line 194 of file TrackballManipulator.hpp.

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

int vl::TrackballManipulator::mRotationButton`[protected]`

Definition at line 195 of file TrackballManipulator.hpp.

int vl::TrackballManipulator::mTranslationButton`[protected]`

Definition at line 196 of file TrackballManipulator.hpp.

int vl::TrackballManipulator::mZoomButton`[protected]`

Definition at line 197 of file TrackballManipulator.hpp.

float vl::TrackballManipulator::mRotationSpeed`[protected]`

Definition at line 198 of file TrackballManipulator.hpp.

float vl::TrackballManipulator::mTranslationSpeed`[protected]`

Definition at line 199 of file TrackballManipulator.hpp.

float vl::TrackballManipulator::mZoomSpeed`[protected]`

Definition at line 200 of file TrackballManipulator.hpp.

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

- D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/TrackballManipulator.hpp
- D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/TrackballManipulator.cpp

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:47.
Permission is granted to use this page to write and publish articles regarding Visualization Library.