Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
Tucano::RotationManipulator Class Reference

Manipulator for rotating a mesh It works as a spherical manipulator (such as a trackball) or a ring manipulator (one axis at a time) separate Spherical and Ring manipulators. More...

#include <trackball.hpp>

Inheritance diagram for Tucano::RotationManipulator:
Tucano::Manipulator Tucano::Trackball Tucano::Camera

Public Member Functions

 RotationManipulator (void)
 Default constructor. More...
 
virtual void setRadius (float r)
 Sets the radius. More...
 
Eigen::Quaternion< float > rotateCamera (const Eigen::Vector2f &screen_pos)
 Rotates the manipulator given a new 2D screen position. More...
 
Eigen::Quaternion< float > computeRotationAngle (float sensibility=1.0)
 Computes the trackball's rotation, using stored initial and final position vectors. More...
 
virtual Eigen::Vector3f computeTranslationVector (void)
 Compute the trackball's translation, using stored initial and final position vectors. More...
 
void updateViewMatrix (void)
 Applies all trackball's transformations to the view matrix. More...
 
void endRotation (void)
 Indicates that a rotation has ended. Disables the rotating flag, indicating that the mouse callback functions will stop reading the mouse coordinates in order to stop the trackball's rotation. More...
 
void render (void)
 Renders the trackball representation. More...
 
- Public Member Functions inherited from Tucano::Manipulator
 Manipulator (void)
 Default constructor. More...
 
Eigen::Vector3f getSpherePos (void)
 Returns the manipulator 3D position. More...
 
void setSpherePos (const Eigen::Vector3f &pos)
 Sets the manipulator 3D position. More...
 
void setExternalCamera (Tucano::Camera *ext_cam)
 Sets the pointer to the external camera The external camera is the actual view camera since the trackball is used here as a mesh manipulator. More...
 
- Public Member Functions inherited from Tucano::Trackball
 Trackball (string shader_dir="")
 Default constructor. More...
 
void reset (void)
 Resets trackball to initial position and orientation. More...
 
bool isRotating (void)
 Returns wether the trackball is being rotated or not. More...
 
bool isTranslating (void)
 Returns wether the trackball is being translated or not. More...
 
Eigen::Vector3f getDefaultTranslation (void)
 Returns the default translation for placing the camera outside the trackball sphere. More...
 
void setDefaultTranslation (Eigen::Vector3f t)
 Sets the default translation vector. More...
 
Eigen::Quaternion< float > getDefaultRotation (void)
 Returns the default rotation quaternion. More...
 
virtual Eigen::Quaternion< float > getRotation (void)
 Returns the rotation (without the default part) as a quaternion. More...
 
void setDefaultRotation (Eigen::Matrix3f rot)
 Sets the default rotation quaternion. More...
 
float getZoom (void)
 Retuns the zoom factor (the radius of the trackball). More...
 
void setTrackballProjectionMatrix (const Eigen::Matrix4f &mat)
 Sets the projection matrix used for the trackball rendering. Note that this is usually different than the projection matrix for the scene. More...
 
void endTranslation (void)
 Indicates that a translation has ended. Disable the translating flag, indicating that the mouse callback functions will stop reading the mouse coordinates in order to stop the trackball's translation. More...
 
void setRenderFlag (bool flag)
 Returns wether the trackball representation should be drawn or not. More...
 
void loadShader (void)
 Load Trackball Shader file. More...
 
void initOpenGLMatrices (void)
 Initializes the view and projection matrices. They are all initialized as Identity matrices, but view is then translated by the default_translation vector. More...
 
Eigen::Matrix4f setTrackballPerspectiveMatrix (float fy, float aspect_ratio, float near_plane, float far_plane)
 Sets the trackball projection matrix as perspective. More...
 
Eigen::Matrix4f setTrackballOrthographicMatrix (float left, float right, float bottom, float top, float near_plane, float far_plane)
 Sets the trackball projection matrix as orthographic. More...
 
Eigen::Vector2f normalizePosition (const Eigen::Vector2f &pos)
 Nomalizes a screen position to range [-1,1]. More...
 
virtual Eigen::Vector3f translateCamera (const Eigen::Vector2f &pos)
 Computes and applies the translation transformations to the trackball given new position. More...
 
void increaseZoom (float scale)
 Increases the zoom on the scene by appling a scale to the View Matrix. The current scale used in View Matrix is multiplied by the given scale factor. More...
 
void decreaseZoom (float scale)
 Decreases the zoom on the scene by appling a scale to the View Matrix. The current scale used in View Matrix is divided by the given scale factor. More...
 
void applyScaleToViewMatrix (float scale)
 Applies a scale factor to the viewMatrix. The current scale used in view matrix will be substituted by the given scale factor. More...
 
void translateViewMatrix (const Eigen::Vector3f &translation)
 Translates the view matrix by a given vector trans. This directly modifies the translation vector of the trackball. Note that the view matrix is always recomputed using the translation, quaternion and zoom. More...
 
void rotateViewMatrix (const Eigen::Affine3f &rot)
 Rotates the view matrix by a given rotation matrix. This directly modifies the quaternion of the trackball. Note that the view matrix is always recomputed using the translation, quaternion and zoom. More...
 
void createTrackballRepresentation (void)
 Creates the circle representating rotation around Z axis. The other circles will be created by simply rotating this one around the desired axis. More...
 
virtual void render (Eigen::Affine3f ext_view_matrix=Eigen::Affine3f::Identity(), Eigen::Matrix4f ext_proj_matrix=Eigen::Matrix4f::Identity())
 Renders the trackball representation. More...
 
- Public Member Functions inherited from Tucano::Camera
void resetViewMatrix (void)
 Reset view matrix. More...
 
void resetProjectionMatrix (void)
 Reset projection matrix. More...
 
void reset (void)
 Resets trackball to initial position and orientation. More...
 
Eigen::Vector3f getCenter (void) const
 Returns the center of the camera in world space. More...
 
void getViewMatrix (GLdouble *matrix)
 Return the modelview matrix as a GLdouble array. More...
 
void getProjectionMatrix (GLdouble *matrix)
 Return the projection matrix as a GLdouble array. More...
 
Eigen::Vector3f projectPoint (const Eigen::Vector4f &pt, Eigen::Vector4f &viewport)
 Returns screen space coordinates of a 3D point. More...
 
Eigen::Affine3f getViewMatrix (void) const
 Returns the view matrix as an Affine 3x3 matrix. More...
 
Eigen::Affine3f * viewMatrix (void)
 Returns a pointer to the view matrix as an Affine 3x3 matrix. More...
 
Eigen::Matrix4f getProjectionMatrix (void) const
 Returns the view matrix as an 4x4 matrix. More...
 
Eigen::Matrix4f * projectionMatrix (void)
 Returns a pointer to the projection matrix as an 4x4 matrix. More...
 
Eigen::Matrix3f getRotationMatrix (void) const
 Returns a 3x3 matrix containing only the rotation of the view matrix. More...
 
Eigen::Vector3f getTranslationMatrix (void) const
 Returns the translation part of the view matrix as a vector. More...
 
float getPerspectiveScale (void) const
 Returns the perspective scale. More...
 
Eigen::Vector4f getViewport (void) const
 Returns the viewport coordinates. More...
 
Eigen::Vector2i getViewportSize (void) const
 Returns the dimensions of the viewport. More...
 
float getViewportAspectRatio (void) const
 Returns the viewport aspect ratio. More...
 
void setViewport (const Eigen::Vector4f &vp)
 Sets the viewport coordinates. More...
 
void setViewport (const Eigen::Vector2i &vp)
 
void setViewport (const Eigen::Vector2f &vp)
 Sets the viewport coordinates considering that the minimum coordinates are zero. More...
 
void setProjectionMatrix (const Eigen::Matrix4f &mat)
 Sets the projection matrix from a given 4x4 matrix. More...
 
void setViewMatrix (const Eigen::Affine3f &mat)
 Sets the view matrix from a given an affine 3x3 matrix. More...
 
float getNearPlane (void) const
 Returns near plane value. More...
 
float getFarPlane (void) const
 Returns far plane value. More...
 
 ~Camera ()
 Default destructor. More...
 
float getFovy (void) const
 Returns current field of view angle in y axis. More...
 
 Camera (void)
 Default constructor. More...
 
Eigen::Matrix4f setPerspectiveMatrix (float fy, float in_aspect_ratio, float in_near_plane, float in_far_plane)
 Sets the projection matrix as a perspective matrix. More...
 
void changeFovy (float new_fovy)
 Changes the fovy and computes new perspective projection matrix. More...
 
Eigen::Matrix4f setOrthographicMatrix (float left, float right, float bottom, float top, float near_plane, float far_plane)
 Sets the projection matrix as a orthographic matrix. More...
 
void incrementFov (float inc)
 Increases the fov of the perspective matrix by a given increment. More...
 
void translate (const Eigen::Vector3f &translation)
 Translates the view matrix by a given vector. More...
 
void rotate (const Eigen::Quaternion< float > &rotation)
 Rotate the view matrix by a given quaternion. More...
 
void scale (const Eigen::Vector3f &scale_factors)
 Scales the view matrix by given factors. More...
 
void scale (float scale_factor)
 Scales the view matrix by given factor in all axis. More...
 

Protected Member Functions

bool computeSphere3DPosition (const Eigen::Vector2f &pixel, Eigen::Vector3f &sphere_pos)
 
bool computeRing3DPosition (const Eigen::Vector2f &pixel, Eigen::Vector3f &sphere_pos)
 

Private Attributes

Eigen::Vector3f last_position = Eigen::Vector3f::Zero()
 The last 3D position clicked on sphere. More...
 
Eigen::Vector3f sphere_position = Eigen::Vector3f::Zero()
 Clicked position on manipulator sphere. More...
 
float inner_radius = 1.0
 inner radius of axis ring More...
 
float outer_radius = 1.3
 outer radius of axis ring More...
 
int selected_axis = -1
 selected axis for rotation More...
 
Eigen::Vector3f selected_normal = Eigen::Vector3f::Zero()
 

Additional Inherited Members

- Static Public Member Functions inherited from Tucano::Camera
static Eigen::Matrix4f createPerspectiveMatrix (float fy, float in_aspect_ratio, float in_near_plane, float in_far_plane)
 Returns a perspective projection matrix with the given parameters. More...
 
static Eigen::Matrix4f createOrthographicMatrix (float left, float right, float bottom, float top, float near_plane, float far_plane)
 Returns an orthographic projection matrix with the given parameters. More...
 
- Protected Attributes inherited from Tucano::Manipulator
Tucano::Cameraexternal_camera
 Pointer to external camera. More...
 
Eigen::Vector3f sphere_position = Eigen::Vector3f::Zero()
 Clicked position on manipulator sphere. More...
 
- Protected Attributes inherited from Tucano::Trackball
float zoom = 1.0
 The current scale being applied to the View Matrix. More...
 
bool rotating = false
 Flag that indicates wether the trackball is being rotated. More...
 
bool translating = false
 Flag that indicates wether the trackball is being translated. More...
 
bool drawTrackball = true
 Flag that indicates wether the trackball's representation should be drawn. More...
 
Eigen::Matrix4f trackballProjectionMatrix
 Projection matrix used for the trackball's drawing. By default it is defined as an orthogonal projection matrix. More...
 
Eigen::Vector3f initialPosition
 Initial position vector used to calculate trackball's rotation. More...
 
Eigen::Vector3f finalPosition
 Final position vector used to calculate trackball's rotation. More...
 
Eigen::Vector2f initialTranslationPosition
 Initial position vector used to calculate trackball's translation. More...
 
Eigen::Vector2f finalTranslationPosition
 Final position vector used to calculate trackball's translation. More...
 
Eigen::Quaternion< float > quaternion
 Trackball's quaternion. More...
 
Eigen::Quaternion< float > default_quaternion
 Trackball's default rotation. More...
 
Eigen::Vector3f translationVector
 Trackball's translation vector. More...
 
Eigen::Vector3f default_translation = Eigen::Vector3f (0.0, 0.0, -4.0)
 Default translation to move camera away from center. More...
 
Tucano::Shader trackball_shader
 Trackball Shader, used just for rendering the trackball's representation. More...
 
Tucano::Mesh mesh
 Trackball visual representation. More...
 
float radius = 0.8
 The trackball radius. It's defined as 0.8 times the smallest viewport dimension. More...
 
bool use_default_shaders
 Flag to use default shaders set as const strings in class, or pass a directory with custom shaders. More...
 
- Protected Attributes inherited from Tucano::Camera
Eigen::Matrix4f projection_matrix
 Projection, or intrinsic, matrix. More...
 
Eigen::Affine3f view_matrix
 View, or extrinsic, matrix. More...
 
Eigen::Vector4f viewport
 Viewport dimensions [minX, minY, width, height]. More...
 
Eigen::Affine3f default_view
 
float near_plane
 Near plane used for projection matrix. More...
 
float far_plane
 Far plane used for projection matrix. More...
 
float frustum_left
 Frustum left dimension. More...
 
float frustum_right
 Frustum right dimension. More...
 
float frustum_top
 Frustum top dimension. More...
 
float frustum_bottom
 Frustum bottom dimension. More...
 
float aspect_ratio
 Aspect ratio for projection matrix. More...
 
float focal_length
 Camera's Focal Length. More...
 
float fovy
 Field of view angle in y axis. More...
 
bool use_perspective
 Flag to indicate if using a perspective or othograpic projection. More...
 

Detailed Description

Manipulator for rotating a mesh It works as a spherical manipulator (such as a trackball) or a ring manipulator (one axis at a time) separate Spherical and Ring manipulators.

Constructor & Destructor Documentation

Tucano::RotationManipulator::RotationManipulator ( void  )
inline

Default constructor.

Member Function Documentation

bool Tucano::RotationManipulator::computeRing3DPosition ( const Eigen::Vector2f &  pixel,
Eigen::Vector3f &  sphere_pos 
)
inlineprotected
Eigen::Quaternion<float> Tucano::RotationManipulator::computeRotationAngle ( float  sensibility = 1.0)
inlinevirtual

Computes the trackball's rotation, using stored initial and final position vectors.

Parameters
sensibilityScales the rotation, works as a sensibility factor
Returns
Returns the increment rotation

Reimplemented from Tucano::Trackball.

bool Tucano::RotationManipulator::computeSphere3DPosition ( const Eigen::Vector2f &  pixel,
Eigen::Vector3f &  sphere_pos 
)
inlineprotected
virtual Eigen::Vector3f Tucano::RotationManipulator::computeTranslationVector ( void  )
inlinevirtual

Compute the trackball's translation, using stored initial and final position vectors.

Returns
Translation increment

Reimplemented from Tucano::Trackball.

void Tucano::RotationManipulator::endRotation ( void  )
inlinevirtual

Indicates that a rotation has ended. Disables the rotating flag, indicating that the mouse callback functions will stop reading the mouse coordinates in order to stop the trackball's rotation.

Reimplemented from Tucano::Trackball.

void Tucano::RotationManipulator::render ( void  )
inline

Renders the trackball representation.

Todo:
setTrackballOrthographicMatrix should be set during viewport resize The external matrices are useful when the trackball should follow a specif object for example, so the main camera matrices should be passed here
Eigen::Quaternion<float> Tucano::RotationManipulator::rotateCamera ( const Eigen::Vector2f &  screen_pos)
inlinevirtual

Rotates the manipulator given a new 2D screen position.

Parameters
screen_posMouse cursor new screen pos
Returns
rotation increment as a Quaternion

Reimplemented from Tucano::Trackball.

virtual void Tucano::RotationManipulator::setRadius ( float  r)
inlinevirtual

Sets the radius.

Reimplemented from Tucano::Trackball.

void Tucano::RotationManipulator::updateViewMatrix ( void  )
inlinevirtual

Applies all trackball's transformations to the view matrix.

Reimplemented from Tucano::Trackball.

Member Data Documentation

float Tucano::RotationManipulator::inner_radius = 1.0
private

inner radius of axis ring

Eigen::Vector3f Tucano::RotationManipulator::last_position = Eigen::Vector3f::Zero()
private

The last 3D position clicked on sphere.

float Tucano::RotationManipulator::outer_radius = 1.3
private

outer radius of axis ring

int Tucano::RotationManipulator::selected_axis = -1
private

selected axis for rotation

Eigen::Vector3f Tucano::RotationManipulator::selected_normal = Eigen::Vector3f::Zero()
private
Eigen::Vector3f Tucano::RotationManipulator::sphere_position = Eigen::Vector3f::Zero()
private

Clicked position on manipulator sphere.


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