Class TrackballControls
- All Implemented Interfaces:
MouseDownHandler
,MouseMoveHandler
,MouseUpHandler
,MouseWheelHandler
,TouchEndHandler
,TouchMoveHandler
,TouchStartHandler
,EventHandler
,RequiresResize
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 Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
true
if panning is pending.private boolean
true
if rotation is pending.private boolean
true
if zooming is pending.private double
Factor for dynamic damping of changes to the view.private Vector3
Location of eye.private boolean
Flag indicating whether panning is enabled.private boolean
Flag indicating whether rotation is enabled.private boolean
Flag indicating whether zooming is enabled.(package private) double
Initial eye distance.private boolean
true
while the pointer is dragging.private boolean
true
to disable dynamic damping of changes to the view..private boolean
true
if trackball controls enabled.private static final double
Maximum eye distance.private static final double
Square of maximum eye distance.private static final double
Minimum eye distance.private static final double
Square of minimum eye distance.private HandlerRegistration
Mouse and touch handlers to control the view of the 3D scene.private HandlerRegistration
Mouse and touch handlers to control the view of the 3D scene.private Vector3
The mouse coordinates on the virtual trackball.private HandlerRegistration
Mouse and touch handlers to control the view of the 3D scene.private HandlerRegistration
Mouse and touch handlers to control the view of the 3D scene.private Vector2
End coordinates on trackball for panning.private double
Speed for panning (shifting).private Vector2
Starting coordinates on trackball for panning.private double
Helper variable to keep track of the distance of two touches between subsequent touch events.private double
Radius of trackball.private Vector3
End coordinates on trackball for rotations.private double
Speed of rotation;private Vector3
Starting coordinates on trackball for rotations.private Timer
Timer for reseting the CSS styling after zooming.private Vector3
Target point eye is looking at.private HandlerRegistration
Mouse and touch handlers to control the view of the 3D scene.private HandlerRegistration
Mouse and touch handlers to control the view of the 3D scene.private HandlerRegistration
Mouse and touch handlers to control the view of the 3D scene.protected static final double
Default increments of zoom factor (multiplicative).private double
Utility variable to keep track of changes of zoom factor while zooming.private double
Speed for zoom. -
Constructor Summary
ConstructorsConstructorDescriptionTrackballControls
(Object3D camera, Widget widget) Creates a new instance of TrackballControls for the 3D scene displayed inwidget
as seen from thecamera
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Free resources.private Vector2
getMouseOnScreen
(int clientX, int clientY) Re-scale pointer coordinates to[0, 1]2
.private Vector3
getMouseProjectionOnBall
(int clientX, int clientY) Convert pointer coordinates to coordinates on (virtual) trackball (unit sphere).Get the target point where the eye is looking.boolean
Check if trackball controls are enabled.void
onMouseDown
(MouseDownEvent event) void
onMouseMove
(MouseMoveEvent event) void
onMouseUp
(MouseUpEvent event) void
onMouseWheel
(MouseWheelEvent event) void
onResize()
void
onTouchEnd
(TouchEndEvent event) void
onTouchMove
(TouchMoveEvent event) void
onTouchStart
(TouchStartEvent event) private void
Update eye and target for (dynamical) panning.private void
Update eye and target for (dynamical) rotating.void
setDynamicDampingFactor
(double dynamicDampingFactor) Set dynamic damping factor (default:0.2
).void
setDynamicUpdate
(boolean dynamic) Enable/disable dynamic moving of 3D view (default: enabled).void
setEnabled
(boolean isEnabled) Enable/disable trackball controls (default: enabled).void
setPan
(boolean pan) Enable/disable pan (default: enabled).void
setPanSpeed
(double panSpeed) Set pan speed (default:0.3
).void
setRotate
(boolean rotate) Enable/disable rotation (default: enabled).void
setRotateSpeed
(double rotateSpeed) Set rotation speed (default:1.0
).void
Set the target point where the eye is looking.void
setZoom
(boolean zoom) Enable/disable zoom (default: enabled).void
setZoomSpeed
(double zoomSpeed) Set zoom speed (default:1.2
).void
update()
Update the view of the 3D scene.void
zoom()
Reset zoom.void
zoom
(double zoom) Set zoom factor.private void
Update eye and target for zooming.
-
Field Details
-
MAX_EYE_DIST
private static final double MAX_EYE_DISTMaximum eye distance. How far you can zoom out.- See Also:
-
MAX_EYE_DIST_SQ
private static final double MAX_EYE_DIST_SQSquare of maximum eye distance.- See Also:
-
MIN_EYE_DIST
private static final double MIN_EYE_DISTMinimum eye distance. How far you can zoom in.- See Also:
-
initialDistance
double initialDistanceInitial eye distance. -
MIN_EYE_DIST_SQ
private static final double MIN_EYE_DIST_SQSquare of minimum eye distance.- See Also:
-
ZOOM_INCR
protected static final double ZOOM_INCRDefault increments of zoom factor (multiplicative).- See Also:
-
isEnabled
private boolean isEnabledtrue
if trackball controls enabled. -
rotateSpeed
private double rotateSpeedSpeed of rotation; -
zoomSpeed
private double zoomSpeedSpeed for zoom. -
panSpeed
private double panSpeedSpeed for panning (shifting). -
zoomChange
private double zoomChangeUtility variable to keep track of changes of zoom factor while zooming. -
hasRotate
private boolean hasRotateFlag indicating whether rotation is enabled. -
hasZoom
private boolean hasZoomFlag indicating whether zooming is enabled. -
hasPan
private boolean hasPanFlag indicating whether panning is enabled. -
doRotate
private boolean doRotatetrue
if rotation is pending. -
doZoom
private boolean doZoomtrue
if zooming is pending. -
doPan
private boolean doPantrue
if panning is pending. -
isDragging
private boolean isDraggingtrue
while the pointer is dragging. -
isDynamicUpdate
private boolean isDynamicUpdatetrue
to disable dynamic damping of changes to the view.. -
dynamicDampingFactor
private double dynamicDampingFactorFactor for dynamic damping of changes to the view. -
radius
private double radiusRadius of trackball. Depends on size of associated widget that displays the 3D scene. -
target
Target point eye is looking at. -
eye
Location of eye. -
rotateStart
Starting coordinates on trackball for rotations. -
rotateEnd
End coordinates on trackball for rotations. -
panStart
Starting coordinates on trackball for panning. -
panEnd
End coordinates on trackball for panning. -
mouseWheelHandler
Mouse and touch handlers to control the view of the 3D scene. -
mouseDownHandler
Mouse and touch handlers to control the view of the 3D scene. -
mouseMoveHandler
Mouse and touch handlers to control the view of the 3D scene. -
mouseUpHandler
Mouse and touch handlers to control the view of the 3D scene. -
touchStartHandler
Mouse and touch handlers to control the view of the 3D scene. -
touchMoveHandler
Mouse and touch handlers to control the view of the 3D scene. -
touchEndHandler
Mouse and touch handlers to control the view of the 3D scene. -
t
Timer for reseting the CSS styling after zooming. -
pinchZoom
private double pinchZoomHelper variable to keep track of the distance of two touches between subsequent touch events. -
mouseOnBall
The mouse coordinates on the virtual trackball.
-
-
Constructor Details
-
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 iftrue
-
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 iftrue
-
setZoom
public void setZoom(boolean zoom) Enable/disable zoom (default: enabled).- Parameters:
zoom
- enables zoom iftrue
-
setPan
public void setPan(boolean pan) Enable/disable pan (default: enabled).- Parameters:
pan
- enables panning iftrue
-
setDynamicUpdate
public void setDynamicUpdate(boolean dynamic) Enable/disable dynamic moving of 3D view (default: enabled).- Parameters:
dynamic
- enables dynamic updates of 3D view iftrue
-
setDynamicDampingFactor
public void setDynamicDampingFactor(double dynamicDampingFactor) Set dynamic damping factor (default:0.2
).- Parameters:
dynamicDampingFactor
- the factor for dynamic damping of
-
getTarget
Get the target point where the eye is looking.- Returns:
- the target point
-
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 interfaceRequiresResize
-
onMouseWheel
Zooms the 3D view.
- Specified by:
onMouseWheel
in interfaceMouseWheelHandler
-
onMouseDown
Marks the potential start of updates to the view of the 3D scene.
- Specified by:
onMouseDown
in interfaceMouseDownHandler
-
onMouseUp
If the left mouse button was released this marks the end updates to the view of the 3D scene.
- Specified by:
onMouseUp
in interfaceMouseUpHandler
-
onMouseMove
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 interfaceMouseMoveHandler
-
onTouchStart
Marks the potential start of updates to the view of the 3D scene.
- Specified by:
onTouchStart
in interfaceTouchStartHandler
-
onTouchMove
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 interfaceTouchMoveHandler
-
onTouchEnd
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 interfaceTouchEndHandler
-
getMouseOnScreen
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
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.
-