Posted: Sat Mar 21, 2009 8:35 pm Post subject: Some math improvements for ACS
Hello there, how are you doing?
This may sound useless for many, but if you are smart and like to invent creative stuff with ACS, it may be very useful IMO.
As ACS doesn't like math very much by default, I am developing my own formulaes. I'll be posting 'em here even for organization reasons (I am afraid of loosing/corrupting them somehow)
Thanks to bagheadspidey for helping me optimizing some codes.
function int FExp(int base, int exp)
int result = 1.0;
int abs_exp = exp;
if (exp < 0) abs_exp *= -1;
Usage: FExp(Your floating value,Your INTEGER exponent) (e.g.: FExp(3.0,5))
Works with negative exponents.
function int FixedSqrt(int number)
int samples=15; //Samples for accuracy
if (number==1.0) return 1.0;
if (number<=0) return 0;
for (int i=0; i<samples; i++)
Usage: use it as a function writing FixedSqrt(your floating number).
Negative values results 0.
Keep in mind that it's not a perfect solution. The smaller the number is, the higher the percentage of error is.
Feel free to change the number of samples by editing the samples string. 15 samples are great in most cases.
Sine, cosine and tangent:
ACS has a built-in sine and cosine system. But tangent is missing, and the values that you put on them must be in a different scale than radian values. 1.0 value means a full circle instead of 2*pi. If you want to make interactive math equations based on sine, cosine or tangent values in radian - which is vastly used - try this conversion:
function int FCos(int fcosnum)
Usage: FCos(your floating number in radians).
Now, it's Sine turn:
function int FSin(int fsinnum)
Usage: FSin(your floating number in radians).
I recommend not to change the pi value.
What about tangent?
That's quite simple. tangent(x) = sin(x)/cos(x). Then:
function int FTan(int ftannum)
Usage: FTan(your floating number in radians)
Arc sine, arc cosine and arc tangent (NOT DONE YET):
This one has been a pain in my butt since nobody teached inverse trigonometry to me yet at school. But I think I got some average results.
Here's the arc sine formulae:
function int FASin(int number)
int samples=5; //Samples for accuracy (over 5 samples usually results wrongly)
if(number!=0 && number<1.0 && number>-1.0 && samples>0)
for(int i=0; i<samples; i++)
Usage: FASin(your floating number)
Although there are 5 samples in this algorithm, the margin of error is considerably big if the input value is close to 1.0.
This problem would be solved if the samples were increased, but unfortunely the values would become completly wrong when processed in ACS because of the depth of the numbers.
Now the acos. As arc cosine of x represents pi/2-asin(x) then:
also I'm not conviced of the use of various constant values in your formulas, that can only result in hacky and inaccurate results To be honest, now looking at some of the formulas..
how the hell did you come up with this?
I took reference from wikipedia mainly. The big deal is that the number can be only 8 chars long in ACS (if I'm not mistaking), so the results can't be more accurate
Anyway, thanks for the links from zdoom wiki. I'll take a look.
Oh my God, you remind me of my math teacher! Looks like you'll be given an A at your next test.
About the usefulness of this, I'm not really convinced. What kind of creative stuff do you think you can invent with these formulaes?
I don't know really. All I can say is that using some math improvements makes the doom gameplay closer to the latest games.
Let me take an example: GTA-VC. It's pretty old, but it has daylight system, some physics and so on. I'm not sure how it works, but I guess they didn't use only additions and subtractions for this.
It depends on creactivity either.
Thank you pal! I didn't know about these custom functions. Now it's way more simple to use these formulas.
Fixed the square root written in the first post. I'll be updating the rest later.
BTW, I couldn't get what's wrong with this square root solution at zdoom wiki page. When I tried the sqrt of 8, it returned to me the 2 value. Looks like it doesn't work with floating numbers.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum