gambas-source-code/app/examples/Games/DeepSpace/.src/MMath.module
Benoît Minisini c6a9cd69c2 [EXAMPLES]
* NEW: Add examples again. I hope correctly this time.


git-svn-id: svn://localhost/gambas/trunk@6726 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2014-12-12 19:58:52 +00:00

64 lines
1.6 KiB
Text

' Gambas module file
'
' Copyright (C) 2004, Michael Isaac. All rights reserved.
'
'PUBLIC CONST Radian AS Float = 0.01745329252
Public SineArray As New Float[]
Public CoSineArray As New Float[]
Public Sub InitializeSineTable()
Dim I As Integer
'We create the cosine/sine array so we dont have to call
'a function which had to calculate a value everytime we call it.
'These calls are made once here, and then from now we can just
'point at the value we want. Should be much faster this way.
For I = 0 To 359
SineArray.Add(Sin(I * (Pi / 180)))
CoSineArray.Add(Cos(I * (Pi / 180)))
Next
End
Function GetDistance(X1 As Float, Y1 As Float, X2 As Float, Y2 As Float) As Float
'RETURN Sqr((X1 - X2) ^ 2 + (Y1 - Y2) ^ 2)
Return Hyp(X1 - X2, Y1 - Y2)
End
' FUNCTION CosE(A AS Float) AS Float
' DIM Angle AS Integer
'
' 'Convert our radian angle to a degree value
' Angle = CInt(A * 180 / Pi)
'
' 'Ensure we're between 0 and 359
' DO WHILE ((Angle < 0) OR (Angle > 359))
' IF Angle > 359 THEN Angle = Angle - 360
' IF Angle < 0 THEN Angle = Angle + 360
' LOOP
'
' 'Return the value
' RETURN CoSineArray[Angle]
' END
'
'
' FUNCTION SinE(A AS Float) AS Float
' DIM Angle AS Integer
'
' 'Convert our radian angle to a degree value
' Angle = CInt(A * (180 / Pi))
'
' 'Ensure we're between 0 and 359
' DO WHILE ((Angle < 0) OR (Angle > 359))
' IF (Angle > 359) THEN Angle = Angle - 360
' IF (Angle < 0) THEN Angle = Angle + 360
' LOOP
'
' 'Return the value
' RETURN SineArray[Angle]
' END