📄 wandviewbehavior.java
字号:
echoBranchGroup.detach() ; echoBranchGroupAttached = false ; } } /** * Creates the sensor listeners for a 6DOF sensor and/or a 2D valuator * sensor using the predefined button and read listeners and the * configured action bindings. * <p> * This is invoked the first time <code>initialize</code> is called. This * method can be overridden by subclasses to modify the configured * bindings or introduce other configuration parameters. */ protected void configureSensorActions() { SensorButtonListener[] sbls ; int buttonCount, buttonActionCount ; SimpleUniverse universe = null ; if (vp != null) universe = vp.getUniverse() ; if (universe != null && universe instanceof ConfiguredUniverse) { // Check if sensors were instantiated from a config file. Map sensorMap = ((ConfiguredUniverse)universe).getNamedSensors() ; if (sensor2D == null && sensor2DName != null) { sensor2D = (Sensor)sensorMap.get(sensor2DName) ; if (sensor2D == null) throw new IllegalArgumentException ("\nsensor " + sensor2DName + " not found") ; } if (sensor6D == null && sensor6DName != null) { sensor6D = (Sensor)sensorMap.get(sensor6DName) ; if (sensor6D == null) throw new IllegalArgumentException ("\nsensor " + sensor6DName + " not found") ; } } if (sensor6D != null) { // Assign default read action. if (readAction6D == UNSET) readAction6D = ECHO ; // Register the read listener. if (readAction6D == ECHO) { echoReadListener6D = new EchoReadListener6D() ; eventAgent.addSensorReadListener (sensor6D, echoReadListener6D) ; } // Check for button range. buttonCount = sensor6D.getSensorButtonCount() ; buttonActionCount = buttonActions6D.size() ; if (buttonActionCount > buttonCount) throw new IllegalArgumentException ("\nbutton index " + (buttonActionCount-1) + " >= number of buttons (" + buttonCount +")") ; // Assign default button actions. if (buttonCount > 2 && (buttonActionCount < 3 || buttonActions6D.get(2) == null)) setButtonAction6D(2, TRANSLATE_BACKWARD) ; if (buttonCount > 1 && (buttonActionCount < 2 || buttonActions6D.get(1) == null)) setButtonAction6D(1, TRANSLATE_FORWARD) ; if (buttonCount > 0 && (buttonActionCount < 1 || buttonActions6D.get(0) == null)) setButtonAction6D(0, GRAB_VIEW) ; buttonActionCount = buttonActions6D.size() ; if (buttonActionCount > 0) { // Set up the button listener array. sbls = new SensorButtonListener[buttonCount] ; for (int i = 0 ; i < buttonActionCount ; i++) { Integer button = (Integer)buttonActions6D.get(i) ; if (button != null) { int action = button.intValue() ; if (action == NONE) sbls[i] = null ; else if (action == GRAB_VIEW) sbls[i] = new GrabViewListener6D() ; else if (action == TRANSLATE_FORWARD) sbls[i] = new TranslationListener6D(false) ; else if (action == TRANSLATE_BACKWARD) sbls[i] = new TranslationListener6D(true) ; else if (action == ROTATE_CCW) sbls[i] = new RotationListener6D(false) ; else if (action == ROTATE_CW) sbls[i] = new RotationListener6D(true) ; else if (action == SCALE_UP) sbls[i] = new ScaleListener6D(false) ; else if (action == SCALE_DOWN) sbls[i] = new ScaleListener6D(true) ; } } // Register the button listeners. eventAgent.addSensorButtonListeners(sensor6D, sbls) ; } // Check for reset view action. if (resetViewButtonCount6D != NONE) { SensorInputAdaptor r = new ResetViewListener(sensor6D, resetViewButtonCount6D) ; eventAgent.addSensorButtonListener(sensor6D, r) ; eventAgent.addSensorReadListener(sensor6D, r) ; } } if (sensor2D != null) { // Assign default read action if (readAction2D == UNSET) readAction2D = ROTATION ; // Register the read listener. if (readAction2D == ROTATION) { SensorReadListener r = new RotationListener2D(sensor2D, sensor6D) ; eventAgent.addSensorReadListener(sensor2D, r) ; } else if (readAction2D == TRANSLATION) { SensorReadListener r = new TranslationListener2D(sensor2D, sensor6D) ; eventAgent.addSensorReadListener(sensor2D, r) ; } else if (readAction2D == SCALE) { SensorReadListener r = new ScaleListener2D(sensor2D, sensor6D) ; eventAgent.addSensorReadListener(sensor2D, r) ; } // Check for button range. buttonCount = sensor2D.getSensorButtonCount() ; buttonActionCount = buttonActions2D.size() ; if (buttonActionCount > buttonCount) throw new IllegalArgumentException ("\nbutton index " + (buttonActionCount-1) + " >= number of buttons (" + buttonCount +")") ; // No default button actions are defined for the 2D sensor. if (buttonActionCount > 0) { // Set up the button listener array. sbls = new SensorButtonListener[buttonCount] ; for (int i = 0 ; i < buttonActionCount ; i++) { Integer button = (Integer)buttonActions2D.get(i) ; if (button != null) { int action = button.intValue() ; if (action == NONE) sbls[i] = null ; else if (action == ROTATION) sbls[i] = new RotationListener2D (sensor2D, sensor6D) ; else if (action == TRANSLATION) sbls[i] = new TranslationListener2D (sensor2D, sensor6D) ; else if (action == SCALE) sbls[i] = new ScaleListener2D (sensor2D, sensor6D) ; } } // Register the button listeners. eventAgent.addSensorButtonListeners(sensor2D, sbls) ; } // Check for reset view action. if (resetViewButtonCount2D != NONE) { SensorInputAdaptor r = new ResetViewListener(sensor2D, resetViewButtonCount2D) ; eventAgent.addSensorButtonListener(sensor2D, r) ; eventAgent.addSensorReadListener(sensor2D, r) ; } } } /** * Creates a 6DOF sensor echo according to configuration parameters. This * is done only if a 6DOF sensor has been specified, the 6DOF sensor read * action has been set to echo the sensor position, the echo transform * group has not already been set, and a ViewingPlatform is in use. This * is invoked the first time <code>initialize</code> is called to set this * behavior live, but before the echo transform group is added to a * <code>BranchGroup</code> and made live. This method can be overridden * to support other echo geometry. */ protected void configureEcho() { Point3d hotspot = new Point3d() ; sensor6D.getHotspot(hotspot) ; if (echoType == GNOMON) { Transform3D gnomonTransform = new Transform3D() ; if (nominalSensorRotation != null) { gnomonTransform.set(nominalSensorRotation) ; gnomonTransform.invert() ; } gnomonTransform.setTranslation(new Vector3d(hotspot)) ; echoGeometry = new SensorGnomonEcho (gnomonTransform, 0.1 * echoSize, 0.5 * echoSize, true) ; } else if (echoType == BEAM) { echoGeometry = new SensorBeamEcho(hotspot, echoSize, true) ; } if (echoGeometry != null) { Appearance a = echoGeometry.getAppearance() ; if (echoColor != null) { Material m = a.getMaterial() ; m.setDiffuseColor(echoColor) ; } if (echoTransparency != 0.0f) { TransparencyAttributes ta = a.getTransparencyAttributes() ; ta.setTransparencyMode(TransparencyAttributes.BLENDED) ; ta.setTransparency(echoTransparency) ; // Use order independent additive blend for gnomon. if (echoGeometry instanceof SensorGnomonEcho) ta.setDstBlendFunction(TransparencyAttributes.BLEND_ONE) ; } echoTransformGroup = new TransformGroup() ; echoTransformGroup.setCapability (TransformGroup.ALLOW_TRANSFORM_WRITE) ; echoTransformGroup.setCapability(Group.ALLOW_CHILDREN_READ) ; echoTransformGroup.setCapability(Group.ALLOW_CHILDREN_WRITE) ; echoTransformGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND) ; echoTransformGroup.addChild(echoGeometry) ; } } /** * A base class for implementing some of this behavior's listeners. */ public class ListenerBase extends SensorInputAdaptor { /** * The initial transform from view platform coordinates to virtual * world coordinates, set by <code>initAction</code>. */ protected Transform3D viewPlatformToVworld = new Transform3D() ; /** * The initial transform from tracker base coordinates to virtual * world coordinates, set by <code>initAction</code>. */ protected Transform3D trackerToVworld = new Transform3D() ; /** * The initial transform from sensor coordinates to virtual * world coordinates, set by <code>initAction</code>. */ protected Transform3D sensorToVworld = new Transform3D() ; /** * The initial transform from sensor coordinates to tracker base * coordinates, set by <code>initAction</code>. */ protected Transform3D sensorToTracker = new Transform3D() ; // Private fields. private Transform3D trackerToSensor = new Transform3D() ; private boolean active = false ; // Misc. temporary objects. private double[] s3Tmp = new double[3] ; private double[] m16Tmp = new double[16] ; private Vector3d v3dTmp = new Vector3d() ; private Transform3D t3dTmp = new Transform3D() ; /** * Initializes the listener action. Subclasses must call this before * starting the action, either from <code>pressed</code> or when a 2D * valuator exits the deadzone threshold. * * @param s reference to a 6DOF sensor if used by the listener; may * be <code>null</code> */ protected void initAction(Sensor s) { targetTG.getTransform(viewPlatformToVworld) ; active = true ; if (s == null) return ; // Kludge to get the static trackerToVworld for this // frame. This is computed from the two separate sensor reads // below, which are close enough to identical to work. The // Java 3D View class needs a getTrackerBaseToVworld() method // (see Java 3D RFE 4676808). s.getRead(sensorToTracker) ; view.getSensorToVworld(s, sensorToVworld) ; trackerToSensor.invert(sensorToTracker) ; trackerToVworld.mul(sensorToVworld, trackerToSensor) ; } /** * Ends the action. Subclasses must be call this from * <code>released</code> or when a 2D valuator enters the deadzone * threshold. * * @param s reference to a 6DOF sensor if used by the listener; may * be <code>null</code> */ protected void endAction(Sensor s) { active = false ; } /** * Returns true if the listener is currently active; that is, if * <code>initAction</code> has been called but not yet * <code>endAction</code>. * * @return true if the listener is active, false otherwise */ protected boolean isActive() { return active ; } public void pressed(SensorEvent e) { initAction(e.getSensor()) ; } public void released(SensorEvent e) { endAction(e.getSensor()) ; } /** * Gets the physical to virtual scale. */ protected double getPhysicalToVirtualScale() { view.getCanvas3D(0).getImagePlateToVworld(t3dTmp) ; t3dTmp.get(m16Tmp) ; return Math.sqrt(m16Tmp[0]*m16Tmp[0] + m16Tmp[1]*m16Tmp[1] + m16Tmp[2]*m16Tmp[2]) ; } /** * Gets the scale from physical units to view platform units. */ protected double getPhysicalToViewPlatformScale() { double vpToVirtualScale ; targetTG.getTransform(t3dTmp) ; t3dTmp.get(m16Tmp) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -