org.selman.java3d.book.common
Class TornadoMouseBehavior

java.lang.Object
  |
  +--javax.media.j3d.SceneGraphObject
        |
        +--javax.media.j3d.Node
              |
              +--javax.media.j3d.Leaf
                    |
                    +--javax.media.j3d.Behavior
                          |
                          +--org.selman.java3d.book.common.TornadoMouseBehavior
Direct Known Subclasses:
TornadoMouseRotate, TornadoMouseScale, TornadoMouseTranslate

public abstract class TornadoMouseBehavior
extends javax.media.j3d.Behavior

Base class for the Tornado Mouse Behaviors (Rotate, Translate, Scale).

Version:
1.0
Author:
Daniel Selman

Field Summary
protected  boolean m_bDragging
           
protected  org.selman.java3d.book.common.TornadoChangeListener m_Listener
           
protected  javax.media.j3d.WakeupOr m_MouseCriterion
           
protected  javax.vecmath.Point3f m_NewPos
           
protected  int m_nLastY
           
protected  java.lang.Object m_Object
           
protected  javax.vecmath.Point3f m_OldPos
           
protected  javax.media.j3d.Transform3D m_Transform3D
           
protected  javax.media.j3d.Transform3D m_Translation
           
protected  javax.vecmath.Vector3f m_TranslationVector
           
 
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
TornadoMouseBehavior()
           
 
Method Summary
protected  void adjustTransform(int xpos, int ypos)
          Transforms the x,y mouse coordinates to coordinates relative to the object.
protected  void applyTransform()
          Saves the behaviors Transform3D into its TransformGroup (if present).
protected abstract  void applyVectorToObject(javax.vecmath.Vector3f v)
          Apply a delta vector (in the object's local coordinates) to the object.
protected  void getImagePlateToVworld(javax.media.j3d.Transform3D t3d)
          Gets the Transform3D to convert from the Image plate coordinate system to the world coordinate system.
protected  void getObjectLocalToVworld(javax.media.j3d.Transform3D t3d)
          Gets the Transform3D to convert from the Objects coordinate system to the world coordinate system.
protected  javax.media.j3d.TransformGroup getTransformGroup()
           
 void initialize()
          Registers which AWT events are of interest to the behaviour
protected  boolean isRelativeToObjectCoordinates()
           
protected  boolean isRelativeToStartDrag()
           
protected abstract  boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt)
           
protected  boolean isStopBehaviorEvent(java.awt.event.MouseEvent evt)
           
protected  void onEndDrag()
          Allows custom end drag processing.
protected  void onStartDrag()
          Allows custom start drag processing.
protected  void processMouseEvent(java.awt.event.MouseEvent evt)
          Dispatches mouse events as appropriate.
 void processStimulus(java.util.Enumeration criteria)
          Dispatches events based on the behaviours criteria
 void setChangeListener(org.selman.java3d.book.common.TornadoChangeListener listener)
          Register a listener for the behavior.
 void setObject(java.lang.Object obj)
          void setObject( Object obj )
 
Methods inherited from class javax.media.j3d.Behavior
getEnable, getNumSchedulingIntervals, getSchedulingBoundingLeaf, getSchedulingBounds, getSchedulingInterval, getView, getWakeupCondition, postId, setEnable, setSchedulingBoundingLeaf, setSchedulingBounds, setSchedulingInterval, updateNodeReferences, wakeupOn
 
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, duplicateSceneGraphObject, getCapability, getCapabilityIsFrequent, getUserData, isCompiled, isLive, setCapability, setCapabilityIsFrequent, setUserData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_Object

protected java.lang.Object m_Object

m_NewPos

protected javax.vecmath.Point3f m_NewPos

m_OldPos

protected javax.vecmath.Point3f m_OldPos

m_TranslationVector

protected javax.vecmath.Vector3f m_TranslationVector

m_Translation

protected javax.media.j3d.Transform3D m_Translation

m_bDragging

protected boolean m_bDragging

m_MouseCriterion

protected javax.media.j3d.WakeupOr m_MouseCriterion

m_nLastY

protected int m_nLastY

m_Transform3D

protected javax.media.j3d.Transform3D m_Transform3D

m_Listener

protected org.selman.java3d.book.common.TornadoChangeListener m_Listener
Constructor Detail

TornadoMouseBehavior

public TornadoMouseBehavior()
Method Detail

setChangeListener

public void setChangeListener(org.selman.java3d.book.common.TornadoChangeListener listener)
Register a listener for the behavior.

Parameters:
listener - the listener to add or null to remove the listener

applyVectorToObject

protected abstract void applyVectorToObject(javax.vecmath.Vector3f v)
Apply a delta vector (in the object's local coordinates) to the object.


isStartBehaviorEvent

protected abstract boolean isStartBehaviorEvent(java.awt.event.MouseEvent evt)
Returns:
true is this the mouse event that starts the tracking behaviour

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent evt)
Dispatches mouse events as appropriate. Should not need to overide this method.


isStopBehaviorEvent

protected boolean isStopBehaviorEvent(java.awt.event.MouseEvent evt)
Returns:
true if this is the event that stops drag tracking behviour the default uses MOUSE_RELEASED.

isRelativeToStartDrag

protected boolean isRelativeToStartDrag()
Returns:
true if this behaviours change vector is relative to the starting mouse click. The default is a behaviour that generates delta change vectors as the user moves the mouse.

isRelativeToObjectCoordinates

protected boolean isRelativeToObjectCoordinates()
Returns:
true if the mouse coordinates should be converted to local object coordinates before being processed by applyVectorToObject

onStartDrag

protected void onStartDrag()
Allows custom start drag processing. Default does nothing.


onEndDrag

protected void onEndDrag()
Allows custom end drag processing. ** Call this base class! **


getObjectLocalToVworld

protected void getObjectLocalToVworld(javax.media.j3d.Transform3D t3d)
Gets the Transform3D to convert from the Objects coordinate system to the world coordinate system.

Parameters:
t3d - the Transform3D to populate

getImagePlateToVworld

protected void getImagePlateToVworld(javax.media.j3d.Transform3D t3d)
Gets the Transform3D to convert from the Image plate coordinate system to the world coordinate system.

Parameters:
t3d - the Transform3D to populate

getTransformGroup

protected javax.media.j3d.TransformGroup getTransformGroup()
Returns:
the TransformGroup if a TG Object is associated with the behavior or null otherwise.

applyTransform

protected void applyTransform()
Saves the behaviors Transform3D into its TransformGroup (if present). Catches any exceptions (bad transform) that might be thrown.


adjustTransform

protected void adjustTransform(int xpos,
                               int ypos)
Transforms the x,y mouse coordinates to coordinates relative to the object. Calculates a "delta vector" in object coordinates and calls ApplyVectorToObject(). Thanks to: A.R. van Ballegooy. Simon McMullen [simonmc@mincom.com]


processStimulus

public void processStimulus(java.util.Enumeration criteria)
Dispatches events based on the behaviours criteria

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

initialize

public void initialize()
Registers which AWT events are of interest to the behaviour

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

setObject

public void setObject(java.lang.Object obj)
void setObject( Object obj )

Parameters:
obj - the Objectto manipulate. A null object disables the behaviour.