Class TrackballControls

Object
Controls
TrackballControls
All Implemented Interfaces:
MouseDownHandler, MouseMoveHandler, MouseUpHandler, MouseWheelHandler, TouchEndHandler, TouchMoveHandler, TouchStartHandler, EventHandler, RequiresResize

Trackball controls for 3D views adapted from Parallax and threejs

CSS Style Rules

The different trackball actions of zooming, panning and rotating change the style classes. As an example, this allow to change the pointer style accordingly.
.evoludo-cursorZoomIn
the 3D view is zooming in.
.evoludo-cursorZoomOut
the 3D view is zooming out.
.evoludo-cursorRotate
the 3D view is rotating
.evoludo-cursorMoveView
the 3D view is panning
Author:
Christoph Hauert
See Also:
  • Field Details

    • MAX_EYE_DIST

      private static final double MAX_EYE_DIST
      Maximum eye distance. How far you can zoom out.
      See Also:
    • MAX_EYE_DIST_SQ

      private static final double MAX_EYE_DIST_SQ
      Square of maximum eye distance.
      See Also:
    • MIN_EYE_DIST

      private static final double MIN_EYE_DIST
      Minimum eye distance. How far you can zoom in.
      See Also:
    • initialDistance

      double initialDistance
      Initial eye distance.
    • MIN_EYE_DIST_SQ

      private static final double MIN_EYE_DIST_SQ
      Square of minimum eye distance.
      See Also:
    • ZOOM_INCR

      protected static final double ZOOM_INCR
      Default increments of zoom factor (multiplicative).
      See Also:
    • isEnabled

      private boolean isEnabled
      true if trackball controls enabled.
    • rotateSpeed

      private double rotateSpeed
      Speed of rotation;
    • zoomSpeed

      private double zoomSpeed
      Speed for zoom.
    • panSpeed

      private double panSpeed
      Speed for panning (shifting).
    • zoomChange

      private double zoomChange
      Utility variable to keep track of changes of zoom factor while zooming.
    • hasRotate

      private boolean hasRotate
      Flag indicating whether rotation is enabled.
    • hasZoom

      private boolean hasZoom
      Flag indicating whether zooming is enabled.
    • hasPan

      private boolean hasPan
      Flag indicating whether panning is enabled.
    • doRotate

      private boolean doRotate
      true if rotation is pending.
    • doZoom

      private boolean doZoom
      true if zooming is pending.
    • doPan

      private boolean doPan
      true if panning is pending.
    • isDragging

      private boolean isDragging
      true while the pointer is dragging.
    • isDynamicUpdate

      private boolean isDynamicUpdate
      true to disable dynamic damping of changes to the view..
    • dynamicDampingFactor

      private double dynamicDampingFactor
      Factor for dynamic damping of changes to the view.
    • radius

      private double radius
      Radius of trackball. Depends on size of associated widget that displays the 3D scene.
    • target

      private Vector3 target
      Target point eye is looking at.
    • eye

      private Vector3 eye
      Location of eye.
    • rotateStart

      private Vector3 rotateStart
      Starting coordinates on trackball for rotations.
    • rotateEnd

      private Vector3 rotateEnd
      End coordinates on trackball for rotations.
    • panStart

      private Vector2 panStart
      Starting coordinates on trackball for panning.
    • panEnd

      private Vector2 panEnd
      End coordinates on trackball for panning.
    • mouseWheelHandler

      private HandlerRegistration mouseWheelHandler
      Mouse and touch handlers to control the view of the 3D scene.
    • mouseDownHandler

      private HandlerRegistration mouseDownHandler
      Mouse and touch handlers to control the view of the 3D scene.
    • mouseMoveHandler

      private HandlerRegistration mouseMoveHandler
      Mouse and touch handlers to control the view of the 3D scene.
    • mouseUpHandler

      private HandlerRegistration mouseUpHandler
      Mouse and touch handlers to control the view of the 3D scene.
    • touchStartHandler

      private HandlerRegistration touchStartHandler
      Mouse and touch handlers to control the view of the 3D scene.
    • touchMoveHandler

      private HandlerRegistration touchMoveHandler
      Mouse and touch handlers to control the view of the 3D scene.
    • touchEndHandler

      private HandlerRegistration touchEndHandler
      Mouse and touch handlers to control the view of the 3D scene.
    • t

      private Timer t
      Timer for reseting the CSS styling after zooming.
    • pinchZoom

      private double pinchZoom
      Helper variable to keep track of the distance of two touches between subsequent touch events.
    • mouseOnBall

      private Vector3 mouseOnBall
      The mouse coordinates on the virtual trackball.
  • Constructor Details

    • TrackballControls

      public TrackballControls(Object3D camera, Widget widget)
      Creates a new instance of TrackballControls for the 3D scene displayed in widget as seen from the camera.
      Parameters:
      camera - the camera of the rendered 3D scene
      widget - the view that displays the 3D scene and listens for pointer and touch events
  • Method Details

    • dispose

      public void dispose()
      Free resources.
    • isEnabled

      public boolean isEnabled()
      Check if trackball controls are enabled.
      Returns:
      true if enabled
    • setEnabled

      public void setEnabled(boolean isEnabled)
      Enable/disable trackball controls (default: enabled).
      Parameters:
      isEnabled - enable trackball controls if true
    • setRotateSpeed

      public void setRotateSpeed(double rotateSpeed)
      Set rotation speed (default: 1.0).
      Parameters:
      rotateSpeed - the speed to rotate 3D view
    • setZoomSpeed

      public void setZoomSpeed(double zoomSpeed)
      Set zoom speed (default: 1.2).
      Parameters:
      zoomSpeed - the speed to zoom 3D view
    • setPanSpeed

      public void setPanSpeed(double panSpeed)
      Set pan speed (default: 0.3).
      Parameters:
      panSpeed - the speed to pan 3D view
    • setRotate

      public void setRotate(boolean rotate)
      Enable/disable rotation (default: enabled).
      Parameters:
      rotate - enables rotation if true
    • setZoom

      public void setZoom(boolean zoom)
      Enable/disable zoom (default: enabled).
      Parameters:
      zoom - enables zoom if true
    • setPan

      public void setPan(boolean pan)
      Enable/disable pan (default: enabled).
      Parameters:
      pan - enables panning if true
    • setDynamicUpdate

      public void setDynamicUpdate(boolean dynamic)
      Enable/disable dynamic moving of 3D view (default: enabled).
      Parameters:
      dynamic - enables dynamic updates of 3D view if true
    • setDynamicDampingFactor

      public void setDynamicDampingFactor(double dynamicDampingFactor)
      Set dynamic damping factor (default: 0.2).
      Parameters:
      dynamicDampingFactor - the factor for dynamic damping of
    • getTarget

      public Vector3 getTarget()
      Get the target point where the eye is looking.
      Returns:
      the target point
    • setTarget

      public void setTarget(Vector3 target)
      Set the target point where the eye is looking.
      Parameters:
      target - the new target for the eye
    • update

      public void update()
      Update the view of the 3D scene. Perform rotations, zooming and panning as requested.

      Note: This method must be called in the AnimatedScene.onUpdate(double) method.

    • zoom

      public void zoom()
      Reset zoom.
    • zoom

      public void zoom(double zoom)
      Set zoom factor.
      Parameters:
      zoom - the new zoom factor
    • onResize

      public void onResize()

      Adjusts the radius of the (virtual) trackball.

      Specified by:
      onResize in interface RequiresResize
    • onMouseWheel

      public void onMouseWheel(MouseWheelEvent event)

      Zooms the 3D view.

      Specified by:
      onMouseWheel in interface MouseWheelHandler
    • onMouseDown

      public void onMouseDown(MouseDownEvent event)

      Marks the potential start of updates to the view of the 3D scene.

      Specified by:
      onMouseDown in interface MouseDownHandler
    • onMouseUp

      public void onMouseUp(MouseUpEvent event)

      If the left mouse button was released this marks the end updates to the view of the 3D scene.

      Specified by:
      onMouseUp in interface MouseUpHandler
    • onMouseMove

      public void onMouseMove(MouseMoveEvent event)

      If the left mouse button is down, this dragging rotates or pans (if Shift-key is pressed) the view of the 3D scene.

      Specified by:
      onMouseMove in interface MouseMoveHandler
    • onTouchStart

      public void onTouchStart(TouchStartEvent event)

      Marks the potential start of updates to the view of the 3D scene.

      Specified by:
      onTouchStart in interface TouchStartHandler
    • onTouchMove

      public void onTouchMove(TouchMoveEvent event)

      For one-finger touch rotate the view and for two-finger touch zoom the view of the 3D scene. Note panning for touch events is not (yet?) implemented.

      Specified by:
      onTouchMove in interface TouchMoveHandler
    • onTouchEnd

      public void onTouchEnd(TouchEndEvent event)

      At least one touch ended. Marks the end of zooming but if one touch remains get ready to rotate the 3D scene.

      Specified by:
      onTouchEnd in interface TouchEndHandler
    • getMouseOnScreen

      private Vector2 getMouseOnScreen(int clientX, int clientY)
      Re-scale pointer coordinates to [0, 1]2. This is used for panning.
      Parameters:
      clientX - the horizontal pointer coordinate (relative to widget)
      clientY - the vertical pointer coordinate (relative to widget)
      Returns:
      scaled pointer coordinates
    • getMouseProjectionOnBall

      private Vector3 getMouseProjectionOnBall(int clientX, int clientY)
      Convert pointer coordinates to coordinates on (virtual) trackball (unit sphere). This is used for rotation.
      Parameters:
      clientX - the horizontal pointer coordinate (relative to widget)
      clientY - the vertical pointer coordinate (relative to widget)
      Returns:
      coordinates of pointer on trackball
    • panCamera

      private void panCamera()
      Update eye and target for (dynamical) panning.
    • zoomCamera

      private void zoomCamera()
      Update eye and target for zooming.
    • rotateCamera

      private void rotateCamera()
      Update eye and target for (dynamical) rotating.