Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: glafebe6 on Tue 27/01/2009 02:46:42

Title: Advanced math operators
Post by: glafebe6 on Tue 27/01/2009 02:46:42
is there any way to do basic limits derivatives integrations or logs in ags ? I really need to use these functions for some physics i want to apply to my game but i cant even do a simple natural log function!
Title: Re: Advanced math operators
Post by: Khris on Tue 27/01/2009 08:12:34
Here:
#define LIMIT 10000.0

float noloopcheck ln(float x) {
  if (x <= 0.0) return 0.0;
  float k, re;
  while (k<LIMIT) {
    re += (Maths.RaiseToPower((x-1.0)/(x+1.0), 2.0*k+1.0)*2.0)/(2.0*k+1.0);
    k += 1.0;
  }
  return re;
}

float log(float base, float x) {
  if (base <= 0.0 || x == 0.0) return 0.0;
  return ln(x)/ln(base);
}


Adjust limit for precision vs. speed.
Title: Re: Advanced math operators
Post by: on Tue 27/01/2009 12:28:53
Quote from: glafebe6 on Tue 27/01/2009 02:46:42
is there any way to do basic limits derivatives integrations or logs in ags ? I really need to use these functions for some physics i want to apply to my game but i cant even do a simple natural log function!

Also, try to exploit every possible property of the things you're working with (e.g. logs' bases multiplication whenever ther is log + log, Taylor, etc.); Khris' code is quite silky, but overusing it could be the doom of your game.
Title: Re: Advanced math operators
Post by: Khris on Tue 27/01/2009 15:00:20
Just out of interest, what are you planning to do in your game?