21 # pragma warning (push)
22 # pragma warning (disable : 4127)
24 # pragma warning (disable : 4530)
34 #if defined(_MSC_VER) && (_MSC_VER < 1000)
37 # define PRId64 "I64d"
50 #define _ISOC9X_SOURCE1
51 #define _ISOC99_SOURCE1
68 #define G3D_DECLARE_SYMBOL(s) \
69 static const std::string SYMBOL_##s = #s
76 return ::rand() / double(RAND_MAX);
95 __inline
long int lrint (
double flt) {
106 __inline
long int lrintf(
float flt) {
119 __inline
long int lrintf(
float flt) {
120 return (
long int)(flt + 0.5f);
123 __inline
long int lrint (
double flt) {
124 return (
long int)(flt + 0.5);
131 #define fuzzyEpsilon64 (0.0000005)
132 #define fuzzyEpsilon32 (0.00001f)
148 return 3.1415926535898;
152 return 3.1415926535898f;
175 int iAbs(
int iValue);
176 int iCeil(
double fValue);
181 int iClamp(
int val,
int low,
int hi);
182 int16
iClamp(int16 val, int16 low, int16 hi);
183 double clamp(
double val,
double low,
double hi);
184 float clamp(
float val,
float low,
float hi);
189 inline double lerp(
double a,
double b,
double f) {
190 return a + (b - a) * f;
193 inline float lerp(
float a,
float b,
float f) {
194 return a + (b - a) * f;
203 int iWrap(
int val,
int hi);
205 int iFloor(
double fValue);
207 int iSign(
int iValue);
208 int iSign(
double fValue);
211 return iSign((
double)f);
215 return floor(f + 0.5f);
219 return floor(f + 0.5f);
227 return lrint(fValue);
245 double abs (
double fValue);
246 double aCos (
double fValue);
247 double aSin (
double fValue);
248 double aTan (
double fValue);
249 double aTan2 (
double fY,
double fX);
250 double sign (
double fValue);
251 double square (
double fValue);
293 float gaussRandom(
float mean = 0.0f,
float stdev = 1.0f);
305 inline T
min(
const T&
x,
const T&
y) {
306 return std::min<T>(
x,
y);
310 inline T
min(
const T&
x,
const T&
y,
const T&
z) {
311 return std::min<T>(std::min<T>(
x,
y), z);
315 inline T
min(
const T&
x,
const T&
y,
const T&
z,
const T& w) {
316 return std::min<T>(std::min<T>(
x,
y), std::min<T>(z, w));
320 inline T
max(
const T&
x,
const T&
y) {
321 return std::max<T>(
x,
y);
325 inline T
max(
const T&
x,
const T&
y,
const T&
z) {
326 return std::max<T>(std::max<T>(
x,
y), z);
330 inline T
max(
const T&
x,
const T&
y,
const T&
z,
const T& w) {
331 return std::max<T>(std::max<T>(
x,
y), std::max<T>(z, w));
356 bool fuzzyEq(
double a,
double b);
362 bool fuzzyNe(
double a,
double b);
366 bool fuzzyGt(
double a,
double b);
369 bool fuzzyGe(
double a,
double b);
372 bool fuzzyLt(
double a,
double b);
375 bool fuzzyLe(
double a,
double b);
381 return 1.0f / sqrtf(x);
401 return ::logf(x) * 1.442695f;
405 return log2((
double)x);
445 inline float dot(
float a,
float b) {
453 inline float mul(
float a,
float b) {
465 return powf(2.0f, x);
470 return 1.0 / sqrt(x);
476 return 1.0f / sqrtf(x);
483 double r = sin(x) /
x;
495 inline float wrap(
float t,
float lo,
float hi) {
496 if ((t >= lo) && (t < hi)) {
502 float interval = hi - lo;
504 return t - interval *
iFloor((t - lo) / interval);
508 inline double wrap(
double t,
double lo,
double hi) {
509 if ((t >= lo) && (t < hi)) {
515 double interval = hi - lo;
517 return t - interval *
iFloor((t - lo) / interval);
520 inline double wrap(
double t,
double hi) {
521 return wrap(t, 0.0, hi);
535 return ( iValue >= 0 ? iValue : -iValue );
540 return int(::
ceil(fValue));
545 inline int iClamp(
int val,
int low,
int hi) {
549 }
else if (val >= hi) {
558 inline int16
iClamp(int16 val, int16 low, int16 hi) {
562 }
else if (val >= hi) {
571 inline double clamp(
double val,
double low,
double hi) {
575 }
else if (val >= hi) {
582 inline float clamp(
float val,
float low,
float hi) {
586 }
else if (val >= hi) {
596 return ((val % hi) + hi) % hi;
604 return int(::
floor(fValue));
609 return ( iValue > 0 ? + 1 : ( iValue < 0 ? -1 : 0 ) );
613 return ( fValue > 0.0 ? + 1 : ( fValue < 0.0 ? -1 : 0 ) );
617 inline double abs (
double fValue) {
618 return double(::fabs(fValue));
622 inline double aCos (
double fValue) {
623 if ( -1.0 < fValue ) {
625 return double(::
acos(fValue));
633 inline float acos (
float fValue) {
634 if ( -1.0f < fValue ) {
635 if ( fValue < 1.0f ) {
646 inline double aSin (
double fValue) {
647 if ( -1.0 < fValue ) {
648 if ( fValue < 1.0 ) {
649 return double(::asin(fValue));
659 inline double aTan (
double fValue) {
660 return double(::atan(fValue));
664 inline double aTan2 (
double fY,
double fX) {
665 return double(::atan2(fY, fX));
669 inline double sign (
double fValue) {
681 inline float sign (
float fValue) {
695 return (hi - low) * float(::rand()) / float(RAND_MAX) + low;
722 return x*x + y*y + z*
z;
727 return x*x + y*y + z*
z;
754 return (x >= y) ? y :
x;
760 return (x >= y) ? x :
y;
777 return ((num & -num) == num);
782 return ((x != 0) && !(x & (x - 1)));
787 return ((x != 0) && !(x & (x - 1)));
791 return (num & 1) == 1;
795 return (num & 1) == 0;
799 return deg *
pi() / 180.0;
803 return rad * 180.0 /
pi();
807 return deg * (float)
pi() / 180.0f;
811 return rad * 180.0f / (float)
pi();
815 return deg * (float)
pi() / 180.0f;
819 return rad * 180.0f / (float)
pi();
824 inline double eps(
double a,
double b) {
830 const double aa =
abs(a) + 1.0;
838 inline float eps(
float a,
float b) {
844 const float aa = (float)
abs(a) + 1.0f;
854 return (a == b) || (
abs(a - b) <=
eps(a, b));
858 return (a == b) || (
abs(a - b) <=
eps(a, b));
866 return a > b +
eps(a, b);
870 return a > b -
eps(a, b);
874 return a < b -
eps(a, b);
878 return a < b +
eps(a, b);
889 return (x << 24) | ((x & 0xFF00) << 8) |
890 ((x & 0xFF0000) >> 8) | ((x & 0xFF000000) >> 24);
897 return (x << 8) | ((x & 0xFF00) >> 8);
903 x =
clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
906 return x * x * (3 - 2 *
x);
914 x =
clamp((x - edge0) / (edge1 - edge0), 0.0f, 1.0f);
917 return x * x * x * (x * (x * 6 - 15) + 10);
923 return sign(b) * powf(fabsf(b), e);
936 inline int pow(
int a,
int b) {
937 return (
int)
pow(
double(a),
double(b));
942 # pragma warning (pop)
float finf()
Definition: g3dmath.cpp:71
float fnan()
Definition: g3dmath.cpp:82
float signedPow(float b, float e)
Definition: g3dmath.h:922
int16_t int16
Definition: g3dmath.h:165
uint32 flipEndian32(const uint32 x)
Definition: g3dmath.h:888
double round(double f)
Definition: g3dmath.h:214
signed short int16_t
Definition: stdint.h:76
int iSign(int iValue)
Definition: g3dmath.h:608
double sumSquares(double x, double y)
Definition: g3dmath.h:711
double abs(double fValue)
Definition: g3dmath.h:617
static Vector3int16 floor(const Vector3 &v)
double aTan2(double fY, double fX)
Definition: g3dmath.h:664
int iAbs(int iValue)
Definition: g3dmath.h:534
double float64
Definition: g3dmath.h:173
int8_t int8
Definition: g3dmath.h:163
int iRound(double fValue)
Definition: g3dmath.h:226
TC_SHARED_API::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions,::google::protobuf::internal::EnumTypeTraits< ::bgs::protocol::LogOption,::bgs::protocol::LogOption_IsValid >, 14, false > log
#define fuzzyEpsilon64
Definition: g3dmath.h:131
bool any(float x)
Definition: g3dmath.h:424
bool isNaN(double x)
Definition: g3dmath.cpp:56
int iFloor(double fValue)
Definition: g3dmath.h:603
float mul(float a, float b)
Definition: g3dmath.h:453
int highestBit(uint32 x)
Definition: g3dmath.cpp:88
uint64_t uint64
Definition: g3dmath.h:170
bool fuzzyNe(double a, double b)
Definition: g3dmath.h:861
float rsq(float x)
Definition: g3dmath.h:380
double clamp(double val, double low, double hi)
Definition: g3dmath.h:571
float smoothstep(float edge0, float edge1, float x)
Definition: g3dmath.h:901
bool isPow2(int num)
Definition: g3dmath.h:776
uint16 flipEndian16(const uint16 x)
Definition: g3dmath.h:896
double pi()
Definition: g3dmath.h:147
signed __int64 int64_t
Definition: stdint.h:89
double aTan(double fValue)
Definition: g3dmath.h:659
double sinc(double x)
Definition: g3dmath.h:482
uint16_t uint16
Definition: g3dmath.h:166
double distance(double x, double y)
Definition: g3dmath.h:731
bool all(float x)
Definition: g3dmath.h:431
T max(const T &x, const T &y)
Definition: g3dmath.h:320
double log2(double x)
Definition: g3dmath.h:396
float wrap(float t, float lo, float hi)
Definition: g3dmath.h:495
unsigned int uint32_t
Definition: stdint.h:80
int iMod3(int x)
Definition: g3dmath.h:881
float normalize(float v)
Definition: g3dmath.h:438
float uniformRandom(float low=0.0f, float hi=1.0f)
Definition: g3dmath.h:694
T min(const T &x, const T &y)
Definition: g3dmath.h:305
double inf()
Definition: g3dmath.cpp:40
float gaussRandom(float mean=0.0f, float stdev=1.0f)
Definition: g3dmath.cpp:18
double toRadians(double deg)
Definition: g3dmath.h:798
unsigned __int64 uint64_t
Definition: stdint.h:90
#define debugAssert(exp)
Definition: debugAssert.h:160
G3D::int16 z
Definition: Vector3int16.h:46
float float32
Definition: g3dmath.h:172
G3D::int16 y
Definition: Vector2int16.h:38
bool isOdd(int num)
Definition: g3dmath.h:790
double square(double fValue)
Definition: g3dmath.h:698
bool isEven(int num)
Definition: g3dmath.h:794
double aCos(double fValue)
Definition: g3dmath.h:622
int pow2(unsigned int x)
Definition: g3dmath.h:392
#define fuzzyEpsilon32
Definition: g3dmath.h:132
double twoPi()
Definition: g3dmath.h:159
float acos(float fValue)
Definition: g3dmath.h:633
T pow5(T x)
Definition: g3dmath.h:298
int64_t int64
Definition: g3dmath.h:169
G3D::Quat pow(const G3D::Quat &q, double x)
Definition: Quat.h:761
uint8_t uint8
Definition: g3dmath.h:164
int iWrap(int val, int hi)
Definition: g3dmath.h:594
unsigned char uint8_t
Definition: stdint.h:78
float dot(float a, float b)
Definition: g3dmath.h:445
signed char int8_t
Definition: stdint.h:75
int32_t int32
Definition: g3dmath.h:167
double exp2(double x)
Definition: g3dmath.h:460
double toDegrees(double rad)
Definition: g3dmath.h:802
float pif()
Definition: g3dmath.h:151
signed int int32_t
Definition: stdint.h:77
double lerp(double a, double b, double f)
Definition: g3dmath.h:189
float smootherstep(float edge0, float edge1, float x)
Definition: g3dmath.h:911
bool fuzzyGt(double a, double b)
Definition: g3dmath.h:865
uint32_t uint32
Definition: g3dmath.h:168
bool fuzzyGe(double a, double b)
Definition: g3dmath.h:869
double aSin(double fValue)
Definition: g3dmath.h:646
G3D::int16 x
Definition: Vector2int16.h:37
static Vector3int16 ceil(const Vector3 &v)
Definition: Vector3int16.cpp:55
double eps(double a, double b)
Definition: g3dmath.h:824
double halfPi()
Definition: g3dmath.h:155
int iMax(int x, int y)
Definition: g3dmath.h:759
int iClamp(int val, int low, int hi)
Definition: g3dmath.h:545
int iRandom(int low, int hi)
Definition: g3dmath.cpp:110
double sign(double fValue)
Definition: g3dmath.h:669
int ceilPow2(unsigned int in)
Definition: g3dmath.h:764
unsigned short uint16_t
Definition: stdint.h:79
bool fuzzyEq(double a, double b)
Definition: g3dmath.h:857
double nan()
Definition: g3dmath.cpp:77
bool fuzzyLe(double a, double b)
Definition: g3dmath.h:877
bool isFinite(double x)
Definition: g3dmath.h:525
int iCeil(double fValue)
Definition: g3dmath.h:539
double rsqrt(double x)
Definition: g3dmath.h:469
int iMin(int x, int y)
Definition: g3dmath.h:753
bool fuzzyLt(double a, double b)
Definition: g3dmath.h:873