home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Muscles_Dr2152735192009.psc / Muscles_2D_Ragdoll_V3.1_DirectX / phyMOD.bas < prev    next >
BASIC Source File  |  2009-05-14  |  2KB  |  88 lines

  1. Attribute VB_Name = "phyMOD"
  2. 'Author : Creator Roberto Mior
  3. '     reexre@gmail.com
  4. '
  5. 'If you use source code or part of it please cite the author
  6. 'You can use this code however you like providing the above credits remain intact
  7. '
  8. '
  9. '
  10.  
  11. Public Type tPoint
  12.     x As Double
  13.     y As Double
  14.     OldX As Double
  15.     OldY As Double
  16.     vx As Double
  17.     vy As Double
  18. End Type
  19.  
  20. Public Type tLink
  21.     P1 As Integer '     Point 1
  22.     P2 As Integer '     Point 2
  23.     MainL As Double '   Distance Between P1 and P2
  24. End Type
  25.  
  26. Public Type tMuscle
  27.     L1 As Integer '     Link1
  28.     L2 As Integer '     Link2
  29.     MainA As Double '   Angle that should be between L1 and L2
  30.     P0 As Integer '     Common point of L1 and L2
  31.     P1 As Integer '     Other point on L1
  32.     P2 As Integer '     Other point on L2
  33.     f As Double '       Muscle Force(strength)
  34. End Type
  35.  
  36. Public Const PI = 3.14159265358979
  37.  
  38. Public AIR As Double
  39. Public Gravity As Double
  40. Public kMuscleSpeedLimit
  41.  
  42. Public MUS As Integer
  43.  
  44.  
  45. Public Function Distance(P1 As tPoint, P2 As tPoint) As Double
  46. Dim DX As Double
  47. Dim dy As Double
  48.  
  49. DX = P1.x - P2.x
  50. dy = P1.y - P2.y
  51.  
  52. Distance = Sqr(DX * DX + dy * dy)
  53.  
  54. End Function
  55.  
  56.  
  57. Public Function Atan2(ByVal x As Double, ByVal y As Double) As Double
  58. 'This Should return Angle (X is deltaX,Y is DeltaY)
  59.  
  60.  
  61. Dim theta As Double
  62.  
  63. If (Abs(x) < 0.0000001) Then
  64.     If (Abs(y) < 0.0000001) Then
  65.         theta = 0#
  66.     ElseIf (y > 0#) Then
  67.         'theta = 1.5707963267949
  68.         theta = PI / 2
  69.     Else
  70.         'theta = -1.5707963267949
  71.         theta = -PI / 2
  72.     End If
  73. Else
  74.     theta = Atn(y / x)
  75.     
  76.     If (x < 0) Then
  77.         If (y >= 0#) Then
  78.             theta = PI + theta
  79.         Else
  80.             theta = theta - PI
  81.         End If
  82.     End If
  83. End If
  84.  
  85. Atan2 = theta
  86. End Function
  87.  
  88.