// DualJoint1D.java import java.awt.* ; import vrml.external.field.*; import vrml.external.exception.*; import vrml.external.Node; import vrml.external.Browser; public class DualJoint1D extends DualSlider1D { String jointName ; public float orientL[] = new float [ 4 ] ; public float orientR[] = new float [ 4 ] ; float loLimit = 0, hiLimit = (float)( Math . PI ) ; EventOutSFRotation orientLOut, orientROut ; EventInSFRotation orientLIn, orientRIn ; Node nodeL = null, nodeR = null ; public DualJoint1D ( String ttl, Vrml2Java vj, String jName, float normalPos, float extremePos ) { super ( ttl ) ; jointName = jName ; loLimit = normalPos ; hiLimit = extremePos ; setXPos ( -1F, LEFT ) ; setXPos ( -1F, RIGHT ) ; if ( vj == null ) return ; try { nodeL = vj . browser . getNode ( "hanim_l_" + jName ) ; orientLIn = (EventInSFRotation)nodeL . getEventIn ( "set_rotation" ) ; orientLOut = (EventOutSFRotation)nodeL . getEventOut ( "rotation_changed" ) ; } catch ( InvalidNodeException ine ) { leftSlider . disable() ; } catch ( InvalidEventInException e ) { System . out . println ( "Error: " + e ) ; } catch ( InvalidEventOutException e ) { System . out . println ( "Error: " + e ) ; } try { nodeR = vj . browser . getNode ( "hanim_r_" + jName ) ; orientRIn = (EventInSFRotation)nodeR . getEventIn ( "set_rotation" ) ; orientROut = (EventOutSFRotation)nodeR . getEventOut ( "rotation_changed" ) ; } catch ( InvalidNodeException ine ) { rightSlider . disable() ; } catch ( InvalidEventInException e ) { System . out . println ( "Error: " + e ) ; } catch ( InvalidEventOutException e ) { System . out . println ( "Error: " + e ) ; } } public boolean handleEvent(Event event) { if ( event . id == Event . ACTION_EVENT && event . target == this ) { if ( nodeL != null ) { float f[] = new float [ 4 ] ; f[0] = 1F ; f[1] = 0F ; f[2] = 0F ; float val = loLimit + ( getXPos ( LEFT ) + 1 ) * ( hiLimit - loLimit ) / 2 ; f[3] = (float)( 2 * Math . PI * val ) ; setOrientation(f,LEFT); } if ( nodeR != null ) { float f[] = new float [ 4 ] ; f[0] = 1F ; f[1] = 0F ; f[2] = 0F ; float val = loLimit + ( getXPos ( RIGHT ) + 1 ) * ( hiLimit - loLimit ) / 2 ; f[3] = (float)( 2 * Math . PI * val ) ; setOrientation(f,RIGHT); } return false ; } return ( super . handleEvent ( event ) ) ; } public float[] getOrientation ( int sType ) { if ( sType == DualSlider1D . LEFT ) { orientL = orientLOut . getValue() ; return orientL ; } if ( sType == DualSlider1D . RIGHT ) { orientR = orientROut . getValue() ; return orientR ; } return null ; } public void setOrientation ( float orientNew[], int sType ) { if ( sType == DualSlider1D . LEFT ) { orientL = orientNew ; orientLIn . setValue ( orientL ) ; } if ( sType == DualSlider1D . RIGHT ) { orientR = orientNew ; orientRIn . setValue ( orientR ) ; } } /** * Get the joint name without the hanim_ or l_ or r_ prefixes. * * @return the name of the joint */ String getJointName() { return ( jointName ) ; } }