#VRML V2.0 utf8 # Filename: BeamConePROTO.wrl # # Purpose: Produce wireframe or transparent beam cones. Typical uses include # propeller/thruster water flow or line-of-sight sonar/radar/light beams. # Negative range values invert base and apex at same relative location. # # Author: Don Brutzman # # Revised: 31 July 2000 # # Related: BeamConeEXAMPLE.wrl # # Default: Beam with apex at (0,0,0) and base of radius 1 in x-z plane at (1,0,0) # # URL: http://web.nps.navy.mil/~brutzman/vrtp/demo/auv/BeamConePROTO.wrl # http://www.web3D.org/WorkingGroups/vrtp/demo/auv/BeamConePROTO.wrl PROTO BeamCone [ eventIn SFBool detect # is a target return detected? eventIn SFFloat range # meters along x axis field SFFloat defaultRange 1 # used until eventIn range sent field SFFloat beamHeightDegrees 10 # degrees across y axis field SFFloat beamWidthDegrees 10 # degrees across z axis field SFColor noDetectionColor .3 .5 .5 field SFColor detectionColor .8 .1 .1 field SFBool wireframe TRUE # wireframe drawn field SFBool solid TRUE # solid cone drawn field SFFloat transparency 0 # 1 = fully transparent, wireframe only ] { DEF BEAM_CONTROL Transform { # scaled by range/beamHeightDegrees/beamWidthDegrees/direction inputs children [ DEF WIREFRAME_SWITCH Switch { whichChoice 0 choice [ WorldInfo { } # null node => no wireframe beam Shape { appearance Appearance { material DEF WIRE_COLOR Material { emissiveColor IS detectionColor transparency IS transparency } } geometry IndexedLineSet { coord Coordinate { point [ # circle outline 0 0.0 0.0, 1 1.0 0.0, 1 .86 .50, 1 .50 .86, 1 0.0 1.0, 1 -.50 .86, 1 -.86 .50, 1 -1.0 0.0, 1 -.86 -.50, 1 -.50 -.86, 1 0.0 -1.0, 1 .50 -.86, 1 .86 -.50, 1 0.0 0.0 ] } coordIndex [ 1 2 3 4 5 6 7 8 9 10 11 12 1 -1, # cone base 0 1 -1, 0 2 -1, 0 3 -1, 0 4 -1, # cone sides 0 5 -1, 0 6 -1, 0 7 -1, 0 8 -1, 0 9 -1, 0 10 -1, 0 11 -1, 0 12 -1, 0 13 -1 # centerline ] } } ] } DEF SOLID_SWITCH Switch { whichChoice 0 choice [ WorldInfo { } # null node => no solid beam Transform { translation .5 0 0 # shift cone along x axis to line up with wireframe rotation 0 0 1 1.5708 # rotate cone apex from +y axis to -x axis children [ Shape { appearance Appearance { material DEF CONE_COLOR Material { emissiveColor IS detectionColor transparency IS transparency } } geometry Cone { height 1 # bottomRadius 1 # default value bottom FALSE } } ] } ] } ] } DEF DETECTION Script { eventIn SFBool detect IS detect field SFBool wireframe IS wireframe field SFBool solid IS solid field SFColor noDetectionColor IS noDetectionColor field SFColor detectionColor IS detectionColor field SFFloat transparency IS transparency eventOut SFColor beamColor eventOut SFInt32 wireframeChoice eventOut SFInt32 solidChoice url "javascript: function initialize () { beamColor = noDetectionColor; if (wireframe == TRUE) wireframeChoice = 1; if (solid == TRUE) solidChoice = 1; } function detect (newDetect, timeStamp) { if (newDetect) beamColor = detectionColor; else beamColor = noDetectionColor; } " # Debug statements: print() and trace() work on CosmoPlayer, # but neither works on Worldview... :( # trace (' wireframe =', wireframe); # trace (' solid =', solid); # trace (' detectionColor =', detectionColor); # trace (' transparency =', transparency); # trace (' newDetect =', newDetect); # trace (' beamColor =', beamColor); # trace (' wireframeChoice =', wireframeChoice); # trace (' solidChoice =', solidChoice); } ROUTE DETECTION.beamColor TO WIRE_COLOR.emissiveColor ROUTE DETECTION.beamColor TO CONE_COLOR.emissiveColor ROUTE DETECTION.wireframeChoice TO WIREFRAME_SWITCH.whichChoice ROUTE DETECTION.solidChoice TO SOLID_SWITCH.whichChoice DEF BEAM_CALCULATE Script { eventIn SFFloat range IS range field SFFloat defaultRange IS defaultRange field SFFloat beamHeightDegrees IS beamHeightDegrees field SFFloat beamWidthDegrees IS beamWidthDegrees eventOut SFVec3f beamScale eventOut SFRotation direction eventOut SFVec3f reverseOffset url "javascript: function initialize () { var beamHeightFactor; var beamWidthFactor; beamHeightFactor= Math.sin ((beamHeightDegrees * 3.141592653 / 180.0) / 2.0); beamWidthFactor = Math.sin ((beamWidthDegrees * 3.141592653 / 180.0) / 2.0); if (defaultRange == 0) defaultRange = .0001; beamScale = new SFVec3f ( defaultRange, defaultRange * beamHeightFactor, defaultRange * beamWidthFactor); } function range (newRange, timeStamp) { var beamHeightFactor; var beamWidthFactor; beamHeightFactor= Math.sin ((beamHeightDegrees * 3.141592653 / 180.0) / 2.0); beamWidthFactor = Math.sin ((beamWidthDegrees * 3.141592653 / 180.0) / 2.0); if (newRange < 0) { direction = new SFRotation (0, 1, 0, 3.141592653); reverseOffset = new SFVec3f (- newRange, 0, 0); beamScale = new SFVec3f ( -newRange, -newRange * beamHeightFactor, -newRange * beamWidthFactor); } else if (newRange == 0) { direction = new SFRotation (0, 1, 0, 0); reverseOffset = new SFVec3f (0, 0, 0); beamScale = new SFVec3f ( .0001, .0001, .0001 ); } else { direction = new SFRotation (0, 1, 0, 0); reverseOffset = new SFVec3f (0, 0, 0); beamScale = new SFVec3f ( newRange, newRange * beamHeightFactor, newRange * beamWidthFactor); } } " # Note above that VRML scale factor triplets all equal to zero are not allowed # Debug statements: print() and trace() work on CosmoPlayer, # but neither works on Worldview... :( # trace (' beamWidthDegrees =', beamWidthDegrees); # trace (' beamHeightDegrees=', beamHeightDegrees); # trace (' initial beamScale=', beamScale); } ROUTE BEAM_CALCULATE.beamScale TO BEAM_CONTROL.scale ROUTE BEAM_CALCULATE.direction TO BEAM_CONTROL.rotation ROUTE BEAM_CALCULATE.reverseOffset TO BEAM_CONTROL.translation } ############################################################################# # Example use of this PROTO file is in BeamConeEXAMPLE.wrl # Redirection text in case a user examines this PROTO file via a 3D browser: Anchor { url [ "BeamConeEXAMPLE.wrl" "file:///C|/vrtp/demo/auv/BeamConeEXAMPLE.wrl" # default PC installation "file:///D|/vrtp/demo/auv/BeamConeEXAMPLE.wrl" # alternate PC installation "http://web.nps.navy.mil/~brutzman/vrtp/demo/auv/BeamConeEXAMPLE.wrl" "http://www.web3D.org/WorkingGroups/vrtp/demo/auv/BeamConeEXAMPLE.wrl" ] children [ Shape { appearance Appearance { material Material { diffuseColor 0 1.0 1.0 emissiveColor 0 1.0 1.0 } } geometry Text { string [ "BeamConePROTO.wrl" "is a PROTO definition file." "" "To see an example scene," "click this text and view" "BeamConeEXAMPLE.wrl" ] fontStyle FontStyle { justify [ "MIDDLE" "MIDDLE" ] } } } ] } Viewpoint { position 0 0 15 } # default viewpoint for this backup Anchor node #############################################################################