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