Difference between revisions of "Simulating new functions"

1,119 bytes added ,  19:35, 6 May 2006
no edit summary
imported>JustTim
imported>JustTim
Line 194: Line 194:
short sParam3
short sParam3
short sResult
short sResult
short sResult2


float fParam1
float fParam1
Line 199: Line 200:
float fParam3
float fParam3
float fResult
float fResult
float fResult2


ref rParam1
ref rParam1
ref rParam2
ref rParam2
ref rParam3
ref rParam3
ref rResult</pre>
ref rResult
ref rResult2</pre>
This is a generalized function framework that can be re-used for as many functions as you like.
This is a generalized function framework that can be re-used for as many functions as you like.


And now make stage 10 for this quest with the following code:
And now make stage 10 for this quest with the following code:
<pre>; float Hypotenuse(float CathetusA, float CathetusB)
<pre>; FUNCTION float Hypotenuse(float CathetusA, float CathetusB)
float sqroot
float sqroot
float n


set Function.fResult to ((fParam1 * fParam1) + (fParam2 * fParam2))
set n to ((Function.fParam1 * Function.fParam1) + (Function.fParam2 * Function.fParam2))
if (fResult <= 0)
if (n <= 0)
   set fResult to 1
   set Function.fResult to 1
else
else
   set sqroot to fResult/2
   set sqroot to n/2
   set sqroot to (sqroot + (fResult/sqroot))/2
   set sqroot to (sqroot + (n/sqroot))/2
   set sqroot to (sqroot + (fResult/sqroot))/2
   set sqroot to (sqroot + (n/sqroot))/2
   set sqroot to (sqroot + (fResult/sqroot))/2
   set sqroot to (sqroot + (n/sqroot))/2
   set sqroot to (sqroot + (fResult/sqroot))/2
   set sqroot to (sqroot + (n/sqroot))/2
   set sqroot to (sqroot + (fResult/sqroot))/2
   set sqroot to (sqroot + (n/sqroot))/2
   set fResult to (fResult * sqroot)
   set Function.fResult to (n * sqroot)
endif</pre>
endif</pre>


Line 236: Line 240:
(I haven't tested the functions here but they should work. Thanks to Galerion for the Square Root function.)
(I haven't tested the functions here but they should work. Thanks to Galerion for the Square Root function.)
--[[User:JustTim|JustTim]] 18:13, 6 May 2006 (EDT)
--[[User:JustTim|JustTim]] 18:13, 6 May 2006 (EDT)
Another cool function:
<pre>; FUNCTION float,float SinCos(float Angle)
float AngleA
float X
float X2
float X3
float X4
float X5
float X6
float X7
float X8
float X9
short xcoeff
short ycoeff
set AngleA to Function.fParam1
If AngleA >= 270
  Set xcoeff to 1
  Set ycoeff to -1
  Set AngleA to AngleA - 270
ElseIf AngleA >= 180
  Set xcoeff to -1
  Set ycoeff to -1
  Set AngleA to AngleA - 180
ElseIf AngleA >= 90
  Set xcoeff to -1
  Set ycoeff to 1
  Set AngleA to AngleA - 90
Else
  Set xcoeff to 1
  Set ycoeff to 1
EndIf
set X to AngleA / 57.2957792
set X2 to X*X
set X3 to X2*X
set X4 to X2*X2
set X5 to X4*X
set X6 to X3*X3
set X7 to X5*X2
set X8 to X4*X4
set X9 to X7*X2
set AngleA to X - X3/6 + X5/120 - X7/5040 + X9/362880 - X9*X2/39916800
set Function.fResult to AngleA * ycoeff ;Sin
set AngleA to 1 - X2/2 + X4/24 - X6/720 + X8/40320 - X8*X2/3628800
set Function.fResult2 to AngleA * xcoeff ;Cos</pre>
Haven't tested this too. I hope it works. Many thanks to mrflippy and Grundulum for this function! --[[User:JustTim|JustTim]] 19:35, 6 May 2006 (EDT)




[[Category:Solutions]]
[[Category:Solutions]]
Anonymous user