Visual Computing Library
Loading...
Searching...
No Matches
vcl::TrackBall< Scalar > Class Template Reference

The TrackBall class implements a trackball camera. More...

#include <vclib/render/viewer/trackball.h>

Classes

struct  TransformArgs
 

Public Types

enum  MotionType {
  ARC , PAN , ZMOVE , ROLL ,
  SCALE , FOV , FOCUS , DIR_LIGHT_ARC ,
  MOTION_NUMBER
}
 
using AtomicMotionArg = std::variant< TransformArgs, Scalar, Point3< Scalar >, std::monostate >
 

Public Member Functions

void reset ()
 
void reset (const Point3< Scalar > &center, Scalar scale)
 Reset the manipulator to a given center and scale.
 
void resetDirectionalLight ()
 
Point3< Scalar > center () const
 
void setCenter (const Point3< Scalar > &center)
 
Scalar scale () const
 
void setScale (Scalar scale)
 
void changeScale (Scalar factor)
 
void setRotation (const Quaternion< Scalar > &rotation)
 
void setRotation (const Point3< Scalar > &axis, Scalar angle)
 
Scalar fovDeg () const
 Get the vertical field of view.
 
void setFovDeg (Scalar fov)
 Set the vertical field of view adapting the eye distance.
 
Camera< Scalar >::ProjectionMode::Enum projectionMode () const
 
void setProjectionMode (Camera< Scalar >::ProjectionMode::Enum mode)
 
void setScreenSize (Scalar width, Scalar height)
 
void setScreenSize (const Point2< Scalar > &sz)
 
DirectionalLight< Scalar > light () const
 
const vcl::Camera< Scalar > & camera () const
 
Matrix44< Scalar > viewMatrix () const
 
Matrix44< Scalar > projectionMatrix () const
 
Matrix44< Scalar > gizmoMatrix () const
 
Matrix44< Scalar > lightGizmoMatrix () const
 
bool isDragging () const
 
MotionType currentMotion () const
 
void applyAtomicMotion (MotionType motion, AtomicMotionArg step=std::monostate())
 Applies an atomic motion to the trackball. Atomic motions are motions that are applied atomically to the camera. The step parameter is a std::variant that can store different values depending on the motion type.
 
void applyScale (Scalar value)
 
void applyRoll (Scalar angleRad)
 
void applyPan (const Point3< Scalar > &translation)
 
void applyArc (const Point3< Scalar > &axis, Scalar angle)
 
void setMousePosition (Scalar x, Scalar y)
 
void setMousePosition (const Point2< Scalar > &point)
 
void beginDragMotion (MotionType motion)
 Starts a drag motion.
 
void endDragMotion (MotionType motion)
 Ends a drag motion.
 
void update ()
 Updates the state of the trackball during a drag motion.
 

Private Member Functions

void setDragMotionValue (MotionType motion, bool value)
 
void drag (MotionType motion)
 
Scalar trackballToPixelRatio () const
 
Point3< Scalar > pointOnTrackballPlane (Point2< Scalar > screenCoord) const
 
Point3< Scalar > pointOnArcball (Point2< Scalar > screenCoord) const
 
void rotate (const Quaternion< Scalar > &q)
 
void rotate (Point3< Scalar > axis, Scalar angleRad)
 
void translate (Point3< Scalar > t)
 Translate in the camera space.
 
void rotateDirLight (const Quaternion< Scalar > &rotation)
 
void rotateDirLight (Point3< Scalar > axis, Scalar angle)
 
void dragArc ()
 
void roll (Scalar delta)
 
void dragRoll ()
 
void performPan (const Point2< Scalar > &pixelDelta)
 perform a pan operation
 
void dragPan ()
 
void performZmove (const Scalar &pixelDelta)
 translate in the camera z direction
 
void dragZmove ()
 
void performScale (Scalar pixelDelta)
 
void dragScale ()
 
void dragDirLightArc ()
 
void performFov (Scalar pixelDelta)
 

Private Attributes

Camera< Scalar > mCamera
 
Affine3< Scalar > mTransform = Affine3<Scalar>::Identity()
 
Quaternion< Scalar > mDirectionalLightTransform
 
Point2< Scalar > mScreenSize = {-1, -1}
 
Scalar mRadius = ARC_BALL_RADIUS_RATIO
 
bool mDragging = false
 
MotionType mCurrDragMotion = MOTION_NUMBER
 
Point3< Scalar > mInitialPoint
 
Affine3< Scalar > mInitialTransform = Affine3<Scalar>::Identity()
 
Quaternion< Scalar > mInitialDirRotation = Quaternion<Scalar>::Identity()
 
Point2< Scalar > mCurrMousePosition
 
Point2< Scalar > mPrevMousePosition
 

Static Private Attributes

static constexpr Scalar ARC_BALL_RADIUS_RATIO = 1.0 / 1.61803398875
 
static constexpr Scalar FOCUS_SCALE_FACTOR = 1.15
 
static constexpr Scalar DEFAULT_FOV_DEG = 54.0
 

Detailed Description

template<typename Scalar>
class vcl::TrackBall< Scalar >

The TrackBall class implements a trackball camera.

The trackball class stores a camera and provides a set motions that allow the user to manipulate it.

There are two main types of motions:

  • atomic motions: these motions have no state and they are applied atomicly to the camera. They are not affected by the mouse position. An example of an atomic motion is a zoom.
  • drag motions: these motions have a state, that may change with the mouse position. They begin and end with the begin/end member functions, and they update their state trough the change of the mouse position. An example of a drag motion is an arcball rotation.

Member Function Documentation

◆ applyAtomicMotion()

template<typename Scalar >
void vcl::TrackBall< Scalar >::applyAtomicMotion ( MotionType  motion,
AtomicMotionArg  step = std::monostate() 
)
inline

Applies an atomic motion to the trackball. Atomic motions are motions that are applied atomically to the camera. The step parameter is a std::variant that can store different values depending on the motion type.

Possible motion types and supported step values are:

  • ROLL:
    • Scalar (positive counter-clockwise roll, negative otherwise)
  • SCALE:
    • Scalar (positive zoom in, negative zoom out)
  • ARC:
  • PAN:
    • Point3 translation in trackball camera space
  • ZMOVE:
    • Scalar z translation in trackball camera space
  • FOCUS:
    • Point3 set center in world space
      Parameters
      motion
      step

◆ beginDragMotion()

template<typename Scalar >
void vcl::TrackBall< Scalar >::beginDragMotion ( MotionType  motion)
inline

Starts a drag motion.

Parameters
[in]motionthe motion type
Note
this function should be called when the drag motion begins (e.g., the mouse is pressed) or the motion type changes.

◆ dragArc()

template<typename Scalar >
void vcl::TrackBall< Scalar >::dragArc ( )
inlineprivate

— User interaction functions — -----------— Arc -----------—

◆ dragDirLightArc()

template<typename Scalar >
void vcl::TrackBall< Scalar >::dragDirLightArc ( )
inlineprivate

--— Directional Light Arc --—

◆ endDragMotion()

template<typename Scalar >
void vcl::TrackBall< Scalar >::endDragMotion ( MotionType  motion)
inline

Ends a drag motion.

Parameters
[in]motionthe motion type
Note
this function should be called when the drag motion ends (e.g., the mouse is released)

◆ performFov()

template<typename Scalar >
void vcl::TrackBall< Scalar >::performFov ( Scalar  pixelDelta)
inlineprivate

--— Fov --—

◆ performPan()

template<typename Scalar >
void vcl::TrackBall< Scalar >::performPan ( const Point2< Scalar > &  pixelDelta)
inlineprivate

perform a pan operation

-----------— Pan -----------—

Parameters
pixelDeltathe pan movement in pixels

◆ performScale()

template<typename Scalar >
void vcl::TrackBall< Scalar >::performScale ( Scalar  pixelDelta)
inlineprivate

-----------— Scaling -----------—

◆ performZmove()

template<typename Scalar >
void vcl::TrackBall< Scalar >::performZmove ( const Scalar &  pixelDelta)
inlineprivate

translate in the camera z direction

-----------— Z-Move -----------—

Parameters
pixelDeltathe delta movement in pixels

◆ reset()

template<typename Scalar >
void vcl::TrackBall< Scalar >::reset ( const Point3< Scalar > &  center,
Scalar  scale 
)
inline

Reset the manipulator to a given center and scale.

Parameters
center
scale

◆ roll()

template<typename Scalar >
void vcl::TrackBall< Scalar >::roll ( Scalar  delta)
inlineprivate

-----------— Roll -----------—

◆ rotate()

template<typename Scalar >
void vcl::TrackBall< Scalar >::rotate ( const Quaternion< Scalar > &  q)
inlineprivate

------— Base functions ------—

◆ setDragMotionValue()

template<typename Scalar >
void vcl::TrackBall< Scalar >::setDragMotionValue ( MotionType  motion,
bool  value 
)
inlineprivate

-----------— Generic Functions -----------—

◆ setFovDeg()

template<typename Scalar >
void vcl::TrackBall< Scalar >::setFovDeg ( Scalar  fov)
inline

Set the vertical field of view adapting the eye distance.

Parameters
[in]fovthe field of view in degrees.

◆ translate()

template<typename Scalar >
void vcl::TrackBall< Scalar >::translate ( Point3< Scalar >  t)
inlineprivate

Translate in the camera space.

Note
from the trackball center Y range is [-1, 1] and X is [-aspectRatio, aspectRatio]

◆ update()

template<typename Scalar >
void vcl::TrackBall< Scalar >::update ( )
inline

Updates the state of the trackball during a drag motion.

Note
: this member function must be called only when a drag motion is in progress (e.g., when the mouse is dragging);

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