com.vwp.j3d.utils.behaviors.keyboard
Class KeyNavigatorBehavior

java.lang.Object
  extended by javax.media.j3d.SceneGraphObject
      extended by javax.media.j3d.Node
          extended by javax.media.j3d.Leaf
              extended by javax.media.j3d.Behavior
                  extended by com.vwp.j3d.utils.behaviors.keyboard.KeyNavigatorBehavior
All Implemented Interfaces:
KeyListener, EventListener

public class KeyNavigatorBehavior
extends javax.media.j3d.Behavior
implements KeyListener

This class is a simple behavior that invokes the KeyNavigator to modify the view platform transform. This implementation bases partially on the KeyNavigatorBehaviour from Sun Inc.


Field Summary
static int MODE_FREEFLY_SPACE
          Mode flag: if this one is set using setmode() the underlying KeyNavigator acts like a spaceship which allowes changing of the altitude in case up- or downRotAngle are used.
static int MODE_NOALTITUDE
          Mode flag: if MODE_NOALTITUDE is set using setMode() the underlying KeyNavigator simulates an object which ich influenced by gravity and a ground below of it, the up- and downRotAngles don't affect the altitude but they simulate a heads position
 
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_PICKABLE_READ, ALLOW_PICKABLE_WRITE, ENABLE_COLLISION_REPORTING, ENABLE_PICK_REPORTING
 
Constructor Summary
KeyNavigatorBehavior(boolean handleLinuxBug, javax.media.j3d.TransformGroup targetTG, javax.media.j3d.Node armingNode)
          Constructs a new key navigator behavior node that operates on the specified transform group and with the specified configuration
KeyNavigatorBehavior(boolean handleLinuxBug, javax.media.j3d.TransformGroup targetTG, javax.media.j3d.Node armingNode, double speedScalingFactor, boolean flyingEnabled, boolean inverseHeadAngle)
          Constructs a new key navigator behavior node that operates on the specified transform group and with the specified configuration
KeyNavigatorBehavior(boolean handleLinuxBug, javax.media.j3d.TransformGroup targetTG, javax.media.j3d.Node armingNode, double speedScalingFactor, boolean flyingEnabled, boolean inverseHeadAngle, FrameActionTrigger trigObj)
          Constructs a new key navigator behavior node that operates on the specified transform group and with the specified configuration
KeyNavigatorBehavior(boolean handleLinuxBug, javax.media.j3d.TransformGroup targetTG, javax.media.j3d.Node armingNode, FrameActionTrigger trigObj)
          Constructs a new key navigator behavior node that operates on the specified transform group and with the specified configuration
 
Method Summary
 void emulateFrameSwitch(int framerate)
          This method lets this Interpolator work also if no frame switching occurs
 void enableDeceleration(boolean set)
          Enables or disables the deceleration, a delayed stopping of the movement when a direction key is released
 void fadeSpeedFactor(double speedScalingFactor, double fadeTimeMSecs)
          Fades the nominal speed of the KeyNavigator to a new value.
 float getFPS()
          Because this Behaviour is called every frame, it implements an FPS counter too.
 void getLocation(javax.vecmath.Vector3d pos, javax.vecmath.Point3f angle)
          Gets the actual position and angle.
 void initialize()
          Override Behavior's initialize method to setup wakeup criteria.
 boolean isMoving()
          Specifies if currently a movement is handled
 void keyPressed(KeyEvent e)
           
 void keyReleased(KeyEvent e)
           
 void keyTyped(KeyEvent e)
           
 void processStimulus(Enumeration criteria)
          Override Behavior's stimulus method to handle the events.
 void setCheckCollisions(boolean checkCollisions, XBranchGroup CollisionRootBranch)
          Enables or disables the collision prevention algorithm.
 void setCollisionArmingNode(javax.media.j3d.Node armingNode)
          Sets the node which is used for the WakeUpOnCollisionXxx conditions.
 void setFlyingEnabled(boolean flyingEnabled)
          Enables or disables the possibility to fly using ALT+page up/down This method calls the corresponding method of the KeyNavigator directly.
 void setFollowTerrain(boolean followTerrain, XBranchGroup CollisionRootBranch, double terrainStepHeight)
          Enables or disables the terrain following algorithm.
 void setFrameActionTrigger(FrameActionTrigger trigObj)
          Here an object is handed over which has inherited from FramActionTrigger; it is called once per frame to perform several operations without creating an own behavior
 void setHeadAngle(boolean inverseHeadAngle, float minHeadAngle, float maxHeadAngle)
          Configures the settings for the head-angle (=x-angle) in MODE_NOALTITUDE.
 void setLocation(javax.vecmath.Vector3d pos, javax.vecmath.Point3f angle, double EyeHeight)
          (Re)Sets the actual position, angle and eyeheight This method calls the corresponding method of the KeyNavigator directly.
 void setMode(int Mode)
          Changes the operational mode and the behaviour of the KeyNavigator.
 void setSkyObjectData(javax.media.j3d.TransformGroup skyTG, float heightOffset)
          In case a skybox, skyplane etc. has to be used it is possible to activate its control using this method.
 void setSpeedFactor(double speedScalingFactor)
          Changes the nominal speed of the KeyNavigator.
 
Methods inherited from class javax.media.j3d.Behavior
getEnable, getNumSchedulingIntervals, getSchedulingBoundingLeaf, getSchedulingBounds, getSchedulingInterval, postId, setEnable, setSchedulingBoundingLeaf, setSchedulingBounds, setSchedulingInterval, updateNodeReferences
 
Methods inherited from class javax.media.j3d.Node
cloneNode, cloneTree, cloneTree, cloneTree, cloneTree, cloneTree, cloneTree, duplicateNode, getBounds, getBoundsAutoCompute, getCollidable, getLocalToVworld, getLocalToVworld, getParent, getPickable, setBounds, setBoundsAutoCompute, setCollidable, setPickable
 
Methods inherited from class javax.media.j3d.SceneGraphObject
clearCapability, clearCapabilityIsFrequent, getCapability, getCapabilityIsFrequent, getUserData, isCompiled, isLive, setCapability, setCapabilityIsFrequent, setUserData
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_FREEFLY_SPACE

public static final int MODE_FREEFLY_SPACE
Mode flag: if this one is set using setmode() the underlying KeyNavigator acts like a spaceship which allowes changing of the altitude in case up- or downRotAngle are used. Using this mode an inertia-dependent movement is simulated

See Also:
Constant Field Values

MODE_NOALTITUDE

public static final int MODE_NOALTITUDE
Mode flag: if MODE_NOALTITUDE is set using setMode() the underlying KeyNavigator simulates an object which ich influenced by gravity and a ground below of it, the up- and downRotAngles don't affect the altitude but they simulate a heads position

See Also:
Constant Field Values
Constructor Detail

KeyNavigatorBehavior

public KeyNavigatorBehavior(boolean handleLinuxBug,
                            javax.media.j3d.TransformGroup targetTG,
                            javax.media.j3d.Node armingNode,
                            double speedScalingFactor,
                            boolean flyingEnabled,
                            boolean inverseHeadAngle,
                            FrameActionTrigger trigObj)
Constructs a new key navigator behavior node that operates on the specified transform group and with the specified configuration

Parameters:
handleLinuxBug - enables a workaround for a bug in the Linux JVM
targetTG - the target transform group
speedScalingFactor - changes the nominal speed of the KeyNavigator
flyingEnabled - enables/disables flying (ALT+page up/down)
inverseHeadAngle - inverts the direction of operation of the page up/down keys
trigObj - this class specifies an class which has inherited from FramActionTrigger; it is called once per frame to perform several operations without creating an own behavior

KeyNavigatorBehavior

public KeyNavigatorBehavior(boolean handleLinuxBug,
                            javax.media.j3d.TransformGroup targetTG,
                            javax.media.j3d.Node armingNode,
                            double speedScalingFactor,
                            boolean flyingEnabled,
                            boolean inverseHeadAngle)
Constructs a new key navigator behavior node that operates on the specified transform group and with the specified configuration

Parameters:
handleLinuxBug - enables a workaround for a bug in the Linux JVM
targetTG - the target transform group
speedScalingFactor - changes the nominal speed of the KeyNavigator
flyingEnabled - enables/disables flying (ALT+page up/down)
inverseHeadAngle - inverts the direction of operation of the page up/down keys

KeyNavigatorBehavior

public KeyNavigatorBehavior(boolean handleLinuxBug,
                            javax.media.j3d.TransformGroup targetTG,
                            javax.media.j3d.Node armingNode,
                            FrameActionTrigger trigObj)
Constructs a new key navigator behavior node that operates on the specified transform group and with the specified configuration

Parameters:
handleLinuxBug - enables a workaround for a bug in the Linux JVM
targetTG - the target transform group
armingNode - the node which arms the collision conditions
trigObj - this class specifies an class which has inherited from FramActionTrigger; it is called once per frame to perform several operations without creating an own behavior

KeyNavigatorBehavior

public KeyNavigatorBehavior(boolean handleLinuxBug,
                            javax.media.j3d.TransformGroup targetTG,
                            javax.media.j3d.Node armingNode)
Constructs a new key navigator behavior node that operates on the specified transform group and with the specified configuration

Parameters:
handleLinuxBug - enables a workaround for a bug in the Linux JVM
targetTG - the target transform group
armingNode - the node which arms the collision conditions
Method Detail

enableDeceleration

public void enableDeceleration(boolean set)
Enables or disables the deceleration, a delayed stopping of the movement when a direction key is released

Parameters:
set - true if deceleration has to be enabled or false otherwise

setSkyObjectData

public void setSkyObjectData(javax.media.j3d.TransformGroup skyTG,
                             float heightOffset)
In case a skybox, skyplane etc. has to be used it is possible to activate its control using this method. Comparing to the TransformGroup used for the camera this one will be modified in a way which simulates a sky above the viewer. That means it will follow the viewer if the position is changed but it won't follow its rotations.

Parameters:
skyTG - the TransformGroup which holds the sky-object and which has to be modified
heightOffset - specifies the y-offset for the sky-object; this value influences the absolute height of the sky-object which is always located at an y-value of y-position of the viewer + eye height + this heightOffset

emulateFrameSwitch

public void emulateFrameSwitch(int framerate)
This method lets this Interpolator work also if no frame switching occurs

Parameters:
framerate - the number of frames per second which have to be emulated

setFrameActionTrigger

public void setFrameActionTrigger(FrameActionTrigger trigObj)
Here an object is handed over which has inherited from FramActionTrigger; it is called once per frame to perform several operations without creating an own behavior

Parameters:
trigObj - the new object which has to be triggered once per frame or null if none has to be used

setSpeedFactor

public void setSpeedFactor(double speedScalingFactor)
Changes the nominal speed of the KeyNavigator. Setting this scaling factor makes it possible to simulate different methods ov moving, like a walking person, a driving car, a flying spaceship,... This method calls the corresponding method of the KeyNavigator directly.

Parameters:
speedScalingFactor - - factor which modifies the speed, values less than 1 decrease the default speed

fadeSpeedFactor

public void fadeSpeedFactor(double speedScalingFactor,
                            double fadeTimeMSecs)
Fades the nominal speed of the KeyNavigator to a new value. Setting this scaling factor makes it possible to simulate different speeds. This method fades smooth from the actual scaling factor to the new one by calling the corresponding method of the KeyNavigator several times.

Parameters:
speedScalingFactor - factor which modifies the speed
fadeTimeMSecs - the time in millisecond the fading requires until the new speedScalingFactor has to be set

setHeadAngle

public void setHeadAngle(boolean inverseHeadAngle,
                         float minHeadAngle,
                         float maxHeadAngle)
Configures the settings for the head-angle (=x-angle) in MODE_NOALTITUDE. This method calls the corresponding method of the KeyNavigator directly.

Parameters:
inverseHeadAngle - specifies if the functionality of the page up/down keys has to be exchanged (true) or not (false)
minHeadAngle - lower maximum the head can be rotated to
maxHeadAngle - upper maximum the head can be rotated to

setFlyingEnabled

public void setFlyingEnabled(boolean flyingEnabled)
Enables or disables the possibility to fly using ALT+page up/down This method calls the corresponding method of the KeyNavigator directly.

Parameters:
flyingEnabled - enable flying (true) or disable it (false

setLocation

public void setLocation(javax.vecmath.Vector3d pos,
                        javax.vecmath.Point3f angle,
                        double EyeHeight)
(Re)Sets the actual position, angle and eyeheight This method calls the corresponding method of the KeyNavigator directly.

Parameters:
pos - specifies the actual position
angle - specifies the actual rotation angles
EyeHeight - specifies the actual EyeHeigt, that means the distance between the camera position and the ground

getLocation

public void getLocation(javax.vecmath.Vector3d pos,
                        javax.vecmath.Point3f angle)
Gets the actual position and angle. This method calls the corresponding method of the KeyNavigator directly.

Parameters:
pos - this vector is filled with the actual position information
angle - this Quat4d object is filled with the actual rotation angle information

setCheckCollisions

public void setCheckCollisions(boolean checkCollisions,
                               XBranchGroup CollisionRootBranch)
Enables or disables the collision prevention algorithm. This method calls the corresponding method of the KeyNavigator directly.

Parameters:
checkCollisions - specifies if collision prevention has to be performed (true) or not (false)
CollisionRootBranch - the branch group which has to be used for collision detection

setFollowTerrain

public void setFollowTerrain(boolean followTerrain,
                             XBranchGroup CollisionRootBranch,
                             double terrainStepHeight)
Enables or disables the terrain following algorithm. This method calls the corresponding method of the KeyNavigator directly.

Parameters:
followTerrain - specifies if terrain following has to be performed (true) or not (false)
CollisionRootBranch - - the branch group which has to be used for terrains collision detection
terrainStepHeight - maximum height which can be climbed; if terrain following is enabled this value has to be greater than 0 to let it take effect, elsewhere only down steps are possible

setMode

public void setMode(int Mode)
Changes the operational mode and the behaviour of the KeyNavigator. See description of MODE_xxx constants in KeyNavigator for details. This method calls the corresponding method of the KeyNavigator directly.

Parameters:
Mode - the value for the new operational mode

getFPS

public float getFPS()
Because this Behaviour is called every frame, it implements an FPS counter too. This method returns the actual framerate

Returns:
the actual framerate in FPS (frames per second)

setCollisionArmingNode

public void setCollisionArmingNode(javax.media.j3d.Node armingNode)
Sets the node which is used for the WakeUpOnCollisionXxx conditions.

Parameters:
armingNode - the node which arms the conditions

initialize

public void initialize()
Override Behavior's initialize method to setup wakeup criteria.

Specified by:
initialize in class javax.media.j3d.Behavior

processStimulus

public void processStimulus(Enumeration criteria)
Override Behavior's stimulus method to handle the events.

Specified by:
processStimulus in class javax.media.j3d.Behavior

isMoving

public boolean isMoving()
Specifies if currently a movement is handled

Returns:
true if the user is moving or false otherwise

keyPressed

public void keyPressed(KeyEvent e)
Specified by:
keyPressed in interface KeyListener

keyReleased

public void keyReleased(KeyEvent e)
Specified by:
keyReleased in interface KeyListener

keyTyped

public void keyTyped(KeyEvent e)
Specified by:
keyTyped in interface KeyListener