Class FlyPathBehavior

  • All Implemented Interfaces:
    java.awt.event.KeyListener, java.util.EventListener

    public class FlyPathBehavior
    extends javax.media.j3d.Behavior
    implements java.awt.event.KeyListener
    Behavior which allows for flying down a specified path and looking around.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  FlyPathBehavior.BranchState
      DOCUMENT ME!
      static interface  FlyPathBehavior.Callback
      Instances which want to be notified of updates to this behavior should implement this interface by providing the viewChanged method implementation.
      (package private) class  FlyPathBehavior.StandardKey
      Class used to send Standard key events to the canvas.
    • Constructor Summary

      Constructors 
      Constructor Description
      FlyPathBehavior​(FlyPathGraphCurve kFlyPathGraph, FlyPathAnnotateList kAnnotateList, javax.media.j3d.TransformGroup kTransformPosition, javax.media.j3d.TransformGroup kTransformDirection, javax.media.j3d.TransformGroup kTransformOrientation, FlythruRender _parentScene)
      Setup to fly along the specified path and look around.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void autoRun()
      One round trip path walk through.
      private static void beep()
      Sound a beep.
      private float clampNormalizedPathDistance​(float fDistance)
      Clamp the input normalized path distance to the range [0,1].
      private void doPathStep​(int iNumSteps)
      Take the specified number of steps along the current path using the current path step size.
      WildMagic.LibFoundation.Curves.Curve3f getBranchCurve()
      Access the curve in the path graph currently positioned along.
      float getBranchDistUnvisitedMax()
      Access the normalized distance traveled from the end of the current branch path.
      float getBranchDistUnvisitedMin()
      Access the normalized distance traveled from the beginning of the current branch path.
      int getBranchIndex()
      Access the index of the curve in the path graph currrently positioned along.
      FlyPathBehavior.BranchState getBranchState()
      Get the current state of traversing.
      float getGazeDistance()
      Get the current distance ahead for looking down the path.
      float getNormalizedPathDistance()
      Get the normalized distance along the current path.
      float getPathDist()
      Get the current position distance along the path.
      float getPathDistance()
      Get the current distance along the path.
      float getPathLength()
      Get the total length of the current path.
      javax.vecmath.Point3f getPathPosition()
      Get the location of the current position along the path.
      float getPathStep()
      Get the current distance increment for moving along the path.
      int getSelectedBranchIndex()
      Access the index of the currently selected branch at a branch point.
      javax.vecmath.Vector3f getViewDirection()
      Retrieve the current base direction vector for viewing.
      javax.vecmath.Matrix3f getViewOrientation()
      Retrieve the current relative orientation transform matrix for viewing which is relative to the current base direction transform for viewing.
      void initialize()
      Implementation of the Behavior abstract method.
      boolean isPathMoveForward()
      Get indication of whether the movement along the current path is in the forward or reverse direction.
      void keyPressed​(java.awt.event.KeyEvent event)
      Handle the key pressed event from the text field.
      void keyReleased​(java.awt.event.KeyEvent event)
      Handle the key released event from the text field.
      void keyTyped​(java.awt.event.KeyEvent event)
      Does nothing.
      void move​(java.lang.String command)
      Call from the JPanelFlythruMove.
      void moveAlongPath​(int _step)
      Move along the path step width.
      private void notifyCallback​(int iEvent)
      Call the implementation of the callback's notification method, if a callback instance has been defined.
      void processStimulus​(java.util.Enumeration kCriteria)
      Implementation of the Behavior abstract method.
      private void setBranch​(int iBranch)
      Make the specified branch be the current state for following.
      private void setBranch​(FlyPathBehavior.BranchState kBranchState)
      Make the specified branch be the current state for following.
      void setBranch​(java.lang.Object _kBranchState)
      Make the specified branch be the current state for following.
      private void setClosestChoiceBranch()
      Loop through all of the possible branch choices and select the one that is the closest to the current view direction vector.
      private void setCurvePathAnnotateItem​(int iItem)
      Set the annotation point along the path.
      private void setIdentityViewOrientation()
      Reset the view orientation transformation to the identity.
      private void setPathDist​(float fNormalizedDist)
      Update the camera position along the path based on the specified distance from the beginning.
      private void setupBranchChoices​(int iBranchParent, int iBranchPoint)
      Create the array of branch choices and set the mode which forces the user to select from among the branch choices.
      void setupCallback​(FlyPathBehavior.Callback kCallback)
      Identify the instance which implements the Callback interface.
      private void setView​(javax.vecmath.Point3d kViewPoint, javax.vecmath.Vector3d kViewdirVector)
      Set the camera to the specified be located at the specified view point and looking in the specified direction.
      • 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, 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EVENT_CHANGE_ALL

        public static final int EVENT_CHANGE_ALL
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • EVENT_CHANGE_POSITION

        public static final int EVENT_CHANGE_POSITION
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • EVENT_CHANGE_ORIENTATION

        public static final int EVENT_CHANGE_ORIENTATION
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • EVENT_CHANGE_BRANCH

        public static final int EVENT_CHANGE_BRANCH
        DOCUMENT ME!
        See Also:
        Constant Field Values
      • m_fGazeDist

        public float m_fGazeDist
        How far ahead down the path should the view be aimed. If zero, then the view direction is the tangent to the curve. If positive, the the view direction is to look at that point along the path.
      • m_fPathStep

        public float m_fPathStep
        What is the increment in distance along the path that each step takes. Increment may be negative indicating that the path is being followed in the opposite direction.
      • currEventTime

        long currEventTime
        current and previous key press time.
      • prevEventTime

        long prevEventTime
        current and previous key press time.
      • m_akBranchChoice

        private FlyPathBehavior.BranchState[] m_akBranchChoice
        When a branch point along the current branch is reached, this array is filled with the possible BranchState instances that the user can select from for following. Once movement is made along one of those selected from the list, then this list is cleared. An index is maintained to indicate which branch in the list is currently selected.
      • m_akBranchState

        private FlyPathBehavior.BranchState[] m_akBranchState
        Identifies the current state of traversing the current branch.
      • m_bChooseBranch

        private boolean m_bChooseBranch
        When a branch point along the current branch is reached, this flag is set until the user selects a branch to follow.
      • m_iAnnotateListItemSelected

        private int m_iAnnotateListItemSelected
        DOCUMENT ME!
      • m_iBranchChoiceIndex

        private int m_iBranchChoiceIndex
        DOCUMENT ME!
      • m_kAnnotateList

        private FlyPathAnnotateList m_kAnnotateList
        Keep reference to instance which describes the annotation points.
      • m_kCallback

        private FlyPathBehavior.Callback m_kCallback
        Instance which implements the Callback interface whose viewChanged method is to be called whenever anything about this behavior changes.
      • m_kFlyPathGraph

        private FlyPathGraphCurve m_kFlyPathGraph
        Keep reference to instance which describes the path.
      • m_kTransform

        private javax.media.j3d.Transform3D m_kTransform
        Transform created for multiple use to avoid new'ing it each time.
      • m_kTransformDirection

        private javax.media.j3d.TransformGroup m_kTransformDirection
        View direction component for this view transform. This assumes a viewup vector (see m_kVectorViewup member). This transform causes the view to look down the path when the yaw=pitch=roll=0.
      • m_kTransformOrientation

        private javax.media.j3d.TransformGroup m_kTransformOrientation
        Orientation (yaw/pitch) component for this view transform.
      • m_kTransformPosition

        private javax.media.j3d.TransformGroup m_kTransformPosition
        Position-only component for this view transform.
      • m_kTransformRot

        private javax.media.j3d.Transform3D m_kTransformRot
        DOCUMENT ME!
      • m_kViewup1

        private javax.vecmath.Vector3d m_kViewup1
        The desired view up vector is a normalized average of these two orthogonal axes vectors. The problem is that if just one desired view up vector is chosen, then when the view direction vector is "aligned" with that vector, some other view up vector would have to be chosen and some rule would have to be defined for that.
      • m_kViewup2

        private javax.vecmath.Vector3d m_kViewup2
        DOCUMENT ME!
      • m_kWakeupCondition

        private final javax.media.j3d.WakeupCondition m_kWakeupCondition
        Conditions which contain the events we want to "wakeup" on.
      • parentScene

        private FlythruRender parentScene
        Parent frame references.
      • pressed

        private boolean pressed
        If any of the mouse move button pressed.
    • Constructor Detail

      • FlyPathBehavior

        public FlyPathBehavior​(FlyPathGraphCurve kFlyPathGraph,
                               FlyPathAnnotateList kAnnotateList,
                               javax.media.j3d.TransformGroup kTransformPosition,
                               javax.media.j3d.TransformGroup kTransformDirection,
                               javax.media.j3d.TransformGroup kTransformOrientation,
                               FlythruRender _parentScene)
        Setup to fly along the specified path and look around.
        Parameters:
        kFlyPathGraph - FlyPathGraphCurve contains the information regarding the graph representation of 3D path segments represented by Curve3 instances
        kAnnotateList - FlyPathAnnotateList contains the list of annotation points.
        kTransformPosition - TransformGroup contains the Transform3D for the current viewing position.
        kTransformDirection - TransformGroup contains the Transform3D for the current viewing direction.
        kTransformOrientation - TransformGroup contains the Transform3D for the current viewing orientation.
        _parentScene - the parent frame which hold Canvas3D.
    • Method Detail

      • autoRun

        public void autoRun()
        One round trip path walk through.
      • getBranchCurve

        public WildMagic.LibFoundation.Curves.Curve3f getBranchCurve()
        Access the curve in the path graph currently positioned along.
        Returns:
        Curve3 Reference to Curve3 instance in path graph.
      • getBranchDistUnvisitedMax

        public float getBranchDistUnvisitedMax()
        Access the normalized distance traveled from the end of the current branch path. Also represents the maximum of the range that has been unvisited.
        Returns:
        float Normalized distance along the current branch path that is maximum of the unvisited range.
      • getBranchDistUnvisitedMin

        public float getBranchDistUnvisitedMin()
        Access the normalized distance traveled from the beginning of the current branch path. Also represents the minimum of the range that has been unvisited.
        Returns:
        float Normalized distance along the current branch path that is minimum of the unvisited range.
      • getBranchIndex

        public int getBranchIndex()
        Access the index of the curve in the path graph currrently positioned along.
        Returns:
        int Index of Curve3 instance in path graph.
      • getGazeDistance

        public float getGazeDistance()
        Get the current distance ahead for looking down the path. If this distance is zero, then the view direction is the tangent to the path curve at the current position.
        Returns:
        float Distance ahead for looking down the path.
      • getNormalizedPathDistance

        public float getNormalizedPathDistance()
        Get the normalized distance along the current path.
        Returns:
        float Value in the range [0,1].
      • getPathDist

        public float getPathDist()
        Get the current position distance along the path.
        Returns:
        float path distance.
      • getPathDistance

        public float getPathDistance()
        Get the current distance along the path.
        Returns:
        distance along the path.
      • getPathLength

        public float getPathLength()
        Get the total length of the current path.
        Returns:
        float Length of the path.
      • getPathPosition

        public javax.vecmath.Point3f getPathPosition()
        Get the location of the current position along the path.
        Returns:
        location of current position
      • getPathStep

        public float getPathStep()
        Get the current distance increment for moving along the path.
        Returns:
        distance increment for moving along path. Always positive regardless of which direction moving along the path.
      • getSelectedBranchIndex

        public int getSelectedBranchIndex()
        Access the index of the currently selected branch at a branch point.
        Returns:
        int Index of currently selected branch; -1 if not currently at a branch point.
      • getViewDirection

        public javax.vecmath.Vector3f getViewDirection()
        Retrieve the current base direction vector for viewing.
        Returns:
        normalized direction vector
      • getViewOrientation

        public javax.vecmath.Matrix3f getViewOrientation()
        Retrieve the current relative orientation transform matrix for viewing which is relative to the current base direction transform for viewing.
        Returns:
        3x3 matrix containing orientation transform
      • initialize

        public void initialize()
        Implementation of the Behavior abstract method.
        Specified by:
        initialize in class javax.media.j3d.Behavior
      • isPathMoveForward

        public boolean isPathMoveForward()
        Get indication of whether the movement along the current path is in the forward or reverse direction.
        Returns:
        boolean True if the movement is along the forward direction along the path.
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent event)
        Handle the key pressed event from the text field.
        Specified by:
        keyPressed in interface java.awt.event.KeyListener
        Parameters:
        event - key event to handle
      • keyReleased

        public void keyReleased​(java.awt.event.KeyEvent event)
        Handle the key released event from the text field.
        Specified by:
        keyReleased in interface java.awt.event.KeyListener
        Parameters:
        event - key event to handle
      • keyTyped

        public void keyTyped​(java.awt.event.KeyEvent event)
        Does nothing.
        Specified by:
        keyTyped in interface java.awt.event.KeyListener
        Parameters:
        event - key event to handle
      • move

        public void move​(java.lang.String command)
        Call from the JPanelFlythruMove.
        Parameters:
        command - move command.
      • moveAlongPath

        public void moveAlongPath​(int _step)
        Move along the path step width.
        Parameters:
        _step - step size.
      • processStimulus

        public void processStimulus​(java.util.Enumeration kCriteria)
        Implementation of the Behavior abstract method. Process events in the criteria which are the ones we setup for.
        Specified by:
        processStimulus in class javax.media.j3d.Behavior
        Parameters:
        kCriteria - collection of WakeupCriterion to which this Behavior is responding to events.
      • setBranch

        public void setBranch​(java.lang.Object _kBranchState)
        Make the specified branch be the current state for following.
        Parameters:
        _kBranchState - BranchState Instance which describes the state of the branch.
      • setupCallback

        public void setupCallback​(FlyPathBehavior.Callback kCallback)
        Identify the instance which implements the Callback interface. The viewChanged method of the Callback interface will be called whenever anything about this behavior changes.
        Parameters:
        kCallback - reference to instance implementing the Callback interface; may pass null reference to disable the callback
      • beep

        private static void beep()
        Sound a beep.
      • clampNormalizedPathDistance

        private float clampNormalizedPathDistance​(float fDistance)
        Clamp the input normalized path distance to the range [0,1]. If the value is outside that range, then sound a beep.
        Parameters:
        fDistance - float Input normalized path distance.
        Returns:
        float Input distance clamped to the range [0,1].
      • doPathStep

        private void doPathStep​(int iNumSteps)
        Take the specified number of steps along the current path using the current path step size. If the number of steps is negative, then the steps are taken in reverse.
        Parameters:
        iNumSteps - int Number of steps to take along the current path.
      • notifyCallback

        private void notifyCallback​(int iEvent)
        Call the implementation of the callback's notification method, if a callback instance has been defined.
        Parameters:
        iEvent - Bitmask identifies the event(s) which caused the view to change. Bitmask created from OR of EVENT_* defintions.
      • setBranch

        private void setBranch​(int iBranch)
        Make the specified branch be the current state for following.
        Parameters:
        iBranch - int Index of the branch path to follow.
      • setBranch

        private void setBranch​(FlyPathBehavior.BranchState kBranchState)
        Make the specified branch be the current state for following.
        Parameters:
        kBranchState - BranchState Instance which describes the state of the branch.
      • setClosestChoiceBranch

        private void setClosestChoiceBranch()
        Loop through all of the possible branch choices and select the one that is the closest to the current view direction vector. Take a vector from the current view point to a point along each choice branch. Compute the dot-product between the current view direction vector and each of these branch direction vectors and take the one with the largest positive value, i.e., most in alignment.
      • setCurvePathAnnotateItem

        private void setCurvePathAnnotateItem​(int iItem)
        Set the annotation point along the path.
        Parameters:
        iItem - int
      • setIdentityViewOrientation

        private void setIdentityViewOrientation()
        Reset the view orientation transformation to the identity. That is, remove all yaw/pitch/roll.
      • setPathDist

        private void setPathDist​(float fNormalizedDist)
        Update the camera position along the path based on the specified distance from the beginning.
        Parameters:
        fNormalizedDist - normalized distance from the beginning of the path for the location of the camera for viewing
      • setupBranchChoices

        private void setupBranchChoices​(int iBranchParent,
                                        int iBranchPoint)
        Create the array of branch choices and set the mode which forces the user to select from among the branch choices.
        Parameters:
        iBranchParent - int Index which identifies the parent branch.
        iBranchPoint - int Index which identifies the point along the branch path where the branching occurs for the choices.
      • setView

        private void setView​(javax.vecmath.Point3d kViewPoint,
                             javax.vecmath.Vector3d kViewdirVector)
        Set the camera to the specified be located at the specified view point and looking in the specified direction.
        Parameters:
        kViewPoint - coordinates of the camera view point
        kViewdirVector - coordinates of the camera view direction vector. This vector must be normalized.