Blender  V3.3
gim_math.h
Go to the documentation of this file.
1 #ifndef GIM_MATH_H_INCLUDED
2 #define GIM_MATH_H_INCLUDED
6 /*
7 -----------------------------------------------------------------------------
8 This source file is part of GIMPACT Library.
9 
10 For the latest info, see http://gimpact.sourceforge.net/
11 
12 Copyright (c) 2006 Francisco Leon Najera. C.C. 80087371.
13 email: projectileman@yahoo.com
14 
15  This library is free software; you can redistribute it and/or
16  modify it under the terms of EITHER:
17  (1) The GNU Lesser General Public License as published by the Free
18  Software Foundation; either version 2.1 of the License, or (at
19  your option) any later version. The text of the GNU Lesser
20  General Public License is included with this library in the
21  file GIMPACT-LICENSE-LGPL.TXT.
22  (2) The BSD-style license that is included with this library in
23  the file GIMPACT-LICENSE-BSD.TXT.
24  (3) The zlib/libpng license that is included with this library in
25  the file GIMPACT-LICENSE-ZLIB.TXT.
26 
27  This library is distributed in the hope that it will be useful,
28  but WITHOUT ANY WARRANTY; without even the implied warranty of
29  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
30  GIMPACT-LICENSE-LGPL.TXT, GIMPACT-LICENSE-ZLIB.TXT and GIMPACT-LICENSE-BSD.TXT for more details.
31 
32 -----------------------------------------------------------------------------
33 */
34 
35 #include "LinearMath/btScalar.h"
36 
37 #define GREAL btScalar
38 #define GREAL2 double
39 #define GINT int
40 #define GUINT unsigned int
41 #define GSHORT short
42 #define GUSHORT unsigned short
43 #define GINT64 long long
44 #define GUINT64 unsigned long long
45 
46 #define G_PI 3.14159265358979f
47 #define G_HALF_PI 1.5707963f
48 //267948966
49 #define G_TWO_PI 6.28318530f
50 //71795864
51 #define G_ROOT3 1.73205f
52 #define G_ROOT2 1.41421f
53 #define G_UINT_INFINITY 0xffffffff
54 #define G_REAL_INFINITY FLT_MAX
55 #define G_SIGN_BITMASK 0x80000000
56 #define G_EPSILON SIMD_EPSILON
57 
59 {
68 };
69 
70 #define G_DEGTORAD(X) ((X)*3.1415926f / 180.0f)
71 #define G_RADTODEG(X) ((X)*180.0f / 3.1415926f)
72 
74 #define GIM_IR(x) ((GUINT&)(x))
75 
77 #define GIM_SIR(x) ((GINT&)(x))
78 
80 #define GIM_AIR(x) (GIM_IR(x) & 0x7fffffff)
81 
83 #define GIM_FR(x) ((GREAL&)(x))
84 
85 #define GIM_MAX(a, b) (a < b ? b : a)
86 #define GIM_MIN(a, b) (a > b ? b : a)
87 
88 #define GIM_MAX3(a, b, c) GIM_MAX(a, GIM_MAX(b, c))
89 #define GIM_MIN3(a, b, c) GIM_MIN(a, GIM_MIN(b, c))
90 
91 #define GIM_IS_ZERO(value) (value < G_EPSILON && value > -G_EPSILON)
92 
93 #define GIM_IS_NEGATIVE(value) (value <= -G_EPSILON)
94 
95 #define GIM_IS_POSISITVE(value) (value >= G_EPSILON)
96 
97 #define GIM_NEAR_EQUAL(v1, v2) GIM_IS_ZERO((v1 - v2))
98 
100 #define GIM_CLAMP(number, minval, maxval) (number < minval ? minval : (number > maxval ? maxval : number))
101 
102 #define GIM_GREATER(x, y) btFabs(x) > (y)
103 
105 #define GIM_SWAP_NUMBERS(a, b) \
106  { \
107  a = a + b; \
108  b = a - b; \
109  a = a - b; \
110  }
111 
112 #define GIM_INV_SQRT(va, isva) \
113  { \
114  if (va <= 0.0000001f) \
115  { \
116  isva = G_REAL_INFINITY; \
117  } \
118  else \
119  { \
120  GREAL _x = va * 0.5f; \
121  GUINT _y = 0x5f3759df - (GIM_IR(va) >> 1); \
122  isva = GIM_FR(_y); \
123  isva = isva * (1.5f - (_x * isva * isva)); \
124  } \
125  }
126 
127 #define GIM_SQRT(va, sva) \
128  { \
129  GIM_INV_SQRT(va, sva); \
130  sva = 1.0f / sva; \
131  }
132 
135 {
136  GREAL r;
137  GIM_INV_SQRT(f, r);
138  return r;
139 }
140 
142 {
143  GREAL r;
144  GIM_SQRT(f, r);
145  return r;
146 }
147 
148 #endif // GIM_MATH_H_INCLUDED
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
GREAL gim_sqrt(GREAL f)
Definition: gim_math.h:141
#define GREAL
Definition: gim_math.h:37
GIM_SCALAR_TYPES
Definition: gim_math.h:59
@ G_STYPE_SHORT
Definition: gim_math.h:62
@ G_STYPE_INT
Definition: gim_math.h:64
@ G_STYPE_USHORT
Definition: gim_math.h:63
@ G_STYPE_UINT64
Definition: gim_math.h:67
@ G_STYPE_REAL
Definition: gim_math.h:60
@ G_STYPE_INT64
Definition: gim_math.h:66
@ G_STYPE_REAL2
Definition: gim_math.h:61
@ G_STYPE_UINT
Definition: gim_math.h:65
GREAL gim_inv_sqrt(GREAL f)
Computes 1.0f / sqrtf(x). Comes from Quake3. See http://www.magic-software.com/3DGEDInvSqrt....
Definition: gim_math.h:134
#define GIM_SQRT(va, sva)
Definition: gim_math.h:127
#define GIM_INV_SQRT(va, isva)
Definition: gim_math.h:112