Bullet Collision Detection & Physics Library
|
Go to the documentation of this file.
18 #ifdef BT_MANAGED_CODE
28 #define BT_BULLET_VERSION 288
47 #define BT_NOT_EMPTY_FILE_CAT_II(p, res) res
48 #define BT_NOT_EMPTY_FILE_CAT_I(a, b) BT_NOT_EMPTY_FILE_CAT_II(~, a##b)
49 #define BT_NOT_EMPTY_FILE_CAT(a, b) BT_NOT_EMPTY_FILE_CAT_I(a, b)
50 #define BT_NOT_EMPTY_FILE \
53 char BT_NOT_EMPTY_FILE_CAT(NoEmptyFileDummy, __COUNTER__); \
56 #define BT_NOT_EMPTY_FILE
61 #if defined(DEBUG) || defined (_DEBUG)
66 #if defined(__MINGW32__) || defined(__CYGWIN__) || (defined (_MSC_VER) && _MSC_VER < 1300)
67 #define SIMD_FORCE_INLINE inline
68 #define ATTRIBUTE_ALIGNED16(a) a
69 #define ATTRIBUTE_ALIGNED64(a) a
70 #define ATTRIBUTE_ALIGNED128(a) a
72 #define SIMD_FORCE_INLINE __forceinline
73 #define ATTRIBUTE_ALIGNED16(a) __declspec() a
74 #define ATTRIBUTE_ALIGNED64(a) __declspec() a
75 #define ATTRIBUTE_ALIGNED128(a) __declspec () a
78 #pragma warning(disable : 4324) // disable padding warning
80 #pragma warning(disable:4996) //Turn off warnings about deprecated C routines
83 #define SIMD_FORCE_INLINE __forceinline
84 #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
85 #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a
86 #define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a
90 #include <ppcintrinsics.h>
91 #define BT_HAVE_NATIVE_FSEL
92 #define btFsel(a,b,c) __fsel((a),(b),(c))
97 #elif (defined (_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))
99 #define BT_USE_SIMD_VECTOR3
105 #if (_MSC_FULL_VER >= 170050727)//Visual Studio 2012 can compile SSE4/FMA3 (but SSE4/FMA3 is not enabled by default)
106 #define BT_ALLOW_SSE4
107 #endif //(_MSC_FULL_VER >= 160040219)
117 #include <emmintrin.h>
127 #define btAssert(x) { if(!(x)){printf("Assert "__FILE__ ":%u (%s)\n", __LINE__, #x);__debugbreak(); }}
130 #define btAssert assert
136 #define btFullAssert(x)
138 #define btLikely(_c) _c
139 #define btUnlikely(_c) _c
143 #if defined (__CELLOS_LV2__)
144 #define SIMD_FORCE_INLINE inline __attribute__((always_inline))
145 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
146 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
147 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
153 #include <spu_printf.h>
154 #define printf spu_printf
155 #define btAssert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
157 #define btAssert assert
164 #define btFullAssert(x)
166 #define btLikely(_c) _c
167 #define btUnlikely(_c) _c
169 #else//defined (__CELLOS_LV2__)
173 #define SIMD_FORCE_INLINE __inline
174 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
175 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
176 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
181 #define btAssert assert
186 #define btFullAssert(x)
189 #define btLikely(_c) __builtin_expect((_c), 1)
190 #define btUnlikely(_c) __builtin_expect((_c), 0)
196 #if (defined (__APPLE__) && (!defined (BT_USE_DOUBLE_PRECISION)))
197 #if defined (__i386__) || defined (__x86_64__)
198 #define BT_USE_SIMD_VECTOR3
202 #define BT_USE_SSE_IN_API
205 #if defined (__SSE4_1__)
206 #include <smmintrin.h>
207 #elif defined (__SSSE3__)
208 #include <tmmintrin.h>
209 #elif defined (__SSE3__)
210 #include <pmmintrin.h>
212 #include <emmintrin.h>
215 #elif defined( __ARM_NEON__ )
217 #define BT_USE_NEON 1
218 #define BT_USE_SIMD_VECTOR3
220 #if defined BT_USE_NEON && defined (__clang__)
221 #include <arm_neon.h>
226 #define SIMD_FORCE_INLINE inline __attribute__ ((always_inline))
227 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
229 #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
230 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
235 #if defined(DEBUG) || defined (_DEBUG)
236 #if defined (__i386__) || defined (__x86_64__)
242 printf("Assert %s in line %d, file %s\n",#x, __LINE__, __FILE__);\
243 asm volatile ("int3");\
246 #else//defined (__i386__) || defined (__x86_64__)
247 #define btAssert assert
248 #endif//defined (__i386__) || defined (__x86_64__)
249 #else//defined(DEBUG) || defined (_DEBUG)
251 #endif//defined(DEBUG) || defined (_DEBUG)
254 #define btFullAssert(x)
255 #define btLikely(_c) _c
256 #define btUnlikely(_c) _c
260 #define SIMD_FORCE_INLINE inline
261 #define ATTRIBUTE_ALIGNED16(a) a
266 #define ATTRIBUTE_ALIGNED64(a) a
267 #define ATTRIBUTE_ALIGNED128(a) a
272 #if defined(DEBUG) || defined (_DEBUG)
273 #define btAssert assert
279 #define btFullAssert(x)
280 #define btLikely(_c) _c
281 #define btUnlikely(_c) _c
284 #endif //__CELLOS_LV2__
289 #if defined(BT_USE_DOUBLE_PRECISION)
292 #define BT_LARGE_FLOAT 1e30
296 #define BT_LARGE_FLOAT 1e18f
300 typedef __m128 btSimdFloat4;
303 #if defined(BT_USE_SSE)
308 static int btNanMask = 0x7F800001;
309 #define BT_NAN (*(float *)&btNanMask)
314 #define BT_INFINITY (*(float *)&btInfinityMask)
324 #ifndef BT_NO_SIMD_OPERATOR_OVERLOADS
325 inline __m128
operator+(
const __m128 A,
const __m128 B)
327 return _mm_add_ps(A, B);
330 inline __m128
operator-(
const __m128 A,
const __m128 B)
332 return _mm_sub_ps(A, B);
335 inline __m128
operator*(
const __m128 A,
const __m128 B)
337 return _mm_mul_ps(A, B);
339 #endif //BT_NO_SIMD_OPERATOR_OVERLOADS
341 #define btCastfTo128i(a) (_mm_castps_si128(a))
342 #define btCastfTo128d(a) (_mm_castps_pd(a))
343 #define btCastiTo128f(a) (_mm_castsi128_ps(a))
344 #define btCastdTo128f(a) (_mm_castpd_ps(a))
345 #define btCastdTo128i(a) (_mm_castpd_si128(a))
346 #define btAssign128(r0, r1, r2, r3) _mm_setr_ps(r0, r1, r2, r3)
350 #define btCastfTo128i(a) ((__m128i)(a))
351 #define btCastfTo128d(a) ((__m128d)(a))
352 #define btCastiTo128f(a) ((__m128)(a))
353 #define btCastdTo128f(a) ((__m128)(a))
354 #define btCastdTo128i(a) ((__m128i)(a))
355 #define btAssign128(r0, r1, r2, r3) \
356 (__m128) { r0, r1, r2, r3 }
357 #define BT_INFINITY INFINITY
363 #include <arm_neon.h>
365 typedef float32x4_t btSimdFloat4;
366 #define BT_INFINITY INFINITY
368 #define btAssign128(r0, r1, r2, r3) \
369 (float32x4_t) { r0, r1, r2, r3 }
385 #define BT_INFINITY (btInfinityMask.mask)
396 #include <arm_neon.h>
398 typedef float32x4_t btSimdFloat4;
399 #define BT_INFINITY INFINITY
401 #define btAssign128(r0, r1, r2, r3) \
402 (float32x4_t) { r0, r1, r2, r3 }
405 #define BT_DECLARE_ALIGNED_ALLOCATOR() \
406 SIMD_FORCE_INLINE void *operator new(size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes, 16); } \
407 SIMD_FORCE_INLINE void operator delete(void *ptr) { btAlignedFree(ptr); } \
408 SIMD_FORCE_INLINE void *operator new(size_t, void *ptr) { return ptr; } \
409 SIMD_FORCE_INLINE void operator delete(void *, void *) {} \
410 SIMD_FORCE_INLINE void *operator new[](size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes, 16); } \
411 SIMD_FORCE_INLINE void operator delete[](void *ptr) { btAlignedFree(ptr); } \
412 SIMD_FORCE_INLINE void *operator new[](size_t, void *ptr) { return ptr; } \
413 SIMD_FORCE_INLINE void operator delete[](void *, void *) {}
415 #if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS)
444 #else//BT_USE_DOUBLE_PRECISION
448 #ifdef USE_APPROXIMATION
450 float xhalf = 0.5f * y;
452 i = 0x5f375a86 - (i >> 1);
454 y = y * (1.5f - xhalf * y * y);
455 y = y * (1.5f - xhalf * y * y);
456 y = y * (1.5f - xhalf * y * y);
461 unsigned long *tfptr = ((
unsigned long *)&tempf) + 1;
463 *tfptr = (0xbfcdd90a - *tfptr) >> 1;
466 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
467 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
468 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
469 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
470 x = (
btScalar(1.5) * x) - (x * x) * (x * z);
504 #endif//BT_USE_DOUBLE_PRECISION
506 #define SIMD_PI btScalar(3.1415926535897932384626433832795029)
507 #define SIMD_2_PI (btScalar(2.0) * SIMD_PI)
508 #define SIMD_HALF_PI (SIMD_PI * btScalar(0.5))
509 #define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0))
510 #define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI)
511 #define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490)
512 #define btRecipSqrt(x) ((btScalar)(btScalar(1.0) / btSqrt(btScalar(x))))
513 #define btRecip(x) (btScalar(1.0) / btScalar(x))
515 #ifdef BT_USE_DOUBLE_PRECISION
516 #define SIMD_EPSILON DBL_EPSILON
517 #define SIMD_INFINITY DBL_MAX
523 #define SIMD_EPSILON FLT_EPSILON
524 #define SIMD_INFINITY FLT_MAX
541 btScalar r = (x - abs_y) / (x + abs_y);
542 angle = coeff_1 - coeff_1 * r;
546 btScalar r = (x + abs_y) / (abs_y - x);
547 angle = coeff_2 - coeff_1 * r;
549 return (y < 0.0f) ? -angle : angle;
556 return (((a) <= eps) && !((a) < -eps));
560 return (!((a) <= eps));
571 #define BT_DECLARE_HANDLE(name) \
572 typedef struct name##__ \
580 return a >= 0 ? b : c;
583 #define btFsels(a, b, c) (btScalar) btFsel(a, b, c)
588 const char *p = (
const char *)&i;
603 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
604 unsigned testEqz = ~testNz;
605 return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
609 unsigned testNz = (unsigned)(((
int)condition | -(
int)condition) >> 31);
610 unsigned testEqz = ~testNz;
611 return static_cast<int>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
615 #ifdef BT_HAVE_NATIVE_FSEL
616 return (
float)
btFsel((
btScalar)condition -
btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
618 return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
622 template <
typename T>
633 return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
638 return static_cast<unsigned short>(((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
660 unsigned char *dst = (
unsigned char *)&a;
661 unsigned char *src = (
unsigned char *)&d;
674 unsigned char *src = (
unsigned char *)&a;
675 unsigned char *dst = (
unsigned char *)&d;
688 unsigned char *src = (
unsigned char *)&d;
704 unsigned char *dst = (
unsigned char *)&d;
718 template <
typename T>
768 else if (angleInRadians >
SIMD_PI)
774 return angleInRadians;
793 template <
typename T>
796 struct btConvertPointerSizeT
803 btConvertPointerSizeT converter;
805 const size_t bit_mask = ~(alignment - 1);
806 converter.ptr = unalignedPtr;
807 converter.integer += alignment - 1;
808 converter.integer &= bit_mask;
809 return converter.ptr;
double btUnswapEndianDouble(const unsigned char *src)
unsigned int btSwapEndianFloat(float d)
btSwapFloat uses using char pointers to swap the endianness
btScalar btLog(btScalar x)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
btScalar btTan(btScalar x)
btMatrix3x3 operator*(const btMatrix3x3 &m, const btScalar &k)
T * btAlignPointer(T *unalignedPtr, size_t alignment)
align a pointer to the provided alignment, upwards
#define SIMD_RADS_PER_DEG
btScalar btAcos(btScalar x)
bool btGreaterEqual(btScalar a, btScalar eps)
int getObjectType() const
btScalar btLargeDot(const btScalar *a, const btScalar *b, int n)
static btInfMaskConverter btInfinityMask
#define SIMD_DEGS_PER_RAD
btScalar btSin(btScalar x)
btScalar btFabs(btScalar x)
btInfMaskConverter(int _mask=0x7F800000)
btTypedObject(int objectType)
btScalar btNormalizeAngle(btScalar angleInRadians)
btScalar btRadians(btScalar x)
btMatrix3x3 operator+(const btMatrix3x3 &m1, const btMatrix3x3 &m2)
btScalar btCos(btScalar x)
unsigned btSwapEndian(unsigned val)
unsigned btSelect(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero)
btSelect avoids branches, which makes performance much better for consoles like Playstation 3 and XBo...
btScalar btExp(btScalar x)
void btSwapEndianDouble(double d, unsigned char *dst)
bool btFuzzyZero(btScalar x)
btScalar btDegrees(btScalar x)
bool btEqual(btScalar a, btScalar eps)
#define SIMD_FORCE_INLINE
btScalar btFsel(btScalar a, btScalar b, btScalar c)
int btIsNegative(btScalar x)
float btUnswapEndianFloat(unsigned int a)
void btSetZero(T *a, int n)
rudimentary class to provide type info
btMatrix3x3 operator-(const btMatrix3x3 &m1, const btMatrix3x3 &m2)
btScalar btAtan2(btScalar x, btScalar y)
#define BT_BULLET_VERSION
btScalar btAtan2Fast(btScalar y, btScalar x)
btScalar btSqrt(btScalar y)
btScalar btPow(btScalar x, btScalar y)
btScalar btAtan(btScalar x)
btScalar btFmod(btScalar x, btScalar y)
static T sum(const btAlignedObjectArray< T > &items)
btScalar btAsin(btScalar x)
bool btMachineIsLittleEndian()