home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 March / VPR9803A.ISO / Netscape / COSMO.Z / COSMO.WRL < prev    next >
Text File  |  1997-05-30  |  31KB  |  998 lines

  1. #VRML V2.0 utf8
  2.  
  3. # Cosmo Player 1.0 UI
  4.  
  5. # This VRML file defines the appearance and behavior of the
  6. # Cosmo Player dashboard.
  7. #
  8. # WARNING: Making changes to this file is not recommended.
  9. # Future releases of Cosmo Player are NOT GUARANTEED to
  10. # support this file format!
  11. #
  12. # Do not open back panel; no user serviceable parts inside.
  13. # The manufacturers of this VRML dashboard are not responsible for
  14. # any liabilities or damages resulting from this VRML dashboard.  Ask
  15. # your doctor or pharmacist.  You may or may not have additional
  16. # rights which may vary from state to state.  Not recommended for
  17. # children under twelve.  Parental guidance discouraged and frowned
  18. # upon.  Pencils, additional paper, and batteries not included.  Some
  19. # assembly may be required.  Does not come with any other figures.
  20. # Your mileage may vary.
  21.  
  22.  
  23. EXTERNPROTO LayoutHint [ field SFString placement
  24.                          field SFFloat widthFraction
  25.                          field SFFloat heightFraction
  26.                          field SFInt32 maxPixelWidth
  27.                          field SFInt32 maxPixelHeight ]
  28. [ "urn:inet:netscape.com:vrml/LayoutHint.wrl" ]
  29.  
  30. EXTERNPROTO CosmoBrowser [
  31.   eventIn  SFBool   set_gravity
  32.   eventIn  SFBool   set_collision
  33.   eventIn  SFBool   set_point
  34.   eventIn  SFString set_navType
  35.   eventIn  SFFloat  set_speed
  36.   eventIn  SFBool   set_headlight
  37.   eventIn  SFFloat  set_headlightIntensity
  38.   eventIn  SFBool   set_anyMode
  39.   eventIn  SFInt32  set_straighten
  40.   eventIn  SFInt32  set_showHelp
  41.  
  42.   eventOut SFBool   gravity_changed
  43.   eventOut SFBool   collision_changed
  44.   eventOut SFBool   point_changed
  45.   eventOut SFString navType_changed
  46.   eventOut SFFloat  speed_changed
  47.   eventOut SFBool   headlight_changed
  48.   eventOut SFFloat  headlightIntensity_changed
  49.   eventOut SFBool   anyMode_changed
  50.   eventOut MFInt32  rect_changed
  51.   eventOut SFInt32  numViewpoints_changed
  52.   eventOut MFString navTypeList_changed
  53. ]
  54. [ "urn:inet:netscape.com:vrml/CosmoBrowser.wrl" ]
  55.  
  56. DEF COSMOBROWSER CosmoBrowser { }
  57.  
  58.  
  59. #
  60. # Black dashboard background
  61. #
  62. Group {
  63.   children [
  64.     LayoutHint {
  65.       placement BOTTOMCENTER
  66.       widthFraction 450.0   # hand-tweaked
  67.       heightFraction 0.085
  68.       maxPixelHeight 40
  69.     }
  70.  
  71.     # Dummy TouchSensor here to absorb any mouse clicks on the 
  72.     # dashboard background (so POINT mode can't click through it)
  73.     TouchSensor { }
  74.  
  75.     Group {
  76.       children [
  77.         Shape {
  78.           appearance Appearance {
  79.             material Material {
  80.               ambientIntensity 0
  81.               diffuseColor  0 0 0
  82.               shininess 0
  83.             }
  84.           }
  85.           geometry IndexedFaceSet {
  86.             ccw TRUE
  87.             solid TRUE
  88.             coord Coordinate {
  89.           point [ 0 4 -0.1, 200000 4 -0.1, 0 37 -0.1, 200000 37 -0.1 ]
  90.         }
  91.             coordIndex [ 0, 1, 3, -1,  3, 2, 0, -1 ]
  92.           }
  93.         }
  94.       ]
  95.     }
  96.   ]
  97. }
  98.  
  99.  
  100. #
  101. # Cosmo logo at far right of dashboard
  102. #
  103. Group {
  104.   children [
  105.     LayoutHint {
  106.       placement BOTTOMRIGHT
  107.       widthFraction  0.169    # the dashboard buttons use the other 0.831
  108.       heightFraction 0.08
  109.       maxPixelHeight 36
  110.     }
  111.  
  112.     Anchor {
  113.       url "http://cosmo.sgi.com/" 
  114.       parameter [ "target=newwindow" ]
  115.       description " "   # Don't show any pop-up description on mouseOver
  116.  
  117.       children [
  118.  
  119.     # Dummy TouchSensor here to absorb any mouse clicks on the 
  120.     # dashboard background (so POINT mode can't click through it)
  121.     # (Needed since the *other* dummy TouchSensor is obscured by
  122.     #  this Anchor...)
  123.     TouchSensor { }
  124.  
  125.     Shape {
  126.       geometry IndexedFaceSet {
  127.         coord Coordinate {
  128.           # coords tweaked to correct aspect ratio of cplogo.jpg
  129.           point [ -2.55  1  0,  0  1  0,  0 0  0,  -2.55 0  0 ]
  130.         }
  131.         texCoord TextureCoordinate {
  132.           point [ 0 1,  1 1,  1 0,  0 0 ]
  133.         }
  134.         coordIndex [ 3, 2, 1, 0, -1 ]
  135.         texCoordIndex [ 3, 2, 1, 0, -1 ]
  136.       }
  137.       appearance Appearance {
  138.         material Material {
  139.           ambientIntensity 1
  140.           diffuseColor 0 0 0
  141.         }
  142.         texture ImageTexture {
  143.           url "netscape/cplogo.jpg"
  144.         }
  145.       }
  146.     }
  147.  
  148.     # Some padding to the right of the logo
  149.     Shape {
  150.       geometry IndexedFaceSet {
  151.         coord Coordinate {
  152.           point [ 0  1  0,  0.15  1  0,  0.15 0 0,  0  0  0 ]
  153.         }
  154.         coordIndex [ 3, 2, 1, 0, -1 ]
  155.       }
  156.       appearance Appearance {
  157.         material Material {
  158.           ambientIntensity 1
  159.           diffuseColor 0 0 0
  160.         }
  161.       }
  162.     }
  163.       ]
  164.     }
  165.   ]
  166. }
  167.  
  168.  
  169. PROTO ModeButton [
  170.   # Textures for each possible state:
  171.   # (Mode buttons have 3 possible states; Gravity button has 4)
  172.   field   MFString   state0_url  [ "bogus0.jpg" ]   # OFF / OFF_ENA
  173.   field   MFString   state1_url  [ "bogus1.jpg" ]   # ON  / ON_ENA
  174.   field   MFString   state2_url  [ "bogus2.jpg" ]   # DIS / OFF_DIS
  175.   field   MFString   state3_url  [ "bogus3.jpg" ]   #     / ON_DIS
  176.  
  177.   # Event in from the ModeController:
  178.   eventIn  SFInt32  setState
  179.  
  180.   # Event out to the ModeController:
  181.   eventOut SFTime   clicked
  182. ]
  183. {
  184.   Group {
  185.     children [
  186.       DEF ModeButton_TouchSensor TouchSensor {
  187.         touchTime IS clicked
  188.       }
  189.       DEF ModeButton_Switch Switch {
  190.         whichChoice IS setState
  191.         choice [
  192.           # State 0:
  193.           Shape {
  194.             appearance Appearance {
  195.               material DEF MDB_MATERIAL Material {
  196.                 ambientIntensity 1
  197.                 diffuseColor 0 0 0
  198.                 shininess 0
  199.               }
  200.               texture ImageTexture {
  201.                 url IS state0_url
  202.               }
  203.             }
  204.             geometry DEF MDB_IFS IndexedFaceSet {
  205.               ccw TRUE
  206.               solid TRUE
  207.               coord Coordinate {
  208.                 point [ -11 0 0, 11 0 0, -11 22 0, 11 22 0 ]
  209.               }
  210.               coordIndex [ 0, 1, 3, -1, 3, 2, 0, -1 ]
  211.               texCoord TextureCoordinate {
  212.                 point [ 0 0, 1 0, 0 1, 1 1, 0 0, 1 0, 0 1, 1 1,
  213.                         0 0, 1 0, 0 1, 1 1 ]
  214.               }
  215.               texCoordIndex [ 4, 5, 7, -1,  7, 6, 4, -1 ]
  216.             }
  217.           }
  218.           # State 1:
  219.           Shape {
  220.             appearance Appearance {
  221.               material USE MDB_MATERIAL
  222.               texture ImageTexture {
  223.                 url IS state1_url
  224.               }
  225.             }
  226.             geometry USE MDB_IFS
  227.           }
  228.           # State 2:
  229.           Shape {
  230.             appearance Appearance {
  231.               material USE MDB_MATERIAL
  232.               texture ImageTexture {
  233.                 url IS state2_url
  234.               }
  235.             }
  236.             geometry USE MDB_IFS
  237.           }
  238.           # State 3:
  239.           Shape {
  240.             appearance Appearance {
  241.               material USE MDB_MATERIAL
  242.               texture ImageTexture {
  243.                 url IS state3_url
  244.               }
  245.             }
  246.             geometry USE MDB_IFS
  247.           }
  248.         ]
  249.       }
  250.     ]
  251.   }
  252. }
  253.  
  254.  
  255. PROTO MomentaryButton [
  256.   field   MFString   on_url   [ "bogus1.jpg" ]
  257.   field   MFString   off_url  [ "bogus2.jpg" ]
  258.   field   MFString   dis_url  [ "bogus3.jpg" ]
  259.  
  260.   eventIn  SFBool    enable_in
  261.   eventOut SFInt32   activated
  262. ]
  263. {
  264.   Group {
  265.     children [
  266.       DEF MomentaryButton_TouchSensor TouchSensor { }
  267.       DEF MomentaryButton_Switch Switch {
  268.         whichChoice 0
  269.         choice [
  270.           # Choice 0: off
  271.           Shape {
  272.             appearance Appearance {
  273.               material DEF MMB_MATERIAL Material {
  274.                 ambientIntensity 1
  275.                 diffuseColor 0 0 0
  276.                 shininess 0
  277.               }
  278.               texture ImageTexture {
  279.                 url IS off_url
  280.               }
  281.             }
  282.             geometry DEF MMB_IFS IndexedFaceSet {
  283.               ccw TRUE
  284.               solid TRUE
  285.               coord Coordinate {
  286.                 point [ -11 0 0, 11 0 0, -11 22 0, 11 22 0 ]
  287.               }
  288.               coordIndex [ 0, 1, 3, -1,  3, 2, 0, -1 ]
  289.               texCoord TextureCoordinate {
  290.                 point [ 0 0, 1 0, 0 1, 1 1, 0 0, 1 0, 0 1, 1 1,
  291.                         0 0, 1 0, 0 1, 1 1 ]
  292.               }
  293.               texCoordIndex [ 4, 5, 7, -1,  7, 6, 4, -1 ]
  294.             }
  295.           }
  296.           # Choice 1: on
  297.           Shape {
  298.             appearance Appearance {
  299.               material USE MMB_MATERIAL
  300.               texture ImageTexture {
  301.                 url IS on_url
  302.               }
  303.             }
  304.             geometry USE MMB_IFS
  305.           }
  306.           # Choice 2: dis
  307.           Shape {
  308.             appearance Appearance {
  309.               material USE MMB_MATERIAL
  310.               texture ImageTexture {
  311.                 url IS dis_url
  312.               }
  313.             }
  314.             geometry USE MMB_IFS
  315.           }
  316.         ]
  317.       }
  318.  
  319.       #
  320.       DEF MomentaryButton_Script Script {
  321.         eventIn  SFTime touchTime
  322.         eventIn  SFBool touch_active
  323.         eventIn  SFBool touch_isover
  324.         eventIn  SFBool  enable_in IS enable_in
  325.         eventOut SFInt32 do_it IS activated
  326.         eventOut SFInt32 switch_choice
  327.  
  328.     field SFBool enabled TRUE
  329.  
  330.         url "javascript:
  331.             function enable_in(bool) {
  332.               enabled = bool;
  333.               if (bool) 
  334.                 switch_choice = 0;  // assume 'off' state
  335.               else
  336.                 switch_choice = 2;
  337.             }              
  338.             function touch_active(bool) {
  339.               if (enabled) {
  340.                 if (bool) 
  341.                   switch_choice = 1;
  342.                 else
  343.                   switch_choice = 0;
  344.               }
  345.             }
  346.             function touch_isover(bool) {
  347.               // This is only here to clean up the possible condition
  348.               // of a button being left 'on' after a very quick touch
  349.               if (enabled)
  350.                 switch_choice = 0;
  351.             }
  352.             function touchTime(nav) {
  353.               if (enabled) {
  354.                 do_it = 1;
  355.               }
  356.             }"
  357.       }
  358.     ]
  359.     ROUTE MomentaryButton_TouchSensor.touchTime    TO MomentaryButton_Script.touchTime
  360.     #
  361.     ROUTE MomentaryButton_TouchSensor.isActive TO MomentaryButton_Script.touch_active
  362.     ROUTE MomentaryButton_TouchSensor.isOver TO MomentaryButton_Script.touch_isover
  363.     ROUTE MomentaryButton_Script.switch_choice TO MomentaryButton_Switch.whichChoice
  364.   }    
  365. }
  366.  
  367. PROTO ToggleButton [
  368.   field   MFString   on_url   [ "bogus1.jpg" ]
  369.   field   MFString   off_url  [ "bogus2.jpg" ]
  370.  
  371.   eventIn  SFBool  state_in
  372.   eventOut SFBool  state_out
  373. ]
  374. {
  375.   Group {
  376.     children [
  377.       DEF ToggleButton_TouchSensor TouchSensor { }
  378.       DEF ToggleButton_Switch Switch {
  379.         whichChoice 0
  380.         choice [
  381.           # Choice 0: off
  382.           Shape {
  383.             appearance Appearance {
  384.               material DEF TB_MATERIAL Material {
  385.                 ambientIntensity 1
  386.                 diffuseColor 0 0 0
  387.                 shininess 0.4
  388.               }
  389.               texture ImageTexture {
  390.                 url IS off_url
  391.               }
  392.             }
  393.             geometry DEF TB_IFS IndexedFaceSet {
  394.               ccw TRUE
  395.               solid TRUE
  396.               coord Coordinate {
  397.                 point [ -11 0 0, 11 0 0, -11 22 0, 11 22 0 ]
  398.               }
  399.               coordIndex [ 0, 1, 3, -1,  3, 2, 0, -1 ]
  400.               texCoord TextureCoordinate {
  401.                 point [ 0 0, 1 0, 0 1, 1 1, 0 0, 1 0, 0 1, 1 1,
  402.                         0 0, 1 0, 0 1, 1 1 ]
  403.               }
  404.               texCoordIndex [ 4, 5, 7, -1,  7, 6, 4, -1 ]
  405.             }
  406.           }
  407.           # Choice 1: on
  408.           Shape {
  409.             appearance Appearance {
  410.               material USE TB_MATERIAL
  411.               texture ImageTexture {
  412.                 url IS on_url
  413.               }
  414.             }
  415.             geometry USE TB_IFS
  416.           }
  417.         ]
  418.       }
  419.  
  420.       #
  421.       DEF ToggleButton_Script Script {
  422.         eventIn SFTime touchTime
  423.         #eventIn SFBool touch_active
  424.         eventIn SFBool state_in IS state_in
  425.  
  426.         eventOut SFBool state_out IS state_out
  427.         eventOut SFInt32 switch_choice
  428.  
  429.         url "javascript:
  430.             function touchTime(time) {
  431.               bStor = !bStor;
  432.               state_out = bStor;
  433.               update_choice();
  434.             }
  435.             function update_choice() {
  436.               if (bStor)
  437.                 switch_choice = 1;
  438.               else
  439.                 switch_choice = 0;
  440.             }
  441.             function state_in(bool) {
  442.               bStor = bool;
  443.               update_choice();
  444.             }"
  445.       }
  446.     ]
  447.     ROUTE ToggleButton_TouchSensor.touchTime    TO ToggleButton_Script.touchTime
  448.     ROUTE ToggleButton_Script.switch_choice TO ToggleButton_Switch.whichChoice
  449.   }    
  450. }
  451.  
  452.  
  453. #
  454. # All the dashboard buttons (left-justified on dashboard)
  455. #
  456. Group {
  457.   children [
  458.  
  459.     LayoutHint {
  460.       placement BOTTOMLEFT
  461.       widthFraction 0.831   # the cosmo logo uses the other 0.169
  462.       heightFraction 0.08
  463.       maxPixelHeight 36
  464.     }
  465.  
  466.     Transform {
  467.       children [
  468.  
  469.     # A separate black box behind the dashboard buttons;
  470.     # needed for the LayoutHint above to work correctly:
  471.         Transform {
  472.           translation 0 13 0
  473.           children [
  474.             Shape {
  475.               appearance Appearance {
  476.                 material Material {
  477.           ambientIntensity 0
  478.           diffuseColor 0 0 0
  479.                   shininess 0
  480.                 }
  481.               }
  482.               geometry IndexedFaceSet {
  483.                 ccw TRUE
  484.                 solid TRUE
  485.                 coord Coordinate {
  486.                   point [ -475 -10 -0.1, 115 -10 -0.1,
  487.               -475 25 -0.1, 115 25 -0.1 ]
  488.                 }
  489.                 coordIndex [ 0, 1, 3, -1,  3, 2, 0, -1 ]
  490.               }
  491.             }
  492.           ]
  493.         }
  494.  
  495.         Transform {
  496.           translation -440 13 0
  497.           scale 3 1 1
  498.           children [
  499.             DEF GRAVITY_BUTTON ModeButton {
  500.               state0_url [ "netscape/groff.jpg" ]
  501.               state1_url [ "netscape/gron.jpg" ]
  502.               state2_url [ "netscape/grdisoff.jpg" ]
  503.               state3_url [ "netscape/grdison.jpg" ]
  504.             }
  505.           ]
  506.         }
  507.  
  508.         Transform {
  509.           translation -382 13 0
  510.           scale 2 1 1
  511.           children [
  512.             DEF WALK_MB ModeButton {
  513.               state0_url [ "netscape/waoff.jpg" ]
  514.               state1_url [ "netscape/waon.jpg" ]
  515.               state2_url [ "netscape/wadisoff.jpg" ]
  516.             }
  517.           ]
  518.         }
  519.  
  520.         Transform {
  521.           translation -335 13 0
  522.           scale 2 1 1
  523.           children [
  524.             DEF SLIDE_MB ModeButton {
  525.               state0_url [ "netscape/sloff.jpg" ]
  526.               state1_url [ "netscape/slon.jpg" ]
  527.               state2_url [ "netscape/sldisoff.jpg" ]
  528.             }
  529.           ]
  530.         }
  531.  
  532.         Transform {
  533.           translation -288 13 0
  534.           scale 2 1 1
  535.           children [
  536.             DEF LOOK_MB ModeButton {
  537.               state0_url [ "netscape/looff.jpg" ]
  538.               state1_url [ "netscape/loon.jpg" ]
  539.               state2_url [ "netscape/lodisoff.jpg" ]
  540.             }
  541.           ]
  542.         }
  543.  
  544.         Transform {
  545.           translation -217 13 0
  546.           scale 3 1 1
  547.           children [
  548.             DEF EXAMINE_MB ModeButton {
  549.               state0_url [ "netscape/exoff.jpg" ]
  550.               state1_url [ "netscape/exon.jpg" ]
  551.               state2_url [ "netscape/exdisoff.jpg" ]
  552.             }
  553.           ]
  554.         }
  555.  
  556.         Transform {
  557.           translation -130 13 0
  558.           scale 2 1 1
  559.           children [
  560.             DEF POINT ToggleButton {
  561.               on_url      [ "netscape/poon.jpg" ]
  562.               off_url     [ "netscape/pooff.jpg" ]
  563.             }
  564.           ]          
  565.           ROUTE COSMOBROWSER.point_changed TO POINT.state_in
  566.           ROUTE POINT.state_out            TO COSMOBROWSER.set_point
  567.         }
  568.  
  569.     Transform {
  570.           translation -84 13 0
  571.           scale 1 1 1
  572.           children [
  573.             DEF VIEWLEFTBUTTON MomentaryButton {
  574.               on_url      [ "netscape/leon.jpg" ]
  575.               off_url     [ "netscape/leoff.jpg" ]
  576.               dis_url     [ "netscape/ledisoff.jpg" ]
  577.             }
  578.  
  579.             DEF ViewLeftButton_Script Script {
  580.               eventIn SFInt32 activated
  581.               url "javascript:
  582.                 function activated(val) {
  583.                   l3dBrowser.GoToPrevViewpoint();
  584.                 }"
  585.             }
  586.           ]
  587.           ROUTE VIEWLEFTBUTTON.activated TO ViewLeftButton_Script.activated
  588.         }
  589.  
  590.     Transform {
  591.           translation -55 13 0
  592.           scale 2 1 1
  593.           children [
  594.  
  595.             DEF VIEWBUTTON MomentaryButton {
  596.               on_url      [ "netscape/vion.jpg" ]
  597.               off_url     [ "netscape/vioff.jpg" ]
  598.             }
  599.  
  600.             DEF ViewButton_Script Script {
  601.               eventIn SFInt32 activated
  602.               url "javascript:
  603.                 function activated(val) {
  604.                   l3dBrowser.ReturnToViewpoint();
  605.                 }"
  606.             }
  607.           ]
  608.           ROUTE VIEWBUTTON.activated     TO ViewButton_Script.activated
  609.         }
  610.  
  611.     Transform {
  612.           translation -25 13 0
  613.           scale 1 1 1
  614.           children [
  615.  
  616.             DEF VIEWRIGHTBUTTON MomentaryButton {
  617.               on_url      [ "netscape/rion.jpg" ]
  618.               off_url     [ "netscape/rioff.jpg" ]
  619.               dis_url     [ "netscape/ridisoff.jpg" ]
  620.             }
  621.  
  622.             DEF ViewRightButton_Script Script {
  623.               eventIn SFInt32 activated
  624.               url "javascript:
  625.                 function activated(val) {
  626.                   l3dBrowser.GoToNextViewpoint();
  627.                 }"
  628.             }
  629.           ]
  630.           ROUTE VIEWRIGHTBUTTON.activated TO ViewRightButton_Script.activated
  631.         }
  632.  
  633.     Transform {
  634.           translation 35 13 0
  635.           scale 4 1 1
  636.           children [
  637.  
  638.             DEF STRAIGHTEN MomentaryButton {
  639.               on_url      [ "netscape/ston.jpg" ]
  640.               off_url     [ "netscape/stoff.jpg" ]
  641.             }
  642.           ]
  643.           ROUTE STRAIGHTEN.activated     TO COSMOBROWSER.set_straighten
  644.         }
  645.  
  646.     Transform {
  647.           translation 100 13 0
  648.           scale 1 1 1
  649.           children [
  650.  
  651.             DEF HELP MomentaryButton {
  652.               on_url      [ "netscape/heon.jpg" ]
  653.               off_url     [ "netscape/heoff.jpg" ]
  654.             }
  655.           ]
  656.           ROUTE HELP.activated     TO COSMOBROWSER.set_showHelp
  657.         }
  658.  
  659.       ]
  660.     }
  661.  
  662.     # The ModeController
  663.     DEF ModeController Script {
  664.  
  665.       # Events in from the COSMOBROWSER:
  666.       eventIn SFString navType_in
  667.       eventIn SFBool   anyMode_in
  668.       eventIn SFBool   gravity_in
  669.       eventIn MFString navTypeList_in
  670.  
  671.       # Events out to the COSMOBROWSER:
  672.       eventOut SFString navType_out
  673.       eventOut SFBool   gravity_out
  674.  
  675.       # Events to/from the 4 ModeButtons and the Gravity button
  676.       #
  677.       eventIn  SFTime  walk_clicked
  678.       eventOut SFInt32 walk_setState
  679.       #
  680.       eventIn  SFTime  slide_clicked
  681.       eventOut SFInt32 slide_setState
  682.       #
  683.       eventIn  SFTime  look_clicked
  684.       eventOut SFInt32 look_setState
  685.       #
  686.       eventIn  SFTime  examine_clicked
  687.       eventOut SFInt32 examine_setState
  688.       #
  689.       eventIn  SFTime  gravity_clicked
  690.       eventOut SFInt32 gravity_setState
  691.  
  692.       # Events in/out of our delay-line TimeSensor
  693.       eventOut SFTime  delay_start_out
  694.       eventIn  SFBool  delay_active_in
  695.  
  696.       # Cached copies of the state from the COSMOBROWSER
  697.       field SFString navType_state "WALK"
  698.       field SFBool   anyMode_state TRUE
  699.       field SFBool   gravity_state TRUE
  700.       field MFString navTypeList_state NULL
  701.  
  702.       # "Enabled" states of various buttons
  703.       field SFBool  wsl_enabled      FALSE
  704.       field SFBool  examine_enabled  FALSE
  705.       field SFBool  gravity_enabled  FALSE
  706.  
  707.       # Misc constants
  708.  
  709.       # navType_state values:
  710.       field SFString   walk_str    "WALK"
  711.       field SFString   look_str    "LOOK"
  712.       field SFString   slide_str   "SLIDE"
  713.       field SFString   fly_str     "FLY"
  714.       field SFString   examine_str "EXAMINE"
  715.  
  716.       # ModeButton states:
  717.       field SFInt32    OFF   0
  718.       field SFInt32    ON    1
  719.       field SFInt32    DIS   2
  720.       # Gravity button states (off/on same as above):
  721.       field SFInt32    OFF_DIS  2
  722.       field SFInt32    ON_DIS   3
  723.  
  724.       url "javascript:
  725.         function navType_in(str, time) {
  726.           navType_state = str;
  727.           update_state();
  728.           // And just in case, force another update_state() to
  729.           // happen soon:
  730.           delay_start_out = time;
  731.         }
  732.         function anyMode_in(bool, time) {
  733.           anyMode_state = bool;
  734.           update_state();
  735.           // And just in case, force another update_state() to
  736.           // happen soon:
  737.           delay_start_out = time;
  738.         }
  739.         function gravity_in(bool, time) {
  740.           gravity_state = bool;
  741.           update_state();
  742.           // And just in case, force another update_state() to
  743.           // happen soon:
  744.           delay_start_out = time;
  745.         }
  746.         function navTypeList_in(mfstr, time) {
  747.           navTypeList_state = mfstr;
  748.           update_state();
  749.           // And just in case, force another update_state() to
  750.           // happen soon:
  751.           delay_start_out = time;
  752.         }
  753.  
  754.         function update_state() {
  755.           // Depending on navType_state and anyMode_state,
  756.           // set the states of all 4 ModeButtons and the gravity button:
  757.  
  758.           // The mode button corresponding to the current navType is ON.
  759.           //
  760.           // The other mode buttons are 'inactive', which could
  761.           // be either OFF or DIS, depending on whether each button
  762.           // is 'enabled' or not.  The 'enabled' rules are:
  763.           //
  764.           // - If anyMode_state==true, all mode buttons are always enabled.
  765.           // - If anyMode_state==false:
  766.           //   - For WALK/SLIDE/LOOK: these mode buttons are enabled if
  767.           //     the navTypeList contains WALK or FLY.
  768.           //   - For EXAMINE: this mode button is enabled if
  769.           //     the navTypeList contains EXAMINE.
  770.           //
  771.  
  772.           if (anyMode_state) {
  773.             wsl_enabled     = true;
  774.             examine_enabled = true;
  775.           }
  776.           else {
  777.             walk_or_fly_found = false;
  778.             examine_found = false;
  779.  
  780.             for (i=0; i < navTypeList_state.length; i++) {
  781.               if ((navTypeList_state[i] == walk_str) ||
  782.                   (navTypeList_state[i] == fly_str))
  783.                 walk_or_fly_found = true;
  784.               if (navTypeList_state[i] == examine_str)
  785.                 examine_found = true;
  786.             }
  787.  
  788.             wsl_enabled = walk_or_fly_found;
  789.             examine_enabled = examine_found;
  790.           }
  791.  
  792.           wsl_inactiveState     = wsl_enabled     ? OFF : DIS;
  793.           examine_inactiveState = examine_enabled ? OFF : DIS;
  794.  
  795.           // Handle every possible known navType_state
  796.           // WALK
  797.           if (navType_state == walk_str) {
  798.             walk_setState = ON;
  799.             slide_setState = OFF;
  800.             look_setState = OFF;
  801.             examine_setState = examine_inactiveState;
  802.             // (This is probably redundant):
  803.             wsl_enabled = true;
  804.           }
  805.           // FLY
  806.           else if (navType_state == fly_str) {
  807.             walk_setState = ON;
  808.             slide_setState = OFF;
  809.             look_setState = OFF;
  810.             examine_setState = examine_inactiveState;
  811.             // (This is probably redundant):
  812.             wsl_enabled = true;
  813.           }
  814.           // LOOK
  815.           else if (navType_state == look_str) {
  816.             walk_setState = OFF;
  817.             slide_setState = OFF;
  818.             look_setState = ON;
  819.             examine_setState = examine_inactiveState;
  820.             // (This is probably redundant):
  821.             wsl_enabled = true;
  822.           }
  823.           // SLIDE
  824.           else if (navType_state == slide_str) {
  825.             // Handle weird case of SLIDEing while in EXAMINE
  826.             // mode (by holding down ALT)! 
  827.             // If wsl_enabled is false, this must be the case; just 
  828.             // leave WALK and LOOK disabled, and SLIDE on:
  829.             if (!wsl_enabled) {
  830.               walk_setState = DIS;
  831.               slide_setState = ON;
  832.               look_setState = DIS;
  833.             }
  834.             else {  // wsl_enabled is true
  835.               walk_setState = OFF;
  836.               slide_setState = ON;
  837.               look_setState = OFF;
  838.             }
  839.             examine_setState = examine_inactiveState;
  840.             // (This is inappropriate sometimes! (see note above)):
  841.             //wsl_enabled = true;
  842.           }
  843.           // EXAMINE
  844.           else if (navType_state == examine_str) {
  845.             walk_setState = wsl_inactiveState;
  846.             slide_setState = wsl_inactiveState;
  847.             look_setState = wsl_inactiveState;
  848.             examine_setState = ON;
  849.             // (This is probably redundant):
  850.             examine_enabled = true;
  851.           }
  852.  
  853.           // Other weird possible cases:
  854.           //   - UNKNOWN   (?)
  855.           //   - QUAKE
  856.           //   - NONE      (dashboard shouldn't even be visible)
  857.           // Make all the ModeButtons either OFF or DIS,
  858.           // depending on anyMode:
  859.           else {
  860.             walk_setState = wsl_inactiveState;
  861.             slide_setState = wsl_inactiveState;
  862.             look_setState = wsl_inactiveState;
  863.             examine_setState = examine_inactiveState;
  864.           }
  865.  
  866.           // Update gravity button state:
  867.  
  868.           // First figure out if it should be enabled or not:
  869.           // It's enabled if anyMode_state==true OR if the navTypeList
  870.           // contains *both* WALK and FLY.  
  871.           // Also, the gravity button is OFF_DIS by defn in EXAMINE mode.
  872.  
  873.           if (navType_state == examine_str) {
  874.             gravity_enabled = false;
  875.             gravity_setState = OFF_DIS;
  876.           }
  877.           else {
  878.  
  879.             if (anyMode_state) {
  880.               gravity_enabled = true;
  881.             }
  882.             else {
  883.               walk_found = false;
  884.               fly_found  = false;
  885.  
  886.               for (i=0; i < navTypeList_state.length; i++) {
  887.                 if (navTypeList_state[i] == walk_str)
  888.                   walk_found = true;
  889.                 if (navTypeList_state[i] == fly_str)
  890.                   fly_found = true;
  891.               }
  892.  
  893.               gravity_enabled = (walk_found && fly_found);
  894.             }
  895.  
  896.             // Now set the button state
  897.             if (gravity_enabled) {
  898.               gravity_setState = gravity_state ? ON : OFF;
  899.             }
  900.             else {  // gravity button disabled
  901.               gravity_setState = gravity_state ? ON_DIS : OFF_DIS;
  902.             }
  903.           }
  904.         }
  905.  
  906.         // Events from our delay TimeSensor
  907.         function delay_active_in(bool) {
  908.           // If !bool, that means the TimeSensor just finished.
  909.           // In that case, do an update_state():
  910.           if (!bool)
  911.             update_state();
  912.         }
  913.  
  914.         // Handle clicks from the buttons
  915.         function walk_clicked(t) {
  916.           if (wsl_enabled)
  917.             navType_out = walk_str;
  918.         }
  919.         function slide_clicked(t) {
  920.           if (wsl_enabled)
  921.             navType_out = slide_str;
  922.         }
  923.         function look_clicked(t) {
  924.           if (wsl_enabled)
  925.             navType_out = look_str;
  926.         }
  927.         function examine_clicked(t) {
  928.           if (examine_enabled)
  929.             navType_out = examine_str;
  930.         }
  931.         function gravity_clicked(t) {
  932.           if (gravity_enabled) {
  933.             gravity_out = !gravity_state;
  934.           }
  935.         }"
  936.     }   # End of ModeController Script
  937.  
  938.     # TimeSensor used by the ModeController to force an update_state()
  939.     # call to happen some time in the future
  940.     DEF ModeControllerDelay TimeSensor {
  941.       cycleInterval 0.05
  942.     }
  943.  
  944.     # Script to enable/disable the View left and right arrow buttons
  945.     DEF ArrowEnabler Script {
  946.       eventIn SFInt32 num_vps_in
  947.       eventOut SFBool arrow_enable_out
  948.       url "javascript:
  949.         function num_vps_in(val) {
  950.           arrow_enable_out = (val > 1);
  951.         }"
  952.     }
  953.  
  954.   ]
  955.  
  956.   # Set up all the ModeController ROUTEs:
  957.  
  958.   # COSMOBROWSER --> ModeController
  959.   #
  960.   ROUTE COSMOBROWSER.navType_changed TO ModeController.navType_in
  961.   ROUTE COSMOBROWSER.navTypeList_changed TO ModeController.navTypeList_in
  962.   ROUTE COSMOBROWSER.anyMode_changed TO ModeController.anyMode_in
  963.   ROUTE COSMOBROWSER.gravity_changed TO ModeController.gravity_in
  964.  
  965.   # ModeController --> COSMOBROWSER
  966.   #
  967.   ROUTE ModeController.navType_out   TO COSMOBROWSER.set_navType
  968.   ROUTE ModeController.gravity_out   TO COSMOBROWSER.set_gravity
  969.  
  970.   # ModeController <--> ModeButtons
  971.   #
  972.   ROUTE WALK_MB.clicked                TO ModeController.walk_clicked
  973.   ROUTE ModeController.walk_setState   TO WALK_MB.setState
  974.   #
  975.   ROUTE LOOK_MB.clicked                TO ModeController.look_clicked
  976.   ROUTE ModeController.look_setState   TO LOOK_MB.setState
  977.   #
  978.   ROUTE SLIDE_MB.clicked               TO ModeController.slide_clicked
  979.   ROUTE ModeController.slide_setState  TO SLIDE_MB.setState
  980.   #
  981.   ROUTE EXAMINE_MB.clicked              TO ModeController.examine_clicked
  982.   ROUTE ModeController.examine_setState TO EXAMINE_MB.setState
  983.   #
  984.   ROUTE GRAVITY_BUTTON.clicked          TO ModeController.gravity_clicked
  985.   ROUTE ModeController.gravity_setState TO GRAVITY_BUTTON.setState
  986.  
  987.   # Hook up the ModeController's delay-line TimeSensor
  988.   ROUTE ModeController.delay_start_out TO ModeControllerDelay.startTime
  989.   ROUTE ModeControllerDelay.isActive TO ModeController.delay_active_in
  990.  
  991.   # Hook up the ArrowEnabler script
  992.   ROUTE COSMOBROWSER.numViewpoints_changed TO ArrowEnabler.num_vps_in
  993.   ROUTE ArrowEnabler.arrow_enable_out TO VIEWRIGHTBUTTON.enable_in
  994.   ROUTE ArrowEnabler.arrow_enable_out TO VIEWLEFTBUTTON.enable_in
  995.  
  996. }
  997. # v.37
  998.