Renderer
Class SandboxController

java.lang.Object
  |
  +--javax.media.j3d.SceneGraphObject
        |
        +--javax.media.j3d.Node
              |
              +--javax.media.j3d.Leaf
                    |
                    +--javax.media.j3d.Behavior
                          |
                          +--Renderer.SandboxController

public class SandboxController
extends javax.media.j3d.Behavior

Supports all the interactive features on a single Sandbox. It handles the keyboard and mouse events that are generated when the view is changed or a Toy is selected and feeds them back to the Sandbox for processing. It also maintains the head-up display.

Version:
Created 17 February 2003
Author:
Dan Tappan
See Also:
Sandbox, Attitude, Position

Field Summary
private  float ATTITUDE_DAMPER_PITCH
           
private  float ATTITUDE_DAMPER_YAW
           
private  float ATTITUDE_ORBIT_YAW
           
private  float ATTITUDE_OUTSIDE
           
private  float ATTITUDE_PITCH_NOMINAL
           
private  float ATTITUDE_ROLL_NOMINAL
           
private  float ATTITUDE_STEP_PITCH
           
private  float ATTITUDE_STEP_ROLL
           
private  float ATTITUDE_STEP_YAW
           
private  float ATTITUDE_YAW_NOMINAL
           
private  int AUTOYAW_FRAME_OFFSET
           
private  int AUTOYAW_INCREMENT
           
private  float CENTER_AXIS_TWEAK
           
private  float FIELD_OF_VIEW_HORIZONTAL
           
private  float FIELD_OF_VIEW_HORIZONTAL_MIDPOINT
           
private  float FIELD_OF_VIEW_VERTICAL
           
private  float FIELD_OF_VIEW_VERTICAL_MIDPOINT
           
private  int HUD_HEIGHT
           
private  int HUD_SHIFT
           
private  int HUD_UPDATE_THRESHOLD
           
private  int HUD_WIDTH
           
private  float HUD_Z
           
private  int KEY_ARROW_DOWN
           
private  int KEY_ARROW_LEFT
           
private  int KEY_ARROW_RIGHT
           
private  int KEY_ARROW_UP
           
private  int KEY_END
           
private  int KEY_ESCAPE
           
private  int KEY_F1
           
private  int KEY_F10
           
private  int KEY_F11
           
private  int KEY_F12
           
private  int KEY_F2
           
private  int KEY_F3
           
private  int KEY_F4
           
private  int KEY_F5
           
private  int KEY_F6
           
private  int KEY_F7
           
private  int KEY_F8
           
private  int KEY_F9
           
private  int KEY_HOME
           
private  int KEY_KEYPAD_DOWN
           
private  int KEY_KEYPAD_LEFT
           
private  int KEY_KEYPAD_RIGHT
           
private  int KEY_KEYPAD_UP
           
private  int KEY_MODIFIER_ALT
           
private  int KEY_MODIFIER_CONTROL
           
private  int KEY_MODIFIER_SHIFT
           
private  int KEY_PAGE_DOWN
           
private  int KEY_PAGE_UP
           
private  int KEY_SHOW_HIDE_HUD
           
private  Attitude m_attitude
           
private  Attitude m_attitude_damper_max
           
private  Attitude m_attitude_damper_min
           
private  Attitude m_attitude_fov
           
private  Attitude m_attitude_head
           
private  SnapCanvas3D m_canvas
           
private  float m_field_of_view_scale_x
           
private  float m_field_of_view_scale_y
           
private  javax.media.j3d.Shape3D m_hud
           
private  javax.media.j3d.Appearance m_hud_appearance
           
(package private)  java.awt.image.BufferedImage m_hud_bitmap
           
private  javax.media.j3d.BranchGroup m_hud_branch_group
           
(package private)  javax.media.j3d.ImageComponent2D m_hud_image
           
private  javax.media.j3d.RenderingAttributes m_hud_rendering_attributes
           
(package private)  javax.media.j3d.Texture2D m_hud_texture
           
private  javax.media.j3d.Transform3D m_hud_transform_3d
           
private  javax.media.j3d.TransformGroup m_hud_transform_group
           
private  int m_hud_update_countdown
           
private  javax.media.j3d.BranchGroup m_master_branch_group
           
private  javax.media.j3d.Transform3D m_master_transform_3d
           
private  javax.media.j3d.TransformGroup m_master_transform_group
           
private  Position m_mouse_position
           
private  Position m_position
           
private  Position m_position_gradient
           
private  Sandbox m_sandbox
           
private  Dimensions m_screen_dimensions
           
private  Position m_screen_frame_max
           
private  Position m_screen_frame_min
           
private  boolean m_show_hud
           
private  com.sun.j3d.utils.universe.SimpleUniverse m_universe
           
private  javax.media.j3d.WakeupCondition m_wakeup_condition
           
private  javax.media.j3d.WakeupCriterion[] m_wakeup_criterion
           
private  boolean MODEL_EDIT_MODE
           
private  float POSITION_X_MAX
           
private  float POSITION_X_MIN
           
private  float POSITION_X_NOMINAL
           
private  float POSITION_X_SPREAD
           
private  float POSITION_X_STEP
           
private  float POSITION_XZ_CORNER_FACTOR
           
private  float POSITION_Y_MAX
           
private  float POSITION_Y_MIN
           
private  float POSITION_Y_NOMINAL
           
private  float POSITION_Y_OUTSIDE
           
private  float POSITION_Y_SPREAD
           
private  float POSITION_Y_STEP
           
private  float POSITION_Z_MAX
           
private  float POSITION_Z_MIN
           
private  float POSITION_Z_NOMINAL
           
private  float POSITION_Z_SPREAD
           
private  float POSITION_Z_STEP
           
private  java.lang.String SCREEN_CAPTURE_FILENAME_PREFIX
           
 
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
 
Fields inherited from class javax.media.j3d.SceneGraphObject
 
Constructor Summary
SandboxController(SnapCanvas3D canvas, javax.media.j3d.BranchGroup branch_group, com.sun.j3d.utils.universe.SimpleUniverse universe, Sandbox sandbox)
          Creates a new controller for a sandbox.
 
Method Summary
private  void assumeNominalView()
          Resets the position and attitudes to sandbox-center looking toward the back.
private  void buildHeadUpDisplay(boolean is_initial_build)
          Builds and places the head-up display.
private  void determinePickSelection(java.awt.event.MouseEvent event)
          Determines which toy, if any, has been clicked on and hands processing off to the appropriate handler in the controlled sandbox.
private  float getScaledX(int x)
          Returns a horizontal coordinate in Java3D units based on the current canvas width in pixels.
private  float getScaledY(int y)
          Returns a vertical coordinate in Java3D units based on the current canvas height in pixels.
 Attitude getViewerAttitude()
          Returns the combined attitude of the field of view and the head of the viewer in the controlled sandbox.
 Attitude getViewerFieldOfViewAttitude()
          Returns the attitude of the field of view of the viewer in the controlled sandbox.
 Attitude getViewerHeadAttitude()
          Returns the attitude of the head of the viewer in the controlled sandbox.
 Position getViewerPosition()
          Returns the position of the viewer in the controlled sandbox.
 void initialize()
          Configures the event handlers.
private  void orbit(float step)
          Causes the sandbox to revolve around its center in the given direction and speed.
private  void processKeyEvent(java.awt.event.KeyEvent event)
          Handles a key event.
private  void processMouseEvent(java.awt.event.MouseEvent event)
          Handles a mouse event.
 void processStimulus(java.util.Enumeration criteria)
          Manages the events that occur and redirects them to the appropriate handler.
 java.lang.String toString()
          Returns a string representation of this object.
 void update(boolean force_hud_update)
          Updates the contents of the controlled sandbox.
 void updateFrame()
          Updates the scaling and other parameters that depend on the size of the frame on which the controlled sandbox resides.
private  void updateHeadUpDisplay()
          Updates the contents of the head-up display.
 
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, wait, wait, wait
 

Field Detail

MODEL_EDIT_MODE

private final boolean MODEL_EDIT_MODE
See Also:
Constant Field Values

m_sandbox

private Sandbox m_sandbox

m_canvas

private SnapCanvas3D m_canvas

m_universe

private com.sun.j3d.utils.universe.SimpleUniverse m_universe

m_master_branch_group

private javax.media.j3d.BranchGroup m_master_branch_group

m_master_transform_group

private javax.media.j3d.TransformGroup m_master_transform_group

m_master_transform_3d

private javax.media.j3d.Transform3D m_master_transform_3d

m_hud_branch_group

private javax.media.j3d.BranchGroup m_hud_branch_group

m_hud_transform_group

private javax.media.j3d.TransformGroup m_hud_transform_group

m_hud_transform_3d

private javax.media.j3d.Transform3D m_hud_transform_3d

m_hud_appearance

private javax.media.j3d.Appearance m_hud_appearance

m_hud_rendering_attributes

private javax.media.j3d.RenderingAttributes m_hud_rendering_attributes

m_hud

private javax.media.j3d.Shape3D m_hud

HUD_Z

private final float HUD_Z
See Also:
Constant Field Values

HUD_HEIGHT

private final int HUD_HEIGHT
See Also:
Constant Field Values

HUD_WIDTH

private final int HUD_WIDTH
See Also:
Constant Field Values

HUD_SHIFT

private final int HUD_SHIFT
See Also:
Constant Field Values

HUD_UPDATE_THRESHOLD

private final int HUD_UPDATE_THRESHOLD
See Also:
Constant Field Values

m_hud_update_countdown

private int m_hud_update_countdown

m_show_hud

private boolean m_show_hud

m_hud_bitmap

java.awt.image.BufferedImage m_hud_bitmap

m_hud_image

javax.media.j3d.ImageComponent2D m_hud_image

m_hud_texture

javax.media.j3d.Texture2D m_hud_texture

m_wakeup_criterion

private javax.media.j3d.WakeupCriterion[] m_wakeup_criterion

m_wakeup_condition

private javax.media.j3d.WakeupCondition m_wakeup_condition

KEY_ARROW_UP

private final int KEY_ARROW_UP
See Also:
Constant Field Values

KEY_ARROW_DOWN

private final int KEY_ARROW_DOWN
See Also:
Constant Field Values

KEY_ARROW_LEFT

private final int KEY_ARROW_LEFT
See Also:
Constant Field Values

KEY_ARROW_RIGHT

private final int KEY_ARROW_RIGHT
See Also:
Constant Field Values

KEY_PAGE_UP

private final int KEY_PAGE_UP
See Also:
Constant Field Values

KEY_PAGE_DOWN

private final int KEY_PAGE_DOWN
See Also:
Constant Field Values

KEY_F1

private final int KEY_F1
See Also:
Constant Field Values

KEY_F2

private final int KEY_F2
See Also:
Constant Field Values

KEY_F3

private final int KEY_F3
See Also:
Constant Field Values

KEY_F4

private final int KEY_F4
See Also:
Constant Field Values

KEY_F5

private final int KEY_F5
See Also:
Constant Field Values

KEY_F6

private final int KEY_F6
See Also:
Constant Field Values

KEY_F7

private final int KEY_F7
See Also:
Constant Field Values

KEY_F8

private final int KEY_F8
See Also:
Constant Field Values

KEY_F9

private final int KEY_F9
See Also:
Constant Field Values

KEY_F10

private final int KEY_F10
See Also:
Constant Field Values

KEY_F11

private final int KEY_F11
See Also:
Constant Field Values

KEY_F12

private final int KEY_F12
See Also:
Constant Field Values

KEY_ESCAPE

private final int KEY_ESCAPE
See Also:
Constant Field Values

KEY_HOME

private final int KEY_HOME
See Also:
Constant Field Values

KEY_END

private final int KEY_END
See Also:
Constant Field Values

KEY_SHOW_HIDE_HUD

private final int KEY_SHOW_HIDE_HUD
See Also:
Constant Field Values

KEY_KEYPAD_LEFT

private final int KEY_KEYPAD_LEFT
See Also:
Constant Field Values

KEY_KEYPAD_RIGHT

private final int KEY_KEYPAD_RIGHT
See Also:
Constant Field Values

KEY_KEYPAD_UP

private final int KEY_KEYPAD_UP
See Also:
Constant Field Values

KEY_KEYPAD_DOWN

private final int KEY_KEYPAD_DOWN
See Also:
Constant Field Values

KEY_MODIFIER_SHIFT

private final int KEY_MODIFIER_SHIFT
See Also:
Constant Field Values

KEY_MODIFIER_CONTROL

private final int KEY_MODIFIER_CONTROL
See Also:
Constant Field Values

KEY_MODIFIER_ALT

private final int KEY_MODIFIER_ALT
See Also:
Constant Field Values

POSITION_X_MIN

private final float POSITION_X_MIN

POSITION_X_MAX

private final float POSITION_X_MAX

POSITION_X_NOMINAL

private final float POSITION_X_NOMINAL
See Also:
Constant Field Values

POSITION_X_STEP

private final float POSITION_X_STEP
See Also:
Constant Field Values

POSITION_X_SPREAD

private final float POSITION_X_SPREAD

POSITION_Y_MIN

private final float POSITION_Y_MIN

POSITION_Y_MAX

private final float POSITION_Y_MAX

POSITION_Y_NOMINAL

private final float POSITION_Y_NOMINAL
See Also:
Constant Field Values

POSITION_Y_STEP

private final float POSITION_Y_STEP
See Also:
Constant Field Values

POSITION_Y_OUTSIDE

private final float POSITION_Y_OUTSIDE

POSITION_Y_SPREAD

private final float POSITION_Y_SPREAD

POSITION_Z_MIN

private final float POSITION_Z_MIN

POSITION_Z_MAX

private final float POSITION_Z_MAX

POSITION_Z_NOMINAL

private final float POSITION_Z_NOMINAL

POSITION_Z_STEP

private final float POSITION_Z_STEP
See Also:
Constant Field Values

POSITION_Z_SPREAD

private final float POSITION_Z_SPREAD

POSITION_XZ_CORNER_FACTOR

private final float POSITION_XZ_CORNER_FACTOR
See Also:
Constant Field Values

ATTITUDE_PITCH_NOMINAL

private final float ATTITUDE_PITCH_NOMINAL
See Also:
Constant Field Values

ATTITUDE_ROLL_NOMINAL

private final float ATTITUDE_ROLL_NOMINAL
See Also:
Constant Field Values

ATTITUDE_YAW_NOMINAL

private final float ATTITUDE_YAW_NOMINAL
See Also:
Constant Field Values

ATTITUDE_STEP_PITCH

private final float ATTITUDE_STEP_PITCH
See Also:
Constant Field Values

ATTITUDE_STEP_ROLL

private final float ATTITUDE_STEP_ROLL
See Also:
Constant Field Values

ATTITUDE_STEP_YAW

private final float ATTITUDE_STEP_YAW
See Also:
Constant Field Values

ATTITUDE_ORBIT_YAW

private final float ATTITUDE_ORBIT_YAW
See Also:
Constant Field Values

ATTITUDE_OUTSIDE

private final float ATTITUDE_OUTSIDE
See Also:
Constant Field Values

ATTITUDE_DAMPER_PITCH

private final float ATTITUDE_DAMPER_PITCH
See Also:
Constant Field Values

ATTITUDE_DAMPER_YAW

private final float ATTITUDE_DAMPER_YAW
See Also:
Constant Field Values

FIELD_OF_VIEW_HORIZONTAL

private final float FIELD_OF_VIEW_HORIZONTAL
See Also:
Constant Field Values

FIELD_OF_VIEW_VERTICAL

private final float FIELD_OF_VIEW_VERTICAL
See Also:
Constant Field Values

FIELD_OF_VIEW_HORIZONTAL_MIDPOINT

private final float FIELD_OF_VIEW_HORIZONTAL_MIDPOINT
See Also:
Constant Field Values

FIELD_OF_VIEW_VERTICAL_MIDPOINT

private final float FIELD_OF_VIEW_VERTICAL_MIDPOINT
See Also:
Constant Field Values

CENTER_AXIS_TWEAK

private final float CENTER_AXIS_TWEAK
See Also:
Constant Field Values

AUTOYAW_FRAME_OFFSET

private final int AUTOYAW_FRAME_OFFSET
See Also:
Constant Field Values

AUTOYAW_INCREMENT

private final int AUTOYAW_INCREMENT
See Also:
Constant Field Values

m_screen_dimensions

private Dimensions m_screen_dimensions

m_screen_frame_min

private Position m_screen_frame_min

m_screen_frame_max

private Position m_screen_frame_max

m_field_of_view_scale_x

private float m_field_of_view_scale_x

m_field_of_view_scale_y

private float m_field_of_view_scale_y

m_mouse_position

private Position m_mouse_position

m_position

private Position m_position

m_position_gradient

private Position m_position_gradient

m_attitude

private Attitude m_attitude

m_attitude_fov

private Attitude m_attitude_fov

m_attitude_head

private Attitude m_attitude_head

m_attitude_damper_min

private Attitude m_attitude_damper_min

m_attitude_damper_max

private Attitude m_attitude_damper_max

SCREEN_CAPTURE_FILENAME_PREFIX

private final java.lang.String SCREEN_CAPTURE_FILENAME_PREFIX
See Also:
Constant Field Values
Constructor Detail

SandboxController

public SandboxController(SnapCanvas3D canvas,
                         javax.media.j3d.BranchGroup branch_group,
                         com.sun.j3d.utils.universe.SimpleUniverse universe,
                         Sandbox sandbox)
Creates a new controller for a sandbox.

Parameters:
canvas - - the Java3D canvas of the sandbox
branch_group - - the root branch group of the tree displayed on the canvas
universe - - the universe where the branch group resides
sandbox - - the sandbox to control
Method Detail

assumeNominalView

private void assumeNominalView()
Resets the position and attitudes to sandbox-center looking toward the back.


buildHeadUpDisplay

private void buildHeadUpDisplay(boolean is_initial_build)
Builds and places the head-up display. This needs to be called when the display is initially built (with true) and each time it is resized (with false). Failure to do so will result in erratic behavior.

Parameters:
is_initial_build - - whether this is the first call, which performs required setup work

determinePickSelection

private void determinePickSelection(java.awt.event.MouseEvent event)
                             throws java.lang.Exception
Determines which toy, if any, has been clicked on and hands processing off to the appropriate handler in the controlled sandbox.

Parameters:
event - - the mouse event
Throws:
java.lang.Exception - - if the sandbox has not been committed
See Also:
Sandbox.processSelectionCallback(java.lang.String, java.awt.event.MouseEvent), Sandbox.commit()

getScaledX

private float getScaledX(int x)
Returns a horizontal coordinate in Java3D units based on the current canvas width in pixels.

Parameters:
x - - the x coordinate in pixels
Returns:
the scaled x coordinate

getScaledY

private float getScaledY(int y)
Returns a vertical coordinate in Java3D units based on the current canvas height in pixels.

Parameters:
y - - the y coordinate in pixels
Returns:
the scaled y coordinate

getViewerPosition

public Position getViewerPosition()
Returns the position of the viewer in the controlled sandbox.

Returns:
the position

getViewerAttitude

public Attitude getViewerAttitude()
Returns the combined attitude of the field of view and the head of the viewer in the controlled sandbox. This refers to where the body is be facing and where the head can be looking within the limitations of the body.

This is a read-only composite of two attitudes, which are combined in SandboxController.

Returns:
the attitude

getViewerFieldOfViewAttitude

public Attitude getViewerFieldOfViewAttitude()
Returns the attitude of the field of view of the viewer in the controlled sandbox. This refers to where the body is be facing.

The return value may be modified to change the attitude. Call update() afterwards to reflect the changes.

Returns:
the attitude
See Also:
update(boolean)

getViewerHeadAttitude

public Attitude getViewerHeadAttitude()
Returns the attitude of the head of the viewer in the controlled sandbox. This refers to where the head would be looking based on where the body is facing.

The return value may be modified to change the attitude. Call update() afterwards to reflect the changes.

Returns:
the attitude
See Also:
update(boolean)

initialize

public void initialize()
Configures the event handlers.

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

orbit

private void orbit(float step)
Causes the sandbox to revolve around its center in the given direction and speed.

Parameters:
step - - the number of degrees to move. Positive is clockwise; negative is counterclockwise

processKeyEvent

private void processKeyEvent(java.awt.event.KeyEvent event)
Handles a key event.

Parameters:
event - - the event

processMouseEvent

private void processMouseEvent(java.awt.event.MouseEvent event)
                        throws java.lang.Exception
Handles a mouse event.

Parameters:
event - - the event
Throws:
java.lang.Exception - - if a pick selection fails on a mouse click

processStimulus

public void processStimulus(java.util.Enumeration criteria)
Manages the events that occur and redirects them to the appropriate handler.

Side Effect: writes a warning to stderr if the event cannot be processed.

Specified by:
processStimulus in class javax.media.j3d.Behavior
Parameters:
criteria - - the event criteria
See Also:
Support.writeWarning(java.lang.String, java.lang.String)

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
the String representation
See Also:
Support.toPrettyString(java.lang.String)

update

public void update(boolean force_hud_update)
Updates the contents of the controlled sandbox.

Parameters:
force_hud_update - - whether the head-up dispay should be forced to update; normally it updates after a certain threshold is reach to reduce unnecessary processing

updateFrame

public void updateFrame()
Updates the scaling and other parameters that depend on the size of the frame on which the controlled sandbox resides. If the frame is resized, this must be called; otherwise the mouse events will not correspond with the scene.


updateHeadUpDisplay

private void updateHeadUpDisplay()
Updates the contents of the head-up display.