Blobalizer
Loading...
Searching...
No Matches
ArcBall Class Reference

Implementation of Ken Shoemake's arcball camera with smooth navigation. More...

#include <ArcBall.h>

Inheritance diagram for ArcBall:
ArcBallCamera

Public Member Functions

 ArcBall (const Vector3 &cameraPosition, const Vector3 &viewCenter, const Vector3 &upDir, Deg fov, const Vector2i &windowSize)
 Constructs a new instance.
 
void setViewParameters (const Vector3 &eye, const Vector3 &viewCenter, const Vector3 &upDir)
 Set the camera view parameters: eye position, view center, up direction.
 
void reset ()
 Reset the camera to its initial position, view center, and up dir.
 
void reshape (const Vector2i &windowSize)
 Update screen size after the window has been resized.
 
bool updateTransformation ()
 Update any unfinished transformation due to lagging.
 
Float lagging () const
 Get the amount of lagging such that the camera will (slowly) smoothly navigate.
 
void setLagging (Float lagging)
 Set the amount of lagging such that the camera will (slowly) smoothly navigate. Lagging must be in [0, 1).
 
void initTransformation (const Vector2i &mousePos)
 Initialize the first (screen) mouse position for camera transformation. This should be called from the mouse pressed event.
 
void rotate (const Vector2i &mousePos)
 Rotate the camera from the previous (screen) mouse position to the current(screen) position.
 
void translate (const Vector2i &mousePos)
 Translate the camera from the previous (screen) mouse position to the current(screen) mouse position.
 
void translateDelta (const Vector2 &translationNDC)
 Translate the camera by the delta amount of (NDC) mouse position. Note that NDC position must be in[-1, -1] to[1, 1].
 
void zoom (Float delta)
 Zoom the camera.
 
Deg fov () const
 Field of view.
 
const DualQuaternion & view () const
 Get the camera's view transformation as a dual quaternion.
 
Matrix4 viewMatrix () const
 Get the camera's view transformation as a matrix.
 
Matrix4 inverseViewMatrix () const
 Get the camera's inverse view matrix (which also produces transformation of the camera)
 
const DualQuaternion & transformation () const
 Get the camera's transformation as a dual quaternion.
 
Matrix4 transformationMatrix () const
 Get the camera's transformation matrix.
 
Float viewDistance () const
 Return the distance from the camera position to the center view.
 

Protected Member Functions

void updateInternalTransformations ()
 Update the camera transformations-.
 
Vector2 screenCoordToNDC (const Vector2i &mousePos) const
 Transform from screen coordinate to NDC - normalized device coordinate. The top - left of the screen corresponds to[-1, 1] NDC, and the bottom right is[1, -1] NDC.
 

Protected Attributes

Deg _fov
 
Vector2i _windowSize
 
Vector2 _prevMousePosNDC
 
Float _lagging {}
 
Vector3 _targetPosition
 
Vector3 _currentPosition
 
Vector3 _positionT0
 
Quaternion _targetQRotation
 
Quaternion _currentQRotation
 
Quaternion _qRotationT0
 
Float _targetZooming
 
Float _currentZooming
 
Float _zoomingT0
 
DualQuaternion _view
 
DualQuaternion _inverseView
 

Detailed Description

Implementation of Ken Shoemake's arcball camera with smooth navigation.

See also
: https://www.talisman.org/~erlkonig/misc/shoemake92-arcball.pdf

Constructor & Destructor Documentation

◆ ArcBall()

ArcBall::ArcBall ( const Vector3 &  cameraPosition,
const Vector3 &  viewCenter,
const Vector3 &  upDir,
Deg  fov,
const Vector2i &  windowSize 
)

Constructs a new instance.

Parameters
cameraPositionthe position of the camera on the arc ball.
viewCenterthe position of the arc ball.
upDira vector representing the upwards direction.
fovthe fov of the camera.
windowSizethe size of the output window.

Member Function Documentation

◆ fov()

Deg ArcBall::fov ( ) const
inline

Field of view.

Returns
the field of view

◆ initTransformation()

void ArcBall::initTransformation ( const Vector2i &  mousePos)

Initialize the first (screen) mouse position for camera transformation. This should be called from the mouse pressed event.

Parameters
mousePosthe current mouse position.

◆ inverseViewMatrix()

Matrix4 ArcBall::inverseViewMatrix ( ) const
inline

Get the camera's inverse view matrix (which also produces transformation of the camera)

Returns
the camera's inverse view transformation

◆ lagging()

Float ArcBall::lagging ( ) const
inline

Get the amount of lagging such that the camera will (slowly) smoothly navigate.

Returns
the amount of lagging in [0, 1).

◆ reset()

void ArcBall::reset ( )

Reset the camera to its initial position, view center, and up dir.

◆ reshape()

void ArcBall::reshape ( const Vector2i &  windowSize)
inline

Update screen size after the window has been resized.

Parameters
windowSizethe new window size.

◆ rotate()

void ArcBall::rotate ( const Vector2i &  mousePos)

Rotate the camera from the previous (screen) mouse position to the current(screen) position.

Parameters
mousePosthe current mouse position.

◆ screenCoordToNDC()

Vector2 ArcBall::screenCoordToNDC ( const Vector2i &  mousePos) const
protected

Transform from screen coordinate to NDC - normalized device coordinate. The top - left of the screen corresponds to[-1, 1] NDC, and the bottom right is[1, -1] NDC.

Parameters
mousePosthe mouse position in screen coordinates.
Returns
the given mouse position in normalized device coordinates

◆ setLagging()

void ArcBall::setLagging ( Float  lagging)

Set the amount of lagging such that the camera will (slowly) smoothly navigate. Lagging must be in [0, 1).

◆ setViewParameters()

void ArcBall::setViewParameters ( const Vector3 &  eye,
const Vector3 &  viewCenter,
const Vector3 &  upDir 
)

Set the camera view parameters: eye position, view center, up direction.

Parameters
eyethe position of the camera on the arc ball.
viewCenterthe position of the arc ball.
upDira vector representing the upwards direction.

◆ transformation()

const DualQuaternion & ArcBall::transformation ( ) const
inline

Get the camera's transformation as a dual quaternion.

Returns
the camera's transformation

◆ transformationMatrix()

Matrix4 ArcBall::transformationMatrix ( ) const
inline

Get the camera's transformation matrix.

Returns
the camera's transformation

◆ translate()

void ArcBall::translate ( const Vector2i &  mousePos)

Translate the camera from the previous (screen) mouse position to the current(screen) mouse position.

Parameters
mousePosthe current mouse position.

◆ translateDelta()

void ArcBall::translateDelta ( const Vector2 &  translationNDC)

Translate the camera by the delta amount of (NDC) mouse position. Note that NDC position must be in[-1, -1] to[1, 1].

Parameters
translationNDCthe translation amount.

◆ updateInternalTransformations()

void ArcBall::updateInternalTransformations ( )
protected

Update the camera transformations-.

◆ updateTransformation()

bool ArcBall::updateTransformation ( )

Update any unfinished transformation due to lagging.

Returns
true if the camera matrices have changed, false otherwise.

◆ view()

const DualQuaternion & ArcBall::view ( ) const
inline

Get the camera's view transformation as a dual quaternion.

Returns
the camera's view transformation

◆ viewDistance()

Float ArcBall::viewDistance ( ) const
inline

Return the distance from the camera position to the center view.

Returns
the distance from the camera position to the center view

◆ viewMatrix()

Matrix4 ArcBall::viewMatrix ( ) const
inline

Get the camera's view transformation as a matrix.

Returns
camera's view transformation

◆ zoom()

void ArcBall::zoom ( Float  delta)

Zoom the camera.

Parameters
deltathe amount of zoom (positive delta = zoom in, negative = zoom out)

Member Data Documentation

◆ _currentPosition

Vector3 ArcBall::_currentPosition
protected

◆ _currentQRotation

Quaternion ArcBall::_currentQRotation
protected

◆ _currentZooming

Float ArcBall::_currentZooming
protected

◆ _fov

Deg ArcBall::_fov
protected

◆ _inverseView

DualQuaternion ArcBall::_inverseView
protected

◆ _lagging

Float ArcBall::_lagging {}
protected

◆ _positionT0

Vector3 ArcBall::_positionT0
protected

◆ _prevMousePosNDC

Vector2 ArcBall::_prevMousePosNDC
protected

◆ _qRotationT0

Quaternion ArcBall::_qRotationT0
protected

◆ _targetPosition

Vector3 ArcBall::_targetPosition
protected

◆ _targetQRotation

Quaternion ArcBall::_targetQRotation
protected

◆ _targetZooming

Float ArcBall::_targetZooming
protected

◆ _view

DualQuaternion ArcBall::_view
protected

◆ _windowSize

Vector2i ArcBall::_windowSize
protected

◆ _zoomingT0

Float ArcBall::_zoomingT0
protected

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