Xj3D 2.0 VRML/X3D Code API

org.web3d.vrml.renderer.ogl.input
Class DefaultUserInputHandler

java.lang.Object
  extended by org.web3d.vrml.renderer.ogl.input.DefaultUserInputHandler
All Implemented Interfaces:
NavigationInfoChangeListener, OGLUserInputHandler, UserInputHandler

public class DefaultUserInputHandler
extends java.lang.Object
implements OGLUserInputHandler, NavigationInfoChangeListener

A complete handler for all user input information within a scene.

The handler takes care of all the handling needed for sensors, anchors, navigation and keyboard. However, it does not define a way of sourcing those events as it assumes that a user will either delegate or extend this class with more specific information such as an AWT listener or Java3D behavior.

The current key handling does not allow keyboard navigation of the world. It passes all key events directly through to the current key sensor if one is registered.

Version:
$Revision: 1.48 $
Author:
Justin Couch

Constructor Summary
DefaultUserInputHandler()
          Create a new instance of this class so that we can process events and send them into the VRML scene.
 
Method Summary
 void addNavigationStateListener(NavigationStateListener l)
          Add a listener for navigation state changes.
 void addSensorStatusListener(SensorStatusListener l)
          Add a listener for navigation state changes.
 void clear()
          Clear all the values, listeners etc, except for the clock.
 boolean getNavigationEnabled()
          Get the currently set navigation state.
 void getOrientation(javax.vecmath.AxisAngle4f ori)
          Get the current user orientation.
 void getPosition(javax.vecmath.Vector3f pos)
          Get the current user position.
 void notifyAvatarSizeChanged(float[] size, int numValid)
          Notification that the avatar size has changed on the current NavigationInfo node.
 void notifyHeadlightChanged(boolean enable)
          Notification that headlight state has changed.
 void notifyNavigationModesChanged(java.lang.String[] newModes, int numValid)
          Notification that the navigation modes allowed has changed on the current NavigationInfo node.
 void notifyNavigationSpeedChanged(float newSpeed)
          Notification that the navigation speed has changed on the current NavigationInfo node.
 void notifyVisibilityLimitChanged(float distance)
          Notification that the visibility limit has been changed.
 void processNavigation()
          Process any navigation velocity.
 void removeNavigationStateListener(NavigationStateListener l)
          Remove a navigation state listener.
 void removeSensorStatusListener(SensorStatusListener l)
          Remove a navigation state listener.
 void sendCurrentNavState()
          The layer that contains this handler has just been made the active navigation layer, so send out to the navigation state listeners the current navigation state for this layer.
 void setActivateSensors(boolean val)
          Sets whether this tracker is eligible to active a sensor.
 void setCenterOfRotation(float[] center)
          Set the center of rotation explicitly to this place.
 void setCollisionListener(CollisionListener l)
          Set the listener for collision notifications.
 void setNavigationEnabled(boolean state)
          Enable or disable navigation processing sub-section of the user input processing.
 void setNavigationInfo(VRMLNavigationInfoNodeType navInfo)
          Set the navigation info that is used for this scene.
 boolean setNavigationMode(java.lang.String mode)
          Set the desired navigation mode.
 void setPickableScene(org.j3d.aviatrix3d.Group scene)
          Set the world group that we are doing the picking on.
 void setTestPointingDevices(boolean enabled)
          Should pointing devices be tested for.
 void setViewInfo(OGLViewpointNodeType vp, org.j3d.aviatrix3d.TransformGroup tg, org.j3d.aviatrix3d.SceneGraphPath path)
          Set the view and it's related transform group to use and the path to get there from the root of the scene.
 void setVRMLClock(VRMLClock clk)
          Set the clock we are going to operate from when generating events.
 void setWorldScale(float scale)
          Set the world scale applied.
 void trackerButton(int tracker, TrackerState state)
          Process the buttons on a tracker.
 void trackerClicked(int tracker, TrackerState state)
          Process a tracker click event.
 void trackerDragged(int tracker, TrackerState state)
          Process a tracker press event.
 boolean trackerIntersected()
          Did the last tracker interaction intersect any active sensors.
 void trackerMoved(int tracker, TrackerState evt)
          Process a tracker moved event.
 void trackerOrientation(int tracker, TrackerState state)
          Process tracker orientation events.
 void trackerPressed(int tracker, TrackerState evt)
          Process a tracker press event.
 void trackerReleased(int tracker, TrackerState state)
          Process a tracker press event.
 void trackerWheel(int tracker, TrackerState state)
          Process a tracker wheel event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultUserInputHandler

public DefaultUserInputHandler()
Create a new instance of this class so that we can process events and send them into the VRML scene. The initial state is set to none.

Method Detail

notifyNavigationModesChanged

public void notifyNavigationModesChanged(java.lang.String[] newModes,
                                         int numValid)
Notification that the navigation modes allowed has changed on the current NavigationInfo node.

Specified by:
notifyNavigationModesChanged in interface NavigationInfoChangeListener
Parameters:
newModes - The new allowed navigation modes
numValid - number of valid modes in array

notifyAvatarSizeChanged

public void notifyAvatarSizeChanged(float[] size,
                                    int numValid)
Notification that the avatar size has changed on the current NavigationInfo node.

Specified by:
notifyAvatarSizeChanged in interface NavigationInfoChangeListener
Parameters:
size - The size parameters for the avatar
numValid - number of valid modes in array

notifyNavigationSpeedChanged

public void notifyNavigationSpeedChanged(float newSpeed)
Notification that the navigation speed has changed on the current NavigationInfo node.

Specified by:
notifyNavigationSpeedChanged in interface NavigationInfoChangeListener
Parameters:
newSpeed - The new navigation speed.

notifyVisibilityLimitChanged

public void notifyVisibilityLimitChanged(float distance)
Notification that the visibility limit has been changed.

Specified by:
notifyVisibilityLimitChanged in interface NavigationInfoChangeListener
Parameters:
distance - The new distance value to use

notifyHeadlightChanged

public void notifyHeadlightChanged(boolean enable)
Notification that headlight state has changed.

Specified by:
notifyHeadlightChanged in interface NavigationInfoChangeListener
Parameters:
enable - true if the headlight should now be on

getNavigationEnabled

public boolean getNavigationEnabled()
Get the currently set navigation state.

Specified by:
getNavigationEnabled in interface UserInputHandler
Returns:
true for the current state

setNavigationEnabled

public void setNavigationEnabled(boolean state)
Enable or disable navigation processing sub-section of the user input processing. By default the navigation processing is enabled.

Specified by:
setNavigationEnabled in interface UserInputHandler
Parameters:
state - true to enable navigation

setPickableScene

public void setPickableScene(org.j3d.aviatrix3d.Group scene)
Set the world group that we are doing the picking on. This allows us to look for the picked items in the scene. A null value is used to clear the world and disable picking behaviours.

Specified by:
setPickableScene in interface OGLUserInputHandler
Parameters:
scene - The scene to pick against

setViewInfo

public void setViewInfo(OGLViewpointNodeType vp,
                        org.j3d.aviatrix3d.TransformGroup tg,
                        org.j3d.aviatrix3d.SceneGraphPath path)
                 throws java.lang.IllegalArgumentException
Set the view and it's related transform group to use and the path to get there from the root of the scene. The transform group must allow for reading the local to Vworld coordinates so that we can accurately implement terrain following. A null value for the path is permitted.

This will also automatically set the center of rotation.

Specified by:
setViewInfo in interface OGLUserInputHandler
Parameters:
vp - The current viewpoint
tg - The transform just about the viewpoint used to move it around in response to the UI device input
path - The path from the root to the transform to use
Throws:
java.lang.IllegalArgumentException - The terminal node is not a viewpoint

setCenterOfRotation

public void setCenterOfRotation(float[] center)
Set the center of rotation explicitly to this place. Coordinates must be in the coordinate space of the current view transform group. The provided array must be of least length 3. Center of rotation is used in examine mode.

Specified by:
setCenterOfRotation in interface UserInputHandler
Parameters:
center - The new center to use

setVRMLClock

public void setVRMLClock(VRMLClock clk)
Set the clock we are going to operate from when generating events. A null value will remove the clock.

Specified by:
setVRMLClock in interface UserInputHandler
Parameters:
clk - The new clock to use

setCollisionListener

public void setCollisionListener(CollisionListener l)
Set the listener for collision notifications. By setting a value of null it will clear the currently set instance

Specified by:
setCollisionListener in interface OGLUserInputHandler
Parameters:
l - The listener to use for change updates

setNavigationInfo

public void setNavigationInfo(VRMLNavigationInfoNodeType navInfo)
Set the navigation info that is used for this scene. The canvas can then use it to build any user interface interactions it desires. A value of null will remove the info and is typically used when the canvas is about to be removed from a universe.

Specified by:
setNavigationInfo in interface UserInputHandler
Parameters:
navInfo - The new navigation information to be used

setTestPointingDevices

public void setTestPointingDevices(boolean enabled)
Should pointing devices be tested for.

Specified by:
setTestPointingDevices in interface UserInputHandler
Parameters:
enabled - Test for intersection when true

trackerButton

public void trackerButton(int tracker,
                          TrackerState state)
Process the buttons on a tracker. No other state will be read.

Specified by:
trackerButton in interface UserInputHandler
Parameters:
tracker - The tracker generating the event.
state - The current state.

trackerPressed

public void trackerPressed(int tracker,
                           TrackerState evt)
Process a tracker press event. This may be used to start a TouchSensor start of a drag sensor or navigation

Specified by:
trackerPressed in interface UserInputHandler
Parameters:
evt - The event that caused the method to be called
tracker - The id of the tracker calling this handler

trackerMoved

public void trackerMoved(int tracker,
                         TrackerState evt)
Process a tracker moved event.

Specified by:
trackerMoved in interface UserInputHandler
Parameters:
evt - The event that caused the method to be called
tracker - The id of the tracker calling this handler

trackerIntersected

public boolean trackerIntersected()
Did the last tracker interaction intersect any active sensors.

Specified by:
trackerIntersected in interface UserInputHandler
Returns:
true if the tracker intersection an active sensor.

setActivateSensors

public void setActivateSensors(boolean val)
Sets whether this tracker is eligible to active a sensor.

Specified by:
setActivateSensors in interface UserInputHandler
Parameters:
val - Whether its eligible

trackerDragged

public void trackerDragged(int tracker,
                           TrackerState state)
Process a tracker press event. This may be used to start a touchtracker, start of a drag tracker or navigation

Specified by:
trackerDragged in interface UserInputHandler
Parameters:
tracker - The id of the tracker that was released
state - The state of the tracker right now

trackerWheel

public void trackerWheel(int tracker,
                         TrackerState state)
Process a tracker wheel event.

Specified by:
trackerWheel in interface UserInputHandler
Parameters:
tracker - The id of the tracker calling this handler
state - The current state.

trackerReleased

public void trackerReleased(int tracker,
                            TrackerState state)
Process a tracker press event. This may be used to start a touchtracker, start of a drag tracker or navigation

Specified by:
trackerReleased in interface UserInputHandler
Parameters:
tracker - The id of the tracker that was released
state - The state of the tracker right now

trackerClicked

public void trackerClicked(int tracker,
                           TrackerState state)
Process a tracker click event. The click is used only on touch trackers and anchors. We treat it like a cross between a select and unselect.

Specified by:
trackerClicked in interface UserInputHandler
Parameters:
tracker - The id of the tracker calling this handler
state - The event that caused the method to be called

trackerOrientation

public void trackerOrientation(int tracker,
                               TrackerState state)
Process tracker orientation events.

Specified by:
trackerOrientation in interface UserInputHandler
Parameters:
tracker - Which tracker sourced the event
state - The current state

processNavigation

public void processNavigation()
Process any navigation velocity. Call every frame.

Specified by:
processNavigation in interface UserInputHandler

setNavigationMode

public boolean setNavigationMode(java.lang.String mode)
Set the desired navigation mode. The mode string is one of the spec-defined strings for the NavigationInfo node in the VRML/X3D specification.

Specified by:
setNavigationMode in interface UserInputHandler
Parameters:
mode - The requested mode.
Returns:
Whether the mode is valid.

addNavigationStateListener

public void addNavigationStateListener(NavigationStateListener l)
Add a listener for navigation state changes. A listener can only be added once. Duplicate requests are ignored.

Specified by:
addNavigationStateListener in interface UserInputHandler
Parameters:
l - The listener to add

removeNavigationStateListener

public void removeNavigationStateListener(NavigationStateListener l)
Remove a navigation state listener. If the reference is null or not known, the request is silently ignored.

Specified by:
removeNavigationStateListener in interface UserInputHandler
Parameters:
l - The listener to remove

addSensorStatusListener

public void addSensorStatusListener(SensorStatusListener l)
Add a listener for navigation state changes. A listener can only be added once. Duplicate requests are ignored.

Specified by:
addSensorStatusListener in interface UserInputHandler
Parameters:
l - The listener to add

removeSensorStatusListener

public void removeSensorStatusListener(SensorStatusListener l)
Remove a navigation state listener. If the reference is null or not known, the request is silently ignored.

Specified by:
removeSensorStatusListener in interface UserInputHandler
Parameters:
l - The listener to remove

getOrientation

public void getOrientation(javax.vecmath.AxisAngle4f ori)
Get the current user orientation.

Specified by:
getOrientation in interface UserInputHandler
Parameters:
ori - The orientation vector to fill in

getPosition

public void getPosition(javax.vecmath.Vector3f pos)
Get the current user position.

Specified by:
getPosition in interface UserInputHandler
Parameters:
pos - The position vector to fill in

setWorldScale

public void setWorldScale(float scale)
Set the world scale applied. This will scale down navinfo parameters to fit into the world.

Specified by:
setWorldScale in interface UserInputHandler
Parameters:
scale - The new world scale.

sendCurrentNavState

public void sendCurrentNavState()
The layer that contains this handler has just been made the active navigation layer, so send out to the navigation state listeners the current navigation state for this layer. This allows the UI to update based on the currently active layer.

Specified by:
sendCurrentNavState in interface UserInputHandler

clear

public void clear()
Clear all the values, listeners etc, except for the clock. Returns the input handler back to being empty, with no state set.

Specified by:
clear in interface UserInputHandler

Xj3D 2.0 VRML/X3D Code API

Copyright © 2001 - 2006 Web3D Consortium