home *** CD-ROM | disk | FTP | other *** search
/ Using Visual Basic 5 (Platinum Edition) / vb5.iso / ACTIVEX / VIS3SPAC / DATA.5 / examples / contrib / Mesmer / JOYSTICK.ALX < prev    next >
Encoding:
Text File  |  1996-11-15  |  14.4 KB  |  330 lines

  1. <!-----------------------------------------------------------------------    
  2. <!  joystick.alx - 11/14/96
  3. <!
  4. <!    Site Design, Programming, and Art By:
  5. <!    Eric Lippke  eric@mbdirect.com (206) 489-5956
  6. <!    Phil Austin  bob@mbdirect.com
  7. <!  John Laney   jlaney@mbdirect.com
  8. <!  Erik Herz    erik@mbdirect.com
  9. <!------------------------------------------------------------------------->
  10.  
  11. <script language="VBScript">
  12.  
  13. dim startX
  14. dim startY
  15. dim oldPos
  16.  
  17. '//--------------------- joystickObj_OnLoad() ---------------------------------
  18. '//--  Turns off all sprites and sets joystick to the starting position.
  19. '//----------------------------------------------------------------------
  20. sub joystickObj_OnLoad()
  21.     oldPos = 2        '// Must set to bogus valid number
  22.     ChangeJoystickPosition(1)
  23. end sub
  24.  
  25. '//--------------------- controller_MouseDown() ---------------------------------
  26. '//--  Sets the starting X,Y position based on the users mouse click.
  27. '//----------------------------------------------------------------------
  28. sub controller_MouseDown (Button, Shift, X, Y)
  29.         startX = X
  30.         startY = Y
  31. end sub
  32.  
  33. '//--------------------- controller_MouseUp() ---------------------------------
  34. '//--  Center the joystick when the mouse is released.
  35. '//----------------------------------------------------------------------
  36. sub controller_MouseUp (Button, Shift, X, Y)
  37.     if(Button = 1) then ChangeJoystickPosition(1)
  38. end sub
  39.  
  40.  
  41. '//--------------------- MouseMove() ---------------------------------
  42. '//--  This function Monitors Mouse movement and sets the correct postion.
  43. '//----------------------------------------------------------------------
  44. sub controller_MouseMove (Button, Shift, X, Y)
  45.     dim newPos
  46.     if (button = 1) then
  47.     
  48.         '// Get The Slope
  49.         if (x = startX) then
  50.             slope = 100
  51.         else
  52.             slope = (startY - y) / (x - startX)
  53.         end if
  54.         
  55.         '// Vertical Line
  56.         if (slope => 1.5 or slope <= -1.5) then    
  57.             if(startY - y=> 0 ) then
  58.                 newPos = 4
  59.             else
  60.                 newPos = 2
  61.             end if
  62.             
  63.         else    '// Horizontal Line
  64.             if (slope <= .5 and slope >= -.5) then
  65.                 if(x - startX=> 0 ) then
  66.                     newPos = 6
  67.                 else
  68.                     newPos = 8
  69.                 end if
  70.                 
  71.             else    '// Top Left To Lower Right Angle
  72.                 if (slope=>.5 and slope <=1.5) then
  73.                     if(startY - y=> 0 ) then
  74.                         newPos = 14
  75.                     else
  76.                         newPos = 16
  77.                     end if
  78.                     
  79.                 else    '// Top Right To Lower Left
  80.                     if(startY - y) >=0 then
  81.                         newpos = 10
  82.                     else
  83.                         newPos = 12
  84.                     end if
  85.                 end if
  86.             end if
  87.         
  88.         end if
  89.         
  90.         ' Calculate The Distance from starting point
  91.         if ( Abs(startX-X)    > 22 or Abs(startY-Y) > 22) then newPos = newPos + 1
  92.         if ( Abs(startX-X)    <= 2 and Abs(startY-Y) <= 2) then newPos = 1
  93.         ChangeJoystickPosition(newPos)
  94.  
  95.         '// Display The X & Y & Slope
  96.         'top.document.joyForm.joyValue.value = Int(x * 1000) / 1000 & "    " & Int(y*1000)/1000 & "     " & Int(slope*1000)/1000
  97.         
  98.     end if
  99. end sub
  100.  
  101. '//--------------------- ChangeJoystickPosition() ---------------------------------
  102. '//--  This function sets the current sprite and hides all the other sprites.
  103. '//----------------------------------------------------------------------
  104. sub ChangeJoystickPosition(thePos)
  105.     if thePos = oldPos then exit sub
  106.     oldPos = thePos
  107.     if thePos = 1 then joystick1.visible = true else joystick1.visible = false end if
  108.     if thePos = 2 then joystick2.visible = true else joystick2.visible = false end if
  109.     if thePos = 3 then joystick3.visible = true else joystick3.visible = false end if
  110.     if thePos = 4 then joystick4.visible = true else joystick4.visible = false end if
  111.     if thePos = 5 then joystick5.visible = true else joystick5.visible = false end if
  112.     if thePos = 6 then joystick6.visible = true else joystick6.visible = false end if
  113.     if thePos = 7 then joystick7.visible = true else joystick7.visible = false end if
  114.     if thePos = 8 then joystick8.visible = true else joystick8.visible = false end if
  115.     if thePos = 9 then joystick9.visible = true else joystick9.visible = false end if
  116.     if thePos = 10 then joystick10.visible = true else joystick10.visible = false end if
  117.     if thePos = 11 then joystick11.visible = true else joystick11.visible = false end if
  118.     if thePos = 12 then joystick12.visible = true else joystick12.visible = false end if
  119.     if thePos = 13 then joystick13.visible = true else joystick13.visible = false end if
  120.     if thePos = 14 then joystick14.visible = true else joystick14.visible = false end if
  121.     if thePos = 15 then joystick15.visible = true else joystick15.visible = false end if
  122.     if thePos = 16 then joystick16.visible = true else joystick16.visible = false end if
  123.     if thePos = 17 then joystick17.visible = true else joystick17.visible = false end if
  124.     
  125.     '// VRML ADD IN SECTION
  126.     dim vrmlPos
  127.     if thePos = 1 then vrmlPos = "center"
  128.     if thePos = 2 then vrmlPos = "slow_down"
  129.     if thePos = 3 then vrmlPos = "fast_down"
  130.     if thePos = 4 then vrmlPos = "slow_up"
  131.     if thePos = 5 then vrmlPos = "fast_up"
  132.     if thePos = 6 then vrmlPos = "slow_right"
  133.     if thePos = 7 then vrmlPos = "fast_right"
  134.     if thePos = 8 then vrmlPos = "slow_left"
  135.     if thePos = 9 then vrmlPos = "fast_left"
  136.     if thePos = 10 then vrmlPos = "slow_topleft"
  137.     if thePos = 11 then vrmlPos = "fast_topleft"
  138.     if thePos = 12 then vrmlPos = "slow_bottomright"
  139.     if thePos = 13 then vrmlPos = "fast_bottomright"
  140.     if thePos = 14 then vrmlPos = "slow_topright"
  141.     if thePos = 15 then vrmlPos = "fast_topright"
  142.     if thePos = 16 then vrmlPos = "slow_bottomleft"
  143.     if thePos = 17 then vrmlPos = "slow_bottomleft"
  144.     top.document.joyForm.joyValue.value = vrmlPos
  145.     
  146.     '// Add Your Call to control the VRML HERE!! - feel free to change the above paramaters.
  147.     '// I listed them above for your reference.
  148.     '// Right now it is set to move full speed.
  149. end sub
  150.  
  151.  
  152.  
  153. </script>
  154.  
  155. <DIV ID="joystickObj" STYLE="LAYOUT:FIXED;WIDTH:80;HEIGHT:84;">
  156.     <OBJECT ID="controller"
  157.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0;LEFT:0;WIDTH:80;HEIGHT:84;ZINDEX:3;">
  158.         <PARAM NAME="PicturePath" VALUE="images/blank.gif">
  159.         <PARAM NAME="BorderStyle" VALUE="0">
  160.         <PARAM NAME="SizeMode" VALUE="3">
  161.         <PARAM NAME="Size" VALUE="9605;4948">
  162.         <PARAM NAME="PictureAlignment" VALUE="0">
  163.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  164.     </OBJECT>
  165.     <OBJECT ID="joystick0"
  166.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:0;">
  167.         <PARAM NAME="PicturePath" VALUE="images/joystick0.jpg">
  168.         <PARAM NAME="BorderStyle" VALUE="0">
  169.         <PARAM NAME="SizeMode" VALUE="3">
  170.         <PARAM NAME="Size" VALUE="9605;4948">
  171.         <PARAM NAME="PictureAlignment" VALUE="0">
  172.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  173.     </OBJECT>
  174.     <OBJECT ID="joystick1"
  175.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  176.         <PARAM NAME="PicturePath" VALUE="images/joystick1.gif">
  177.         <PARAM NAME="BorderStyle" VALUE="0">
  178.         <PARAM NAME="SizeMode" VALUE="3">
  179.         <PARAM NAME="Size" VALUE="9605;4948">
  180.         <PARAM NAME="PictureAlignment" VALUE="0">
  181.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  182.     </OBJECT>
  183.     <OBJECT ID="joystick2"
  184.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  185.         <PARAM NAME="PicturePath" VALUE="images/joystick2.gif">
  186.         <PARAM NAME="BorderStyle" VALUE="0">
  187.         <PARAM NAME="SizeMode" VALUE="3">
  188.         <PARAM NAME="Size" VALUE="9605;4948">
  189.         <PARAM NAME="PictureAlignment" VALUE="0">
  190.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  191.     </OBJECT>
  192.     <OBJECT ID="joystick3"
  193.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  194.         <PARAM NAME="PicturePath" VALUE="images/joystick3.gif">
  195.         <PARAM NAME="BorderStyle" VALUE="0">
  196.         <PARAM NAME="SizeMode" VALUE="3">
  197.         <PARAM NAME="Size" VALUE="9605;4948">
  198.         <PARAM NAME="PictureAlignment" VALUE="0">
  199.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  200.     </OBJECT>
  201.     <OBJECT ID="joystick4"
  202.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  203.         <PARAM NAME="PicturePath" VALUE="images/joystick4.gif">
  204.         <PARAM NAME="BorderStyle" VALUE="0">
  205.         <PARAM NAME="SizeMode" VALUE="3">
  206.         <PARAM NAME="Size" VALUE="9605;4948">
  207.         <PARAM NAME="PictureAlignment" VALUE="0">
  208.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  209.     </OBJECT>
  210.     <OBJECT ID="joystick5"
  211.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  212.         <PARAM NAME="PicturePath" VALUE="images/joystick5.gif">
  213.         <PARAM NAME="BorderStyle" VALUE="0">
  214.         <PARAM NAME="SizeMode" VALUE="3">
  215.         <PARAM NAME="Size" VALUE="9605;4948">
  216.         <PARAM NAME="PictureAlignment" VALUE="0">
  217.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  218.     </OBJECT>
  219.     <OBJECT ID="joystick6"
  220.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  221.         <PARAM NAME="PicturePath" VALUE="images/joystick6.gif">
  222.         <PARAM NAME="BorderStyle" VALUE="0">
  223.         <PARAM NAME="SizeMode" VALUE="3">
  224.         <PARAM NAME="Size" VALUE="9605;4948">
  225.         <PARAM NAME="PictureAlignment" VALUE="0">
  226.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  227.     </OBJECT>
  228.     <OBJECT ID="joystick7"
  229.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  230.         <PARAM NAME="PicturePath" VALUE="images/joystick7.gif">
  231.         <PARAM NAME="BorderStyle" VALUE="0">
  232.         <PARAM NAME="SizeMode" VALUE="3">
  233.         <PARAM NAME="Size" VALUE="9605;4948">
  234.         <PARAM NAME="PictureAlignment" VALUE="0">
  235.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  236.     </OBJECT>
  237.     <OBJECT ID="joystick8"
  238.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  239.         <PARAM NAME="PicturePath" VALUE="images/joystick8.gif">
  240.         <PARAM NAME="BorderStyle" VALUE="0">
  241.         <PARAM NAME="SizeMode" VALUE="3">
  242.         <PARAM NAME="Size" VALUE="9605;4948">
  243.         <PARAM NAME="PictureAlignment" VALUE="0">
  244.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  245.     </OBJECT>
  246.     <OBJECT ID="joystick9"
  247.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  248.         <PARAM NAME="PicturePath" VALUE="images/joystick9.gif">
  249.         <PARAM NAME="BorderStyle" VALUE="0">
  250.         <PARAM NAME="SizeMode" VALUE="3">
  251.         <PARAM NAME="Size" VALUE="9605;4948">
  252.         <PARAM NAME="PictureAlignment" VALUE="0">
  253.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  254.     </OBJECT>
  255.     <OBJECT ID="joystick10"
  256.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  257.         <PARAM NAME="PicturePath" VALUE="images/joystick10.gif">
  258.         <PARAM NAME="BorderStyle" VALUE="0">
  259.         <PARAM NAME="SizeMode" VALUE="3">
  260.         <PARAM NAME="Size" VALUE="9605;4948">
  261.         <PARAM NAME="PictureAlignment" VALUE="0">
  262.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  263.     </OBJECT>
  264.     <OBJECT ID="joystick11"
  265.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  266.         <PARAM NAME="PicturePath" VALUE="images/joystick11.gif">
  267.         <PARAM NAME="BorderStyle" VALUE="0">
  268.         <PARAM NAME="SizeMode" VALUE="3">
  269.         <PARAM NAME="Size" VALUE="9605;4948">
  270.         <PARAM NAME="PictureAlignment" VALUE="0">
  271.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  272.     </OBJECT>
  273.     <OBJECT ID="joystick12"
  274.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  275.         <PARAM NAME="PicturePath" VALUE="images/joystick12.gif">
  276.         <PARAM NAME="BorderStyle" VALUE="0">
  277.         <PARAM NAME="SizeMode" VALUE="3">
  278.         <PARAM NAME="Size" VALUE="9605;4948">
  279.         <PARAM NAME="PictureAlignment" VALUE="0">
  280.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  281.     </OBJECT>
  282.     <OBJECT ID="joystick13"
  283.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  284.         <PARAM NAME="PicturePath" VALUE="images/joystick13.gif">
  285.         <PARAM NAME="BorderStyle" VALUE="0">
  286.         <PARAM NAME="SizeMode" VALUE="3">
  287.         <PARAM NAME="Size" VALUE="9605;4948">
  288.         <PARAM NAME="PictureAlignment" VALUE="0">
  289.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  290.     </OBJECT>
  291.     <OBJECT ID="joystick14"
  292.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  293.         <PARAM NAME="PicturePath" VALUE="images/joystick14.gif">
  294.         <PARAM NAME="BorderStyle" VALUE="0">
  295.         <PARAM NAME="SizeMode" VALUE="3">
  296.         <PARAM NAME="Size" VALUE="9605;4948">
  297.         <PARAM NAME="PictureAlignment" VALUE="0">
  298.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  299.     </OBJECT>
  300.     <OBJECT ID="joystick15"
  301.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  302.         <PARAM NAME="PicturePath" VALUE="images/joystick15.gif">
  303.         <PARAM NAME="BorderStyle" VALUE="0">
  304.         <PARAM NAME="SizeMode" VALUE="3">
  305.         <PARAM NAME="Size" VALUE="9605;4948">
  306.         <PARAM NAME="PictureAlignment" VALUE="0">
  307.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  308.     </OBJECT>
  309.     <OBJECT ID="joystick16"
  310.       CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  311.         <PARAM NAME="PicturePath" VALUE="images/joystick16.gif">
  312.         <PARAM NAME="BorderStyle" VALUE="0">
  313.         <PARAM NAME="SizeMode" VALUE="3">
  314.         <PARAM NAME="Size" VALUE="9605;4948">
  315.         <PARAM NAME="PictureAlignment" VALUE="0">
  316.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  317.     </OBJECT>
  318.     <OBJECT ID="joystick17"
  319.      CLASSID="CLSID:D4A97620-8E8F-11CF-93CD-00AA00C08FDF" STYLE="TOP:0px;LEFT:0px;WIDTH:80px;HEIGHT:84px;ZINDEX:1;">
  320.         <PARAM NAME="PicturePath" VALUE="images/joystick17.gif">
  321.         <PARAM NAME="BorderStyle" VALUE="0">
  322.         <PARAM NAME="SizeMode" VALUE="3">
  323.         <PARAM NAME="Size" VALUE="9605;4948">
  324.         <PARAM NAME="PictureAlignment" VALUE="0">
  325.         <PARAM NAME="VariousPropertyBits" VALUE="19">
  326.     </OBJECT>  
  327.    
  328. </DIV>
  329.  
  330.