Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 25 Vote(s) - 4.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Us To Improve the Wiki!
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#85
RE: Help Us To Improve the Wiki!

I was thinking about what other sort of resources might be worth while producing (Hoping to get what would amount to maybe 5 pages or so - enough to kick off a new "resources" script category). In a previous post i put up some basic string parsing & a proper dynamic list structure - which covers two pages. Math functions (sin/cos/tan and inverses + sqrt) are certainly worth considering for a third. Perhaps stacks/queues? or maybe something a little more interesting?



The second part of this is of course what formatting I should use. I've been writing with folding regions as defined by my updated notepad++ files (I want to have these replace the outdated version but I can't upload files to the wiki! If somebody would be so kind as to upload the latest version it would be v. useful).
But perhaps it is better to strip out all but very simplistic comments - moving the documentation into the wiki page for each resource?

Of course, I don't want to be soloing this resources idea so if anyone would like to get working on it too it'd help out alot! Smile I probably wont get around to this until after my map for teamnesia & have made more progress on my current WIP anyway.

Edit:
Here's the progress i'm willing to make on the math part for now - i'm tired and mathed out - not all fully tested (atan2 is untested but simply lifted from gamedev so it should work?) Again, all of this has folding regions as per the updated np++ files.
//Begin Math
//+ Constants
const float PI = 3.1415926535f;
const float HPI = PI * 0.5f;
const float PI2 = PI * 2.0f;
//-
//+ Sign Of
int sign(float &in x) { if(x==0.0f) return 0; return (x>0.0f)?1:-1; }
int sign(int &in x)   { if(x==0)    return 0; return (x>0)?1:-1; }
//-
//+ Abs
float abs(float &in x) { return (x>0.0f)?x:-x; }
int abs(int &in x)     { return (x>0)?x:-x; }
//-
//+ Approx
//Determines if two numbers are approximately equal (Differ by no more than epsilon)
bool approx(float &in x, float &in y, float &in epsilon) {
float delta = x-y; return ((delta>0?delta:-delta) <= (epsilon>0?epsilon:-epsilon)); }
//-
//+ Sqrt
//Prereq: Approx
//Returns the squareroot of x
const uint32 _SQRTITERATIONS=16; //Maximum number of iterations for sqrt computation
const float  _SQRTDELTA=0.00001f; //Margin of error allowable if complete before iteration ceiling
float sqrt(float &in x) {
  if(x<=0) return 0; //Early out - not valid input.
  uint32 i = 0; float o = x * 0.5f;
  while( i<_SQRTITERATIONS && !approx(o*o,x,_SQRTDELTA) && o != 0)
    { o = 0.5f * (o + x/o); i++; }
  return o;             }
//-
//+ Max/Min
//Max: Returns largest of two numbers
//Min: Returns smallest of two numbers
float max(float &in x, float &in y) { return x>y?x:y; }
int max(int &in x, int &in y) { return x>y?x:y; }
float min(float &in x, float &in y) { return x<y?x:y; }
int min(int &in x, int &in y) { return x<y?x:y; }
float clamp(float &in x, float &in upper, float &in lower) { return (x<lower?lower:(x<upper?x:upper)); }
int clamp(int &in x, int &in upper, int &in lower) { return (x<lower?lower:(x<upper?x:upper)); }
//-
//+ Factorial
uint32 fact(uint32 &in x) { if(x==0) return 1;
    uint32 y = x; for(uint32 i=x-1; i>0; i--) y*=i; return y; }
int fact(int &in x)       { if(x<=0) return 1;
    int y = x; for(int i=x-1; i>0; i--) y*=i; return y; }
//-
//+ Conversions
//Degrees to radians
float degtorad(float &in x) { return x * 0.0174532925f; }
//Radians to degrees
float radtodeg(float &in x) { return x * 57.2957795f; }
//-
//+ Trig Functions
//+ ..Helper
const float  _TRIGARCTANLIM=128.0f; //Value when x exceeds 90 is returned
const uint32 _TRIGITERATIONS=32; //Maximum number of iterations for sqrt computation
const float  _TRIGDELTA=0.00001f; //Smallest diff for trig vals
//Constrains X : -PI<X<PI
float trigClamp(float &in x) {
if(x > PI || x < -PI)
  { int t = x/PI2; return x-t*PI2; }
else return x;
}
//-
//+ ..Sin/Cos/Tan
//COSINE
float cos(float &in y) {
  float x = trigClamp(y);
  float t,s; t=1.0f; s = 1.0f; uint32 p=0;
  while( p<_TRIGITERATIONS)
   { p++; t = (-t * x * x) / ((2 * p - 1) * (2 * p)); s+=t; }
  return s;
}
//SINE
float sin(float &in y) {
  return cos(y-HPI);
}
//TAN (Tan(90 deg) Returns 0xFFFFFFFF [Use isInf()])
float tan(float &in y) {
  float x = trigClamp(y);
  float c = cos(x);
  if(c > -_TRIGDELTA/2 && c <_TRIGDELTA/2) return float(0xFFFFFFFF); //Return #+INF                                        
  return cos(x-HPI)/c;
}
//-
//+ ..ARC Sin/Cos/Tan [APPROX]
float arccos(float &in x) {
return trigClamp((-0.69813170079773212f * x * x - 0.87266462599716477f) * x + 1.5707963267948966f); }
float arcsin(float &in x) { return trigClamp(HPI-arccos(x)); }
float arctan(float &in x) {  if(x > _TRIGARCTANLIM) return HPI;
else if(x < -_TRIGARCTANLIM) return -HPI; else return trigClamp(HPI-arccos(x/sqrt(x*x+1.1f))); }
float arctan2(float &in x, float &in y) {
float c1 = HPI * 0.5f;    float c2 = 3.0f * c1; float abs_y = abs(y); float angle;    
if (x >= 0) { float r = (x - abs_y) / (x + abs_y);    angle = c1 - c1 * r;    }
else { float r = (x + abs_y) / (abs_y - x);    angle = c2 - c1 * r;    }    
return y<0?-angle:angle; }
//Can somebody actually get a good expansion to work here?
//-
//-
//+ Rounding
int floor(float &in x) { return int(x); }
int ceil(float &in x)  { int y = int(x); return (y==x?y:y+1); }
int round(float &in x) { int y = int(x); return (y+0.5f>x)?y:(y+1);}
//-
//End

Edit 2:
arctan2 works.
(This post was last modified: 12-09-2011, 05:37 AM by Apjjm.)
09-05-2011, 06:13 PM
Find


Messages In This Thread
Help Us To Improve the Wiki! - by Tanshaydar - 06-20-2011, 04:05 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-13-2011, 01:51 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 07-13-2011, 04:49 PM
RE: Help Us To Improve the Wiki! - by Kyle - 07-13-2011, 02:23 PM
RE: Help Us To Improve the Wiki! - by xtron - 07-13-2011, 04:25 PM
RE: Help Us To Improve the Wiki! - by xtron - 07-13-2011, 05:02 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-13-2011, 05:07 PM
RE: Help Us To Improve the Wiki! - by Kyle - 07-13-2011, 05:15 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-13-2011, 05:24 PM
RE: Help Us To Improve the Wiki! - by xtron - 07-13-2011, 09:37 PM
RE: Help Us To Improve the Wiki! - by Kyle - 07-13-2011, 09:40 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-13-2011, 10:50 PM
RE: Help Us To Improve the Wiki! - by xtron - 07-13-2011, 11:16 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-14-2011, 12:12 AM
RE: Help Us To Improve the Wiki! - by Kyle - 07-14-2011, 12:50 AM
RE: Help Us To Improve the Wiki! - by xtron - 07-14-2011, 01:11 AM
RE: Help Us To Improve the Wiki! - by yasar11732 - 07-14-2011, 01:54 AM
RE: Help Us To Improve the Wiki! - by Kyle - 07-14-2011, 02:06 AM
RE: Help Us To Improve the Wiki! - by xtron - 07-14-2011, 02:05 AM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 07-14-2011, 02:53 AM
RE: Help Us To Improve the Wiki! - by xtron - 07-14-2011, 03:00 AM
RE: Help Us To Improve the Wiki! - by Kyle - 07-14-2011, 03:26 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-14-2011, 08:57 AM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 07-14-2011, 10:13 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-14-2011, 10:51 AM
RE: Help Us To Improve the Wiki! - by jens - 07-14-2011, 10:53 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-14-2011, 11:18 AM
RE: Help Us To Improve the Wiki! - by jens - 07-14-2011, 11:36 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-14-2011, 12:07 PM
RE: Help Us To Improve the Wiki! - by xtron - 07-14-2011, 12:09 PM
RE: Help Us To Improve the Wiki! - by xtron - 07-14-2011, 01:34 PM
RE: Help Us To Improve the Wiki! - by Kyle - 07-14-2011, 03:03 PM
RE: Help Us To Improve the Wiki! - by xtron - 07-14-2011, 03:47 PM
RE: Help Us To Improve the Wiki! - by Kyle - 07-14-2011, 06:09 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-14-2011, 11:51 PM
RE: Help Us To Improve the Wiki! - by xtron - 07-14-2011, 11:54 PM
RE: Help Us To Improve the Wiki! - by Kyle - 07-14-2011, 11:55 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 07-15-2011, 12:08 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-15-2011, 01:14 AM
RE: Help Us To Improve the Wiki! - by Kyle - 07-15-2011, 01:31 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-15-2011, 01:36 AM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 07-15-2011, 01:40 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-15-2011, 10:31 AM
RE: Help Us To Improve the Wiki! - by xtron - 07-15-2011, 10:57 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-15-2011, 11:11 AM
RE: Help Us To Improve the Wiki! - by Rel - 07-18-2011, 05:01 PM
RE: Help Us To Improve the Wiki! - by Kyle - 07-18-2011, 05:05 PM
RE: Help Us To Improve the Wiki! - by Rel - 07-18-2011, 05:18 PM
RE: Help Us To Improve the Wiki! - by Kyle - 07-18-2011, 05:38 PM
RE: Help Us To Improve the Wiki! - by Rel - 07-18-2011, 05:57 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-18-2011, 06:19 PM
RE: Help Us To Improve the Wiki! - by Rel - 07-18-2011, 06:24 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-18-2011, 06:33 PM
RE: Help Us To Improve the Wiki! - by Rel - 07-18-2011, 07:43 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 07-21-2011, 05:48 AM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 07-21-2011, 06:01 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 07-21-2011, 08:23 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 07-22-2011, 03:04 AM
RE: Help Us To Improve the Wiki! - by Rel - 07-22-2011, 04:15 AM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 07-22-2011, 04:34 AM
RE: Help Us To Improve the Wiki! - by Apjjm - 08-16-2011, 08:12 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 08-16-2011, 08:23 PM
RE: Help Us To Improve the Wiki! - by Apjjm - 08-17-2011, 02:01 AM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 08-17-2011, 08:49 AM
RE: Help Us To Improve the Wiki! - by plutomaniac - 08-17-2011, 09:36 AM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 08-17-2011, 08:06 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 08-17-2011, 09:56 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 08-17-2011, 10:06 PM
RE: Help Us To Improve the Wiki! - by plutomaniac - 08-17-2011, 10:08 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 08-18-2011, 09:07 AM
RE: Help Us To Improve the Wiki! - by jens - 08-18-2011, 09:56 AM
RE: Help Us To Improve the Wiki! - by Elven - 08-21-2011, 10:23 PM
RE: Help Us To Improve the Wiki! - by JetlinerX - 08-22-2011, 04:54 AM
RE: Help Us To Improve the Wiki! - by Elven - 08-22-2011, 10:01 AM
RE: Help Us To Improve the Wiki! - by Apjjm - 09-05-2011, 06:13 PM
RE: Help Us To Improve the Wiki! - by Elven - 10-19-2011, 08:13 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 10-19-2011, 09:13 PM
RE: Help Us To Improve the Wiki! - by Elven - 10-19-2011, 10:17 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 10-19-2011, 10:52 PM
RE: Help Us To Improve the Wiki! - by Elven - 10-19-2011, 10:59 PM
RE: Help Us To Improve the Wiki! - by Nevicar - 03-11-2012, 04:50 AM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 03-11-2012, 05:34 AM
RE: Help Us To Improve the Wiki! - by Nevicar - 03-11-2012, 05:54 AM
RE: Help Us To Improve the Wiki! - by ClayPigeon - 03-15-2012, 12:17 PM
RE: Help Us To Improve the Wiki! - by Stepper321 - 03-16-2012, 05:37 PM
RE: Help Us To Improve the Wiki! - by Tanshaydar - 03-16-2012, 06:18 PM
RE: Help Us To Improve the Wiki! - by Stepper321 - 03-16-2012, 07:54 PM
RE: Help Us To Improve the Wiki! - by jessehmusic - 04-06-2012, 04:22 PM
RE: Help Us To Improve the Wiki! - by Homicide13 - 05-07-2012, 01:26 AM
RE: Help Us To Improve the Wiki! - by Apjjm - 05-07-2012, 02:35 AM
RE: Help Us To Improve the Wiki! - by Homicide13 - 05-07-2012, 03:01 AM
RE: Help Us To Improve the Wiki! - by Traggey - 05-19-2012, 02:13 AM
RE: Help Us To Improve the Wiki! - by Apjjm - 06-12-2012, 03:34 AM
RE: Help Us To Improve the Wiki! - by jens - 06-12-2012, 06:57 AM
RE: Help Us To Improve the Wiki! - by Finzy - 08-04-2012, 03:33 PM
RE: Help Us To Improve the Wiki! - by The chaser - 10-26-2012, 04:31 PM
RE: Help Us To Improve the Wiki! - by Racingcreed - 12-08-2012, 08:21 PM



Users browsing this thread: 1 Guest(s)