⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wandviewbehavior.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Indicates that the echo type is a beam extending from the     * origin of the sensor's local coordinate system to its hotspot.     */    public static final int BEAM = 24 ;    /**     * Indicates that a button listener or read listener has not been     * set for a particular target.  This allows this behavior to use that     * target for a default listener.     */    private static final int UNSET = -1 ;    private View view = null ;    private SensorEventAgent eventAgent = null ;    private String sensor6DName = null ;    private String sensor2DName = null ;    private Shape3D echoGeometry = null ;    private BranchGroup echoBranchGroup = null ;    private TransformGroup echoTransformGroup = null ;    private SensorReadListener echoReadListener6D = null ;    private boolean echoBranchGroupAttached = false ;    private WakeupCondition wakeupConditions = new WakeupOnElapsedFrames(0) ;    private boolean configured = false ;    // The rest of these private fields are all configurable through    // ConfiguredUniverse.     private Sensor sensor6D = null ;    private Sensor sensor2D = null ;    private int x2D = 3 ;    private int y2D = 7 ;    private double threshold2D = 0.0 ;    private int readAction6D = UNSET ;    private int readAction2D = UNSET ;    private ArrayList buttonActions6D = new ArrayList() ;    private ArrayList buttonActions2D = new ArrayList() ;    private double translationSpeed = 0.1 ;    private int translationUnits = PHYSICAL_METERS ;    private int translationTimeBase = PER_SECOND ;    private double accelerationTime = 1.0 ;    private double constantSpeedTime = 8.0 ;    private double fastSpeedFactor = 10.0 ;    private double rotationSpeed = 180.0 ;    private int rotationUnits = DEGREES ;    private int rotationTimeBase = PER_SECOND ;    private int rotationCoords = SENSOR ;    private double scaleSpeed = 2.0 ;    private int scaleTimeBase = PER_SECOND ;    private int transformCenterSource = HOTSPOT ;    private Point3d transformCenter = new Point3d(0.0, 0.0, 0.0) ;    private int resetViewButtonCount6D = 3 ;    private int resetViewButtonCount2D = NONE ;    private int echoType = GNOMON ;    private double echoSize = 0.01 ;    private Color3f echoColor = null ;    private float echoTransparency = 0.0f ;    private Transform3D nominalSensorRotation = null ;    /**     * Parameterless constructor for this behavior.  This is called when this     * behavior is instantiated from a configuration file.     * <p>     * <b>Syntax:</b><br>(NewViewPlatformBehavior <i>&lt;name&gt;</i>     * com.sun.j3d.utils.behaviors.vp.WandViewBehavior)     */    public WandViewBehavior() {        // Create an event agent.        eventAgent = new SensorEventAgent(this) ;        // Set a default SchedulingBounds.        setSchedulingBounds(new BoundingSphere(new Point3d(0.0, 0.0, 0.0),                                               Double.POSITIVE_INFINITY)) ;    }    /**     * Creates a new instance with the specified sensors and echo parameters.     * At least one sensor must be non-<code>null</code>.     * <p>     * This constructor should only be used if either     * <code>SimpleUniverse</code> or <code>ConfiguredUniverse</code> is used     * to set up the view side of the scene graph, or if it is otherwise to be     * attached to a <code>ViewingPlatform</code>.  If this behavior is not     * instantiated from a configuration file then it must then be explicitly     * attached to a <code>ViewingPlatform</code> instance with the     * <code>ViewingPlatform.setViewPlatformBehavior</code> method.     *      * @param sensor6D a six degree of freedom sensor which generates reads     *  relative to the tracker base in physical units; may be     *  <code>null</code>     * @param sensor2D 2D valuator which generates X and Y reads ranging from     *  [-1.0 .. +1.0]; may be <code>null</code>     * @param echoType either <code>GNOMON</code>, <code>BEAM</code>, or     *  <code>NONE</code> for the 6DOF sensor echo     * @param echoSize the width of the 6DOF sensor echo in physical meters;     *  ignored if echoType is <code>NONE</code>     */    public WandViewBehavior(Sensor sensor6D, Sensor sensor2D,                            int echoType, double echoSize) {        this() ;        this.sensor6D = sensor6D ;        this.sensor2D = sensor2D ;        this.echoType = echoType ;        this.echoSize = echoSize ;    }    /**     * Creates a new instance with the specified sensors and a 6DOF sensor     * echo parented by the specified <code>TransformGroup</code>.  At least     * one sensor must be non-<code>null</code>.     * <p>     * This constructor should only be used if either     * <code>SimpleUniverse</code> or <code>ConfiguredUniverse</code> is used     * to set up the view side of the scene graph, or if it is otherwise to be     * attached to a <code>ViewingPlatform</code>.  If this behavior is not     * instantiated from a configuration file then it must then be explicitly     * attached to a <code>ViewingPlatform</code> instance with the     * <code>ViewingPlatform.setViewPlatformBehavior</code> method.     * <p>     * If the echo <code>TransformGroup</code> is non-<code>null</code>, it     * will be added to a new <code>BranchGroup</code> and attached to the     * <code>ViewingPlatform</code>, where its transform will be updated in     * response to the sensor reads.  Capabilities to allow writing its     * transform and to read, write, and extend its children will be set.  The     * echo geometry is assumed to incorporate the position and orientation of     * the 6DOF sensor hotspot.     *      * @param sensor6D a six degree of freedom sensor which generates reads     *  relative to the tracker base in physical units; may be     *  <code>null</code>     * @param sensor2D 2D valuator which generates X and Y reads ranging from     *  [-1.0 .. +1.0]; may be <code>null</code>     * @param echo a <code>TransformGroup</code> containing the visible echo     *  which will track the 6DOF sensor's position and orientation, or     *  <code>null</code> for no echo     */    public WandViewBehavior(Sensor sensor6D, Sensor sensor2D,			    TransformGroup echo) {        this() ;        this.sensor6D = sensor6D ;        this.sensor2D = sensor2D ;	if (echo != null) {	    echo.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE) ;	    echo.setCapability(Group.ALLOW_CHILDREN_READ) ;	    echo.setCapability(Group.ALLOW_CHILDREN_WRITE) ;	    echo.setCapability(Group.ALLOW_CHILDREN_EXTEND) ;	}        this.echoTransformGroup = echo ;    }    /**     * Creates a new instance with the specified sensors and a 6DOF sensor     * echo parented by the specified <code>TransformGroup</code>.  At least     * one sensor must be non-<code>null</code>.     * <p>     * This constructor should only be used if <code>SimpleUniverse</code> or     * <code>ConfiguredUniverse</code> is <i>not</i> used to set up the view     * side of the scene graph.  The application must set up the view side     * itself and supply references to the <code>View</code> and the     * <code>TransformGroup</code> containing the view platform transform.     * <code>ViewingPlatform.setViewPlatformBehavior</code> must <i>not</i>     * be called, and this behavior must be explicitly added to the virtual     * universe by the application.     * <p>     * If the echo <code>TransformGroup</code> is non-<code>null</code>, it     * will only be used to update its associated transform with the position     * and orientation of a 6DOF sensor (if supplied).  The application is     * responsible for adding the echo to the virtual universe.  The echo     * geometry is assumed to incorporate the position and orientation of the     * 6DOF sensor hotspot.     *      * @param sensor6D a six degree of freedom sensor which generates reads     *  relative to the tracker base in physical units; may be     *  <code>null</code>     * @param sensor2D 2D valuator which generates X and Y reads ranging from     *  [-1.0 .. +1.0]; may be <code>null</code>     * @param view a reference to the <code>View</code> attached to the      *  <code>ViewPlatform</code> to be manipulated by this behavior     * @param viewTransform a <code>TransformGroup</code> containing the view     *  platform transform; appropriate capabilities to update the transform     *  must be set     * @param homeTransform a <code>Transform3D</code> containing the     *  view transform to be used when the view is reset; may be     *  <code>null</code> for identity     * @param echo a <code>TransformGroup</code> containing the visible echo     *  which will track the 6DOF sensor's position and orientation, or     *  <code>null</code> for no echo; appropriate capabilities to update the     *  transform must be set     */    public WandViewBehavior(Sensor sensor6D, Sensor sensor2D,			    View view, TransformGroup viewTransform,			    Transform3D homeTransform, TransformGroup echo) {        this() ;        this.sensor6D = sensor6D ;        this.sensor2D = sensor2D ;	this.view = view ;	this.targetTG = viewTransform ;        this.echoTransformGroup = echo ;        if (homeTransform == null)            setHomeTransform(new Transform3D()) ;	else	    setHomeTransform(homeTransform) ;    }    /**     * Initializes and configures this behavior.     * NOTE: Applications should <i>not</i> call this method. It is called by     * the Java 3D behavior scheduler.     */    public void initialize() {        // Don't configure the sensors and echo after the first time.        if (!configured) {            configureSensorActions() ;	    // Configure an echo only if a ViewingPlatform is in use.	    if (vp != null) {		if (echoTransformGroup == null &&		    sensor6D != null && readAction6D == ECHO) {		    configureEcho() ;		}		if (echoTransformGroup != null) {		    echoBranchGroup = new BranchGroup() ;		    echoBranchGroup.setCapability			(BranchGroup.ALLOW_DETACH) ;		    echoBranchGroup.setCapability			(BranchGroup.ALLOW_CHILDREN_READ) ;		    echoBranchGroup.setCapability			(BranchGroup.ALLOW_CHILDREN_WRITE) ;		    echoBranchGroup.addChild(echoTransformGroup) ;		    echoBranchGroup.compile() ;		}		attachEcho() ;	    }            configured = true ;        }        wakeupOn(wakeupConditions) ;    }    /**     * Processes a stimulus meant for this behavior.       * NOTE: Applications should <i>not</i> call this method. It is called by     * the Java 3D behavior scheduler.     */    public void processStimulus(Enumeration criteria) {        // Invoke the sensor event dispatcher.        eventAgent.dispatchEvents() ;        // Wake up on the next frame.        wakeupOn(wakeupConditions) ;    }    /**     * Enables or disables this behavior.  The default state is enabled.     * @param enable true or false to enable or disable this behavior     */    public void setEnable(boolean enable) {        if (enable == getEnable()) {            return ;	}	else if (enable) {	    attachEcho() ;	}	else {	    detachEcho() ;	}        super.setEnable(enable) ;    }        /**     * Sets the <code>ViewingPlatform</code> for this behavior.  If a subclass     * overrides this method, it must call     * <code>super.setViewingPlatform(vp)</code>.  NOTE: Applications should     * <i>not</i> call this method.  It is called by the     * <code>ViewingPlatform</code>.     */    public void setViewingPlatform(ViewingPlatform vp) {        super.setViewingPlatform(vp) ;        if (vp == null) {	    detachEcho() ;            return ;        }	Viewer[] viewers = vp.getViewers() ;	if (viewers != null) {	    // Get the View from the first Viewer attached to the	    // ViewingPlatform.  Multiple Viewers are not supported.	    if (viewers.length != 0 && viewers[0] != null)		view = viewers[0].getView() ;	    if (viewers.length > 1)		throw new RuntimeException("multiple Viewers not supported") ;	}	if (view == null) {	    // Fallback to the first View attached to a live ViewPlatform.	    view = getView() ;	}	if (view == null) {	    // This behavior requires a view.  Bail.	    throw new RuntimeException("a view is not available") ;	}        // Get the top-most TransformGroup in the ViewingPlatform.        // ViewPlatformBehavior retrieves the bottom-most which won't work        // if there are multiple TransformGroups.        targetTG = vp.getMultiTransformGroup().getTransformGroup(0) ;        // Should be an API for checking if homeTransform is null.        if (homeTransform == null)            setHomeTransform(new Transform3D()) ;	attachEcho() ;    }        /**     * Attaches the echo BranchGroup to the ViewingPlatform if appropriate.     */    private void attachEcho() {	if (vp != null &&	    echoBranchGroup != null && !echoBranchGroupAttached) {	    vp.addChild(echoBranchGroup) ;	    echoBranchGroupAttached = true ;	}    }    /**     * Detaches the echo BranchGroup from the ViewingPlatform if appropriate.     */    private void detachEcho() {	if (echoBranchGroup != null && echoBranchGroupAttached) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -