Class OrbitBehavior
- java.lang.Object
-
- All Implemented Interfaces:
java.awt.event.KeyListener,java.awt.event.MouseListener,java.awt.event.MouseMotionListener,java.awt.event.MouseWheelListener,java.util.EventListener
public class OrbitBehavior extends ViewPlatformAWTBehavior
Moves the View around a point of interest when the mouse is dragged with a mouse button pressed. Includes rotation, zoom, and translation actions. Zooming can also be obtained by using mouse wheel.This behavior must be added to the ViewingPlatform using the
ViewingPlatform.setViewPlatformBehaviormethod.The rotate action rotates the ViewPlatform around the point of interest when the mouse is moved with the main mouse button pressed. The rotation is in the direction of the mouse movement, with a default rotation of 0.01 radians for each pixel of mouse movement.
The zoom action moves the ViewPlatform closer to or further from the point of interest when the mouse is moved with the middle mouse button pressed (or Alt-main mouse button on systems without a middle mouse button). The default zoom action is to translate the ViewPlatform 0.01 units for each pixel of mouse movement. Moving the mouse up moves the ViewPlatform closer, moving the mouse down moves the ViewPlatform further away.
By default, the zoom action allows the ViewPlatform to move through the center of rotation to orbit at a negative radius. The
STOP_ZOOMconstructor flag will stop the ViewPlatform at a minimum radius from the center. The default minimum radius is 0.0 and can be set using thesetMinRadiusmethod.The
PROPORTIONAL_ZOOMconstructor flag changes the zoom action to move the ViewPlatform proportional to its distance from the center of rotation. For this mode, the default action is to move the ViewPlatform by 1% of its distance from the center of rotation for each pixel of mouse movement.The translate action translates the ViewPlatform when the mouse is moved with the right mouse button pressed (Shift-main mouse button on systems without a right mouse button). The translation is in the direction of the mouse movement, with a default translation of 0.01 units for each pixel of mouse movement.
The sensitivity of the actions can be scaled using the
setActionFactor()methods which scale the default movement by the factor. The rotate and translate actions have separate factors for x and y.The actions can be reversed using the
REVERSE_ACTION constructor flags. The default action moves the ViewPlatform around the objects in the scene. TheREVERSE_ACTION flags can make the objects in the scene appear to be moving in the direction of the mouse movement.The actions can be disabled by either using the
DISABLE_ACTION constructor flags or thesetActionEnablemethods.The default center of rotation is (0, 0, 0) and can be set using the
setRotationCenter()method.- Since:
- Java 3D 1.2.1
-
-
Field Summary
Fields Modifier and Type Field Description static intDISABLE_ROTATEConstructor flag to disable rotatestatic intDISABLE_TRANSLATEConstructor flag to disable translatestatic intDISABLE_ZOOMConstructor flag to disable zoomstatic intPROPORTIONAL_ZOOMConstructor flag to use proportional zoom, which determines how much you zoom based on view's distance from the center of rotation.static intREVERSE_ALLConstructor flag to reverse all the behaviorsstatic intREVERSE_ROTATEConstructor flag to reverse the rotate behaviorstatic intREVERSE_TRANSLATEConstructor flag to reverse the translate behaviorstatic intREVERSE_ZOOMConstructor flag to reverse the zoom behaviorstatic intSTOP_ZOOMConstructor flag that indicates zoom should stop when it reaches the minimum orbit radius set by setMinRadius().-
Fields inherited from class com.sun.j3d.utils.behaviors.vp.ViewPlatformAWTBehavior
canvases, frameWakeup, KEY_LISTENER, motion, MOUSE_LISTENER, MOUSE_MOTION_LISTENER, MOUSE_WHEEL_LISTENER, POST_ID, postWakeup, targetTransform
-
Fields inherited from class com.sun.j3d.utils.behaviors.vp.ViewPlatformBehavior
homeTransform, targetTG, vp
-
Fields inherited from class javax.media.j3d.Node
ALLOW_AUTO_COMPUTE_BOUNDS_READ, ALLOW_AUTO_COMPUTE_BOUNDS_WRITE, ALLOW_BOUNDS_READ, ALLOW_BOUNDS_WRITE, ALLOW_COLLIDABLE_READ, ALLOW_COLLIDABLE_WRITE, ALLOW_LOCAL_TO_VWORLD_READ, ALLOW_LOCALE_READ, ALLOW_PARENT_READ, ALLOW_PICKABLE_READ, ALLOW_PICKABLE_WRITE, ENABLE_COLLISION_REPORTING, ENABLE_PICK_REPORTING
-
-
Constructor Summary
Constructors Constructor Description OrbitBehavior()Parameterless constructor for this behavior.OrbitBehavior(Canvas3D c)Creates a new OrbitBehaviorOrbitBehavior(Canvas3D c, int flags)Creates a new OrbitBehavior
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetMinRadius()Returns the minimum orbit radius.booleangetRotateEnable()Retrieves the state of rotate enabledvoidgetRotationCenter(javax.vecmath.Point3d center)Places the value of the center around which the View rotates into the Point3d.doublegetRotXFactor()Returns the x rotation movement multiplierdoublegetRotYFactor()Returns the y rotation movement multiplierbooleangetTranslateEnable()Retrieves the state of translate enableddoublegetTransXFactor()Returns the x translation movement multiplierdoublegetTransYFactor()Returns the y translation movement multiplierbooleangetZoomEnable()Retrieves the state of zoom enableddoublegetZoomFactor()Returns the zoom movement multiplierprotected voidintegrateTransforms()Called once per frame (if the view is moving) to calculate the new view platform transformvoidMinRadius(java.lang.Object[] r)Property which sets the minimum radius for the OrbitBehavior.protected voidprocessAWTEvents(java.awt.AWTEvent[] events)This is called once per frame if there are any AWT events to process.protected voidprocessMouseEvent(java.awt.event.MouseEvent evt)voidProportionalZoom(java.lang.Object[] state)Property which sets proportional zoom behavior.voidReverseRotate(java.lang.Object[] state)Property which sets reverse rotate behavior.voidReverseTranslate(java.lang.Object[] state)Property which sets reverse translate behavior.voidReverseZoom(java.lang.Object[] state)Property which sets reverse zoom behavior.voidRotateEnable(java.lang.Object[] enabled)Property which enables or disables rotation.voidRotationCenter(java.lang.Object[] center)Property which sets the center around which the View rotates.voidRotFactors(java.lang.Object[] factors)Property which sets the rotation x and y factors.voidRotXFactor(java.lang.Object[] xFactor)Property which sets the rotation x factor.voidRotYFactor(java.lang.Object[] yFactor)Property which sets the rotation y factor.voidsetMinRadius(double r)Sets the minimum radius for the OrbitBehavior.voidsetProportionalZoom(boolean state)Set proportional zoom behavior.voidsetReverseRotate(boolean state)Set reverse rotate behavior.voidsetReverseTranslate(boolean state)Set reverse translate behavior.voidsetReverseZoom(boolean state)Set reverse zoom behavior.voidsetRotateEnable(boolean enabled)Enables or disables rotation.voidsetRotationCenter(javax.vecmath.Point3d center)Sets the center around which the View rotates.voidsetRotFactors(double xfactor, double yfactor)Sets the rotation x and y factors.voidsetRotXFactor(double xfactor)Sets the rotation x factor.voidsetRotYFactor(double yfactor)Sets the rotation y factor.voidsetTransFactors(double xfactor, double yfactor)Sets the translation x and y factors.voidsetTranslateEnable(boolean enabled)Enables or disables translate.voidsetTransXFactor(double xfactor)Sets the translation x factor.voidsetTransYFactor(double yfactor)Sets the translation y factor.voidsetViewingPlatform(ViewingPlatform vp)Sets the ViewingPlatform for this behavior.voidsetZoomEnable(boolean enabled)Enables or disables zoom.voidsetZoomFactor(double zfactor)Sets the zoom factor.voidTransFactors(java.lang.Object[] factors)Property which sets the translation x and y factors.voidTranslateEnable(java.lang.Object[] enabled)Property which enables or disables translate.voidTransXFactor(java.lang.Object[] xFactor)Property which sets the translation x factor.voidTransYFactor(java.lang.Object[] yFactor)Property which sets the translation y factor.voidZoomEnable(java.lang.Object[] enabled)Property which enables or disables zoom.voidZoomFactor(java.lang.Object[] zFactor)Property which sets the zoom factor.-
Methods inherited from class com.sun.j3d.utils.behaviors.vp.ViewPlatformAWTBehavior
initialize, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, processStimulus, queueAWTEvent, setEnable, setListenerFlags
-
Methods inherited from class com.sun.j3d.utils.behaviors.vp.ViewPlatformBehavior
getHomeTransform, getViewingPlatform, goHome, setHomeTransform
-
Methods inherited from class javax.media.j3d.Behavior
getEnable, getNumSchedulingIntervals, getSchedulingBoundingLeaf, getSchedulingBounds, getSchedulingInterval, getView, getWakeupCondition, postId, setSchedulingBoundingLeaf, setSchedulingBounds, setSchedulingInterval, updateNodeReferences, wakeupOn
-
Methods inherited from class javax.media.j3d.Node
cloneNode, cloneTree, cloneTree, cloneTree, cloneTree, cloneTree, cloneTree, duplicateNode, getBounds, getBoundsAutoCompute, getCollidable, getLocale, getLocalToVworld, getLocalToVworld, getParent, getPickable, setBounds, setBoundsAutoCompute, setCollidable, setPickable
-
Methods inherited from class javax.media.j3d.SceneGraphObject
clearCapability, clearCapabilityIsFrequent, duplicateSceneGraphObject, getCapability, getCapabilityIsFrequent, getName, getUserData, isCompiled, isLive, setCapability, setCapabilityIsFrequent, setName, setUserData, toString
-
-
-
-
Field Detail
-
REVERSE_ROTATE
public static final int REVERSE_ROTATE
Constructor flag to reverse the rotate behavior- See Also:
- Constant Field Values
-
REVERSE_TRANSLATE
public static final int REVERSE_TRANSLATE
Constructor flag to reverse the translate behavior- See Also:
- Constant Field Values
-
REVERSE_ZOOM
public static final int REVERSE_ZOOM
Constructor flag to reverse the zoom behavior- See Also:
- Constant Field Values
-
REVERSE_ALL
public static final int REVERSE_ALL
Constructor flag to reverse all the behaviors- See Also:
- Constant Field Values
-
STOP_ZOOM
public static final int STOP_ZOOM
Constructor flag that indicates zoom should stop when it reaches the minimum orbit radius set by setMinRadius(). The minimus radius default is 0.0.- See Also:
- Constant Field Values
-
DISABLE_ROTATE
public static final int DISABLE_ROTATE
Constructor flag to disable rotate- See Also:
- Constant Field Values
-
DISABLE_TRANSLATE
public static final int DISABLE_TRANSLATE
Constructor flag to disable translate- See Also:
- Constant Field Values
-
DISABLE_ZOOM
public static final int DISABLE_ZOOM
Constructor flag to disable zoom- See Also:
- Constant Field Values
-
PROPORTIONAL_ZOOM
public static final int PROPORTIONAL_ZOOM
Constructor flag to use proportional zoom, which determines how much you zoom based on view's distance from the center of rotation. The percentage of distance that the viewer zooms is determined by the zoom factor.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OrbitBehavior
public OrbitBehavior()
Parameterless constructor for this behavior. This is intended for use by ConfiguredUniverse, which requires such a constructor for configurable behaviors. The Canvas3D used to listen for mouse and mouse motion events is obtained from the superclass setViewingPlatform() method.- Since:
- Java 3D 1.3
-
OrbitBehavior
public OrbitBehavior(Canvas3D c)
Creates a new OrbitBehavior- Parameters:
c- The Canvas3D to add the behavior to
-
OrbitBehavior
public OrbitBehavior(Canvas3D c, int flags)
Creates a new OrbitBehavior- Parameters:
c- The Canvas3D to add the behavior toflags- The option flags
-
-
Method Detail
-
processAWTEvents
protected void processAWTEvents(java.awt.AWTEvent[] events)
Description copied from class:ViewPlatformAWTBehaviorThis is called once per frame if there are any AWT events to process. Themotionvariable will be true when the method is called. If it is true when the method returns integrateTransforms will be called immediately. The AWTEvents are presented in the array in the order in which they arrived from AWT.- Specified by:
processAWTEventsin classViewPlatformAWTBehavior
-
processMouseEvent
protected void processMouseEvent(java.awt.event.MouseEvent evt)
-
setViewingPlatform
public void setViewingPlatform(ViewingPlatform vp)
Sets the ViewingPlatform for this behavior. This method is called by the ViewingPlatform. If a sub-calls overrides this method, it must call super.setViewingPlatform(vp). NOTE: Applications should not call this method.- Overrides:
setViewingPlatformin classViewPlatformAWTBehavior- Parameters:
vp- the target ViewingPlatform for this behavior
-
integrateTransforms
protected void integrateTransforms()
Description copied from class:ViewPlatformAWTBehaviorCalled once per frame (if the view is moving) to calculate the new view platform transform- Specified by:
integrateTransformsin classViewPlatformAWTBehavior
-
setRotationCenter
public void setRotationCenter(javax.vecmath.Point3d center)
Sets the center around which the View rotates. The default is (0,0,0).- Parameters:
center- The Point3d to set the center of rotation to
-
RotationCenter
public void RotationCenter(java.lang.Object[] center)
Property which sets the center around which the View rotates. Used by ConfiguredUniverse.- Parameters:
center- array of length 1 containing an instance of Point3d- Since:
- Java 3D 1.3
-
getRotationCenter
public void getRotationCenter(javax.vecmath.Point3d center)
Places the value of the center around which the View rotates into the Point3d.- Parameters:
center- The Point3d
-
setRotFactors
public void setRotFactors(double xfactor, double yfactor)Sets the rotation x and y factors. The factors are used to determine how many radians to rotate the view for each pixel of mouse movement. The view is rotated factor * 0.01 radians for each pixel of mouse movement. The default factor is 1.0.- Parameters:
xfactor- The x movement multiplieryfactor- The y movement multiplier
-
RotFactors
public void RotFactors(java.lang.Object[] factors)
Property which sets the rotation x and y factors. Used by ConfiguredUniverse.- Parameters:
factors- array of length 2 containing instances of Double- Since:
- Java 3D 1.3
-
setRotXFactor
public void setRotXFactor(double xfactor)
Sets the rotation x factor. The factors are used to determine how many radians to rotate the view for each pixel of mouse movement. The view is rotated factor * 0.01 radians for each pixel of mouse movement. The default factor is 1.0.- Parameters:
xfactor- The x movement multiplier
-
RotXFactor
public void RotXFactor(java.lang.Object[] xFactor)
Property which sets the rotation x factor. Used by ConfiguredUniverse.- Parameters:
xFactor- array of length 1 containing instance of Double- Since:
- Java 3D 1.3
-
setRotYFactor
public void setRotYFactor(double yfactor)
Sets the rotation y factor. The factors are used to determine how many radians to rotate the view for each pixel of mouse movement. The view is rotated factor * 0.01 radians for each pixel of mouse movement. The default factor is 1.0.- Parameters:
yfactor- The y movement multiplier
-
RotYFactor
public void RotYFactor(java.lang.Object[] yFactor)
Property which sets the rotation y factor. Used by ConfiguredUniverse.- Parameters:
yFactor- array of length 1 containing instance of Double- Since:
- Java 3D 1.3
-
setTransFactors
public void setTransFactors(double xfactor, double yfactor)Sets the translation x and y factors. The factors are used to determine how many units to translate the view for each pixel of mouse movement. The view is translated factor * 0.01 units for each pixel of mouse movement. The default factor is 1.0.- Parameters:
xfactor- The x movement multiplieryfactor- The y movement multiplier
-
TransFactors
public void TransFactors(java.lang.Object[] factors)
Property which sets the translation x and y factors. Used by ConfiguredUniverse.- Parameters:
factors- array of length 2 containing instances of Double- Since:
- Java 3D 1.3
-
setTransXFactor
public void setTransXFactor(double xfactor)
Sets the translation x factor. The factors are used to determine how many units to translate the view for each pixel of mouse movement. The view is translated factor * 0.01 units for each pixel of mouse movement. The default factor is 1.0.- Parameters:
xfactor- The x movement multiplier
-
TransXFactor
public void TransXFactor(java.lang.Object[] xFactor)
Property which sets the translation x factor. Used by ConfiguredUniverse.- Parameters:
xFactor- array of length 1 containing instance of Double- Since:
- Java 3D 1.3
-
setTransYFactor
public void setTransYFactor(double yfactor)
Sets the translation y factor. The factors are used to determine how many units to translate the view for each pixel of mouse movement. The view is translated factor * 0.01 units for each pixel of mouse movement. The default factor is 1.0.- Parameters:
yfactor- The y movement multiplier
-
TransYFactor
public void TransYFactor(java.lang.Object[] yFactor)
Property which sets the translation y factor. Used by ConfiguredUniverse.- Parameters:
yFactor- array of length 1 containing instance of Double- Since:
- Java 3D 1.3
-
setZoomFactor
public void setZoomFactor(double zfactor)
Sets the zoom factor. The factor is used to determine how many units to zoom the view for each pixel of mouse movement. The view is zoomed factor * 0.01 units for each pixel of mouse movement. For proportional zoom, the view is zoomed factor * 1% of the distance from the center of rotation for each pixel of mouse movement. The default factor is 1.0.- Parameters:
zfactor- The movement multiplier
-
ZoomFactor
public void ZoomFactor(java.lang.Object[] zFactor)
Property which sets the zoom factor. Used by ConfiguredUniverse.- Parameters:
zFactor- array of length 1 containing instance of Double- Since:
- Java 3D 1.3
-
getRotXFactor
public double getRotXFactor()
Returns the x rotation movement multiplier- Returns:
- The movement multiplier for x rotation
-
getRotYFactor
public double getRotYFactor()
Returns the y rotation movement multiplier- Returns:
- The movement multiplier for y rotation
-
getTransXFactor
public double getTransXFactor()
Returns the x translation movement multiplier- Returns:
- The movement multiplier for x translation
-
getTransYFactor
public double getTransYFactor()
Returns the y translation movement multiplier- Returns:
- The movement multiplier for y translation
-
getZoomFactor
public double getZoomFactor()
Returns the zoom movement multiplier- Returns:
- The movement multiplier for zoom
-
setRotateEnable
public void setRotateEnable(boolean enabled)
Enables or disables rotation. The default is true.- Parameters:
enabled- true or false to enable or disable rotate
-
RotateEnable
public void RotateEnable(java.lang.Object[] enabled)
Property which enables or disables rotation. Used by ConfiguredUniverse.- Parameters:
enabled- array of length 1 containing instance of Boolean- Since:
- Java 3D 1.3
-
setZoomEnable
public void setZoomEnable(boolean enabled)
Enables or disables zoom. The default is true.- Parameters:
enabled- true or false to enable or disable zoom
-
ZoomEnable
public void ZoomEnable(java.lang.Object[] enabled)
Property which enables or disables zoom. Used by ConfiguredUniverse.- Parameters:
enabled- array of length 1 containing instance of Boolean- Since:
- Java 3D 1.3
-
setTranslateEnable
public void setTranslateEnable(boolean enabled)
Enables or disables translate. The default is true.- Parameters:
enabled- true or false to enable or disable translate
-
TranslateEnable
public void TranslateEnable(java.lang.Object[] enabled)
Property which enables or disables translate. Used by ConfiguredUniverse.- Parameters:
enabled- array of length 1 containing instance of Boolean- Since:
- Java 3D 1.3
-
getRotateEnable
public boolean getRotateEnable()
Retrieves the state of rotate enabled- Returns:
- the rotate enable state
-
getZoomEnable
public boolean getZoomEnable()
Retrieves the state of zoom enabled- Returns:
- the zoom enable state
-
getTranslateEnable
public boolean getTranslateEnable()
Retrieves the state of translate enabled- Returns:
- the translate enable state
-
setMinRadius
public void setMinRadius(double r)
Sets the minimum radius for the OrbitBehavior. The zoom will stop at this distance from the center of rotation. The default is 0.0. The minimum will have no affect if the STOP_ZOOM constructor flag is not set.- Parameters:
r- the minimum radius- Throws:
java.lang.IllegalArgumentException- if the radius is less than 0.0
-
MinRadius
public void MinRadius(java.lang.Object[] r)
Property which sets the minimum radius for the OrbitBehavior. Used by ConfiguredUniverse.- Parameters:
r- array of length 1 containing instance of Double- Since:
- Java 3D 1.3
-
getMinRadius
public double getMinRadius()
Returns the minimum orbit radius. The zoom will stop at this distance from the center of rotation if the STOP_ZOOM constructor flag is set.- Returns:
- the minimum radius
-
setReverseTranslate
public void setReverseTranslate(boolean state)
Set reverse translate behavior. The default is false.- Parameters:
state- if true, reverse translate behavior- Since:
- Java 3D 1.3
-
ReverseTranslate
public void ReverseTranslate(java.lang.Object[] state)
Property which sets reverse translate behavior. Used by ConfiguredUniverse.- Parameters:
state- array of length 1 containing instance of Boolean- Since:
- Java 3D 1.3
-
setReverseRotate
public void setReverseRotate(boolean state)
Set reverse rotate behavior. The default is false.- Parameters:
state- if true, reverse rotate behavior- Since:
- Java 3D 1.3
-
ReverseRotate
public void ReverseRotate(java.lang.Object[] state)
Property which sets reverse rotate behavior. Used by ConfiguredUniverse.- Parameters:
state- array of length 1 containing instance of Boolean- Since:
- Java 3D 1.3
-
setReverseZoom
public void setReverseZoom(boolean state)
Set reverse zoom behavior. The default is false.- Parameters:
state- if true, reverse zoom behavior- Since:
- Java 3D 1.3
-
ReverseZoom
public void ReverseZoom(java.lang.Object[] state)
Property which sets reverse zoom behavior. Used by ConfiguredUniverse.- Parameters:
state- array of length 1 containing instance of Boolean- Since:
- Java 3D 1.3
-
setProportionalZoom
public void setProportionalZoom(boolean state)
Set proportional zoom behavior. The default is false.- Parameters:
state- if true, use proportional zoom behavior- Since:
- Java 3D 1.3
-
ProportionalZoom
public void ProportionalZoom(java.lang.Object[] state)
Property which sets proportional zoom behavior. Used by ConfiguredUniverse.- Parameters:
state- array of length 1 containing instance of Boolean- Since:
- Java 3D 1.3
-
-