00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 #ifndef INC_MACROS
00106 #define INC_MACROS
00107
00108 #include <math.h>
00109
00110 #define _Long(x) ((INT32)(x))
00111 #define _Int(x) ((INT32)(x))
00112 #define _Float(x) ((FLOAT)(x))
00113 #define _Dble(x) ((double)(x))
00114
00115 double const XS_2PI = 6.28318530717958623200;
00116 double const XS_DEGTORAD = 0.01745329251994329547;
00117 double const XS_E = 2.71828182845904553488;
00118 double const XS_EEXPPI = 23.14069263277927390732;
00119 double const XS_GOLDEN = 1.61803398874989490253;
00120 double const XS_INVPI = 0.31830988618379069122;
00121 double const XS_LN10 = 2.30258509299404590109;
00122 double const XS_LN2 = 0.69314718055994528623;
00123 double const XS_LOG10E = 0.43429448190325187218;
00124 double const XS_LOG2E = 1.44269504088896338700;
00125 double const XS_LOG05 = -0.693147180559945;
00126 double const XS_PI = 3.14159265358979323846;
00127 double const XS_PIDIV2 = 1.57079632679489655800;
00128 double const XS_PIDIV4 = 0.78539816339744827900;
00129 double const XS_RADTODEG = 57.29577951308232286465;
00130 double const XS_SQRT2 = 1.41421356237309514547;
00131 double const XS_SQRT2PI = 2.50662827463100024161;
00132 double const XS_SQRT3 = 1.73205080756887719318;
00133 double const XS_SQRT10 = 3.16227766016837952279;
00134 double const XS_SQRTE = 1.64872127070012819416;
00135 double const XS_SQRTHALF = 0.70710678118654757274;
00136 double const XS_SQRTLN2 = 0.83255461115769768821;
00137 double const XS_SQRTPI = 1.77245385090551588192;
00138 double const XS_EPSILON = 1.0e-10;
00139 double const XS_GOOGOL = 1.0e50;
00140
00141
00142
00143
00144
00145
00146 inline INT32 LClamp(INT32 x, INT32 min, INT32 max)
00147 {
00148 return (x < min ? min : (x > max ? max : x));
00149 }
00150
00151 inline INT32 LAbs(INT32 x)
00152 {
00153 return (x >= 0) ? x : -x;
00154 }
00155
00156 inline INT32 LSign(INT32 x)
00157 {
00158 return (x < 0) ? -1 : 1;
00159 }
00160
00161 inline INT32 LSmooth(INT32 x)
00162 {
00163 return (3 - 2 * x) * x * x;
00164 }
00165
00166
00167
00168
00169
00170
00171 inline INT32 LMin(INT32 x, INT32 y)
00172 {
00173 return (x < y) ? x : y;
00174 }
00175
00176 inline INT32 LMax(INT32 x, INT32 y)
00177 {
00178 return (x > y) ? x : y;
00179 }
00180
00181
00182
00183
00184
00185
00186 inline INT32 LMin(INT32 x, INT32 y, INT32 z)
00187 {
00188 return (x < y) ? LMin(x, z) : LMin(y, z);
00189 }
00190
00191 inline INT32 LMax(INT32 x, INT32 y, INT32 z)
00192 {
00193 return (x > y) ? LMax(x, z) : LMax(y, z);
00194 }
00195
00196
00197
00198
00199
00200
00201
00202 inline float FClamp(float x)
00203 {
00204 return (x < 0.0f ? 0.0f : (x > 1.0f ? 1.0f : x));
00205 }
00206
00207 inline float FAbs(float x)
00208 {
00209 return (x >= 0.0f) ? x : -x;
00210 }
00211
00212 inline float FFrac(float x)
00213 {
00214 return (x-((INT32)(x)));
00215 }
00216
00217 inline float FCeil(float x)
00218 {
00219 return (x == _Int(x)) ? x : (x > 0.0f) ? _Float(_Int(x) + 1.0f) : _Float(_Int(x));
00220 }
00221
00222 inline float FFloor(float x)
00223 {
00224 return (x == _Int(x)) ? x : (x > 0.0f) ? _Float(_Int(x)) : _Float(_Int(x) - 1.0f);
00225 }
00226
00227 inline float FRound(float x)
00228 {
00229 return (x >= 0.0f) ? _Float(_Int(x + 0.5f)) : _Float(- _Int(0.5f - x));
00230 }
00231
00232 inline float FSign(float x)
00233 {
00234 return (x < 0.0f) ? -1.0f : 1.0f;
00235 }
00236
00237 inline float FSmooth(float x)
00238 {
00239 return (3.0f - 2.0f * x) * x * x;
00240 }
00241
00242 inline float FTrunc(float x)
00243 {
00244 return _Float(_Int(x));
00245 }
00246
00247
00248
00249
00250
00251
00252 inline float FMin(float x, float y)
00253 {
00254 return (x < y) ? x : y;
00255 }
00256
00257 inline float FMax(float x, float y)
00258 {
00259 return (x > y) ? x : y;
00260 }
00261
00262
00263
00264
00265
00266
00267 inline float FMax(float x, float y, float z)
00268 {
00269 return (x > y) ? FMax(x, z) : FMax(y, z);
00270 }
00271
00272 inline float FMin(float x, float y, float z)
00273 {
00274 return (x < y) ? FMin(x, z) : FMin(y, z);
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288 inline double DAbs(double f)
00289 {
00290 return (f >= 0) ? f : -f;
00291 }
00292
00293 inline double DFrac(double f)
00294 {
00295 return (f-_Long(f));
00296 }
00297
00298 inline double DCeil(double f)
00299 {
00300 return (f == _Int(f)) ? f : (f > 0) ? _Dble(_Int(f) + 1) : _Dble(_Int(f));
00301 }
00302
00303 inline double DCube(double f)
00304 {
00305 return f * f * f;
00306 }
00307
00308 inline double DDegrees(double f)
00309 {
00310 return f * XS_RADTODEG;
00311 }
00312
00313 inline double DFloor(double f)
00314 {
00315 return (f == _Int(f)) ? f : (f > 0) ? _Dble(_Int(f)) : _Dble(_Int(f)-1);
00316 }
00317
00318 inline double DInv(double f)
00319 {
00320 return 1.0 / f;
00321 }
00322
00323 inline BOOL DIsZero(double f)
00324 {
00325 return ((f<=0.0) ? (f >= -XS_EPSILON) : (f <= XS_EPSILON));
00326 }
00327
00328 inline double DRadians(double f)
00329 {
00330 return f * XS_DEGTORAD;
00331 }
00332
00333 inline double DRound(double f)
00334 {
00335 return (f >= 0) ? _Dble(_Int(f + 0.5)) : _Dble(- _Int(0.5 - f));
00336 }
00337
00338 inline double DSign(double f)
00339 {
00340 return (f < 0) ? -1.0 : 1.0;
00341 }
00342
00343 inline double DSmooth(double f)
00344 {
00345 return (3.0 - 2.0 * f) * f * f;
00346 }
00347
00348 inline double DTrunc(double f)
00349 {
00350 return _Dble(_Int(f));
00351 }
00352
00353 inline double DZSign(double f)
00354 {
00355 return (f > 0) ? 1.0 : (f < 0) ? -1.0 : 0.0;
00356 }
00357
00358 inline double DCubeRoot(double x)
00359 {
00360 return (x>0.0) ? pow(x, 1.0/3.0) : (x<0.0) ? -pow(-x, 1.0/3.0) : 0.0;
00361 }
00362
00363
00364
00365
00366
00367
00368
00369 inline BOOL DFuzEQ(double f, double g)
00370 {
00371 return (f <= g) ? (f >= g - XS_EPSILON) : (f <= g + XS_EPSILON);
00372 }
00373
00374 inline BOOL DFuzGEQ(double f, double g)
00375 {
00376 return (f >= g - XS_EPSILON);
00377 }
00378
00379 inline BOOL DFuzLEQ(double f, double g)
00380 {
00381 return (f <= g + XS_EPSILON);
00382 }
00383
00384 inline double DMax(double f, double g)
00385 {
00386 return (f > g) ? f : g;
00387 }
00388
00389 inline double DMin(double f, double g)
00390 {
00391 return (f < g) ? f : g;
00392 }
00393
00394 inline void DSwap(double& f, double& g)
00395 {
00396 double gmTmp = f; f = g; g = gmTmp;
00397 }
00398
00399 inline void DSwap(INT32& i, INT32& j)
00400 {
00401 INT32 gmTmp = i; i = j; j = gmTmp;
00402 }
00403
00404 inline void DSort(double& lo, double& hi)
00405 {
00406 if (lo>hi) DSwap(lo,hi);
00407 }
00408
00409 inline double DStep(double a, double f)
00410 {
00411 return _Dble(f>=a);
00412 }
00413
00414 inline double DFuzStep(double a, double f, double fzz)
00415 {
00416 return _Dble(f>=(a+fzz));
00417 }
00418
00419 inline double DGamma(double gamma, double f)
00420 {
00421 return (gamma==0.0) ? XS_GOOGOL : pow(f, 1/gamma);
00422 }
00423
00424 inline double DBias(double bias, double f)
00425 {
00426 return pow(f,log(bias)/log(0.5));
00427 }
00428
00429 inline double DGain(double gain, double f)
00430 {
00431 return (f<0.5) ? (DBias(1.0-gain,2.0*f)/2.0) : (1-DBias(1.0-gain, 2.0-2.0*f)/2.0);
00432 }
00433
00434 inline double DExculsiveOr(double a, double b)
00435 {
00436 return (a + b - a * b);
00437 }
00438
00439 inline double DIntersection(double a, double b)
00440 {
00441 return (a * b);
00442 }
00443
00444 inline double DDifference(double a, double b)
00445 {
00446 return (a - a * b);
00447 }
00448
00449 inline double DRepeat(double u, double freq)
00450 {
00451
00452 return DFrac(u*freq);
00453 }
00454
00455 inline double DTile(double u, double freq)
00456 {
00457
00458 return _Long(u*freq);
00459 }
00460
00461
00462
00463
00464
00465
00466
00467 inline double DClamp(const double x, const double a, const double b)
00468 {
00469 return (x < a ? a : (x > b ? b : x));
00470 }
00471
00472 inline double DLerp(double f, double l, double h)
00473 {
00474 return l + ((h - l) * f );
00475 }
00476
00477 inline double DNorm(double f, double a, double b)
00478 {
00479 return (f-a)/(b-a);
00480 }
00481
00482 inline double DMax(double f, double g, double h)
00483 {
00484 return (f > g) ? DMax(f, h) : DMax(g, h);
00485 }
00486
00487 inline double DMin(double f, double g, double h)
00488 {
00489 return (f < g) ? DMin(f, h) : DMin(g, h);
00490 }
00491
00492 inline double DSlide(double f, double l, double h)
00493 {
00494 return (f < 0) ? l : (f > 1) ? h : DLerp(DSmooth(f), l, h);
00495 }
00496
00497 inline double DSmoothStep(double a, double b, double f)
00498 {
00499 return (f < a) ? 0.0 : (f > b) ? 1.0 : DSmooth(DNorm(f,a,b));
00500 }
00501
00502 inline double DBoxStep(double a, double b, double x)
00503 {
00504 return (DClamp((x-a)/(b-a),0,1));
00505 }
00506
00507 inline double DPulse(double a, double b, double x)
00508 {
00509 return (DStep(a,x) - DStep(b,x));
00510 }
00511
00512 inline double DFuzPulse(double a, double b, double x, double fzz)
00513 {
00514 return (DFuzStep(a,x,-fzz) - DFuzStep(b,x,+fzz));
00515 }
00516
00517 inline double DRange(double t,
00518 double min, double max,
00519 double lo, double mid, double hi)
00520 {
00521 return (t<min) ? lo : ((t>max) ? hi : mid);
00522 }
00523
00524
00525 #endif