btScalar.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*
  2. Copyright (c) 2003-2009 Erwin Coumans http://bullet.googlecode.com
  3. This software is provided 'as-is', without any express or implied warranty.
  4. In no event will the authors be held liable for any damages arising from the use of this software.
  5. Permission is granted to anyone to use this software for any purpose,
  6. including commercial applications, and to alter it and redistribute it freely,
  7. subject to the following restrictions:
  8. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  9. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  10. 3. This notice may not be removed or altered from any source distribution.
  11. */
  12. #ifndef BT_SCALAR_H
  13. #define BT_SCALAR_H
  14. #ifdef BT_MANAGED_CODE
  15. //Aligned data types not supported in managed code
  16. #pragma unmanaged
  17. #endif
  18. #include <float.h>
  19. #include <math.h>
  20. #include <stdlib.h> //size_t for MSVC 6.0
  21. #include <stdint.h>
  22. /* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/
  23. #define BT_BULLET_VERSION 279
  24. // -- GODOT start --
  25. namespace VHACD {
  26. // -- GODOT end --
  27. inline int32_t btGetVersion()
  28. {
  29. return BT_BULLET_VERSION;
  30. }
  31. // -- GODOT start --
  32. }; // namespace VHACD
  33. // -- GODOT end --
  34. #if defined(DEBUG) || defined(_DEBUG)
  35. #define BT_DEBUG
  36. #endif
  37. #ifdef _WIN32
  38. #if defined(__MINGW32__) || defined(__CYGWIN__) || (defined(_MSC_VER) && _MSC_VER < 1300)
  39. #define SIMD_FORCE_INLINE inline
  40. #define ATTRIBUTE_ALIGNED16(a) a
  41. #define ATTRIBUTE_ALIGNED64(a) a
  42. #define ATTRIBUTE_ALIGNED128(a) a
  43. #else
  44. //#define BT_HAS_ALIGNED_ALLOCATOR
  45. #pragma warning(disable : 4324) // disable padding warning
  46. // #pragma warning(disable:4530) // Disable the exception disable but used in MSCV Stl warning.
  47. // #pragma warning(disable:4996) //Turn off warnings about deprecated C routines
  48. // #pragma warning(disable:4786) // Disable the "debug name too long" warning
  49. #define SIMD_FORCE_INLINE __forceinline
  50. #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
  51. #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a
  52. #define ATTRIBUTE_ALIGNED128(a) __declspec(align(128)) a
  53. #ifdef _XBOX
  54. #define BT_USE_VMX128
  55. #include <ppcintrinsics.h>
  56. #define BT_HAVE_NATIVE_FSEL
  57. #define btFsel(a, b, c) __fsel((a), (b), (c))
  58. #else
  59. // -- GODOT start --
  60. //#if (defined(_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined(BT_USE_DOUBLE_PRECISION))
  61. #if (defined(_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined(BT_USE_DOUBLE_PRECISION)) && (!defined(_M_ARM)) && (!defined(_M_ARM64))
  62. // -- GODOT end --
  63. #define BT_USE_SSE
  64. #include <emmintrin.h>
  65. #endif
  66. #endif //_XBOX
  67. #endif //__MINGW32__
  68. #include <assert.h>
  69. #ifdef BT_DEBUG
  70. #define btAssert assert
  71. #else
  72. #define btAssert(x)
  73. #endif
  74. //btFullAssert is optional, slows down a lot
  75. #define btFullAssert(x)
  76. #define btLikely(_c) _c
  77. #define btUnlikely(_c) _c
  78. #else
  79. #if defined(__CELLOS_LV2__)
  80. #define SIMD_FORCE_INLINE inline __attribute__((always_inline))
  81. #define ATTRIBUTE_ALIGNED16(a) a __attribute__((aligned(16)))
  82. #define ATTRIBUTE_ALIGNED64(a) a __attribute__((aligned(64)))
  83. #define ATTRIBUTE_ALIGNED128(a) a __attribute__((aligned(128)))
  84. #ifndef assert
  85. #include <assert.h>
  86. #endif
  87. #ifdef BT_DEBUG
  88. #ifdef __SPU__
  89. #include <spu_printf.h>
  90. #define printf spu_printf
  91. #define btAssert(x) \
  92. { \
  93. if (!(x)) { \
  94. printf("Assert " __FILE__ ":%u (" #x ")\n", __LINE__); \
  95. spu_hcmpeq(0, 0); \
  96. } \
  97. }
  98. #else
  99. #define btAssert assert
  100. #endif
  101. #else
  102. #define btAssert(x)
  103. #endif
  104. //btFullAssert is optional, slows down a lot
  105. #define btFullAssert(x)
  106. #define btLikely(_c) _c
  107. #define btUnlikely(_c) _c
  108. #else
  109. #ifdef USE_LIBSPE2
  110. #define SIMD_FORCE_INLINE __inline
  111. #define ATTRIBUTE_ALIGNED16(a) a __attribute__((aligned(16)))
  112. #define ATTRIBUTE_ALIGNED64(a) a __attribute__((aligned(64)))
  113. #define ATTRIBUTE_ALIGNED128(a) a __attribute__((aligned(128)))
  114. #ifndef assert
  115. #include <assert.h>
  116. #endif
  117. #ifdef BT_DEBUG
  118. #define btAssert assert
  119. #else
  120. #define btAssert(x)
  121. #endif
  122. //btFullAssert is optional, slows down a lot
  123. #define btFullAssert(x)
  124. #define btLikely(_c) __builtin_expect((_c), 1)
  125. #define btUnlikely(_c) __builtin_expect((_c), 0)
  126. #else
  127. //non-windows systems
  128. #if (defined(__APPLE__) && defined(__i386__) && (!defined(BT_USE_DOUBLE_PRECISION)))
  129. #define BT_USE_SSE
  130. #include <emmintrin.h>
  131. #define SIMD_FORCE_INLINE inline
  132. ///@todo: check out alignment methods for other platforms/compilers
  133. #define ATTRIBUTE_ALIGNED16(a) a __attribute__((aligned(16)))
  134. #define ATTRIBUTE_ALIGNED64(a) a __attribute__((aligned(64)))
  135. #define ATTRIBUTE_ALIGNED128(a) a __attribute__((aligned(128)))
  136. #ifndef assert
  137. #include <assert.h>
  138. #endif
  139. #if defined(DEBUG) || defined(_DEBUG)
  140. #define btAssert assert
  141. #else
  142. #define btAssert(x)
  143. #endif
  144. //btFullAssert is optional, slows down a lot
  145. #define btFullAssert(x)
  146. #define btLikely(_c) _c
  147. #define btUnlikely(_c) _c
  148. #else
  149. #define SIMD_FORCE_INLINE inline
  150. ///@todo: check out alignment methods for other platforms/compilers
  151. ///#define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
  152. ///#define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
  153. ///#define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
  154. #define ATTRIBUTE_ALIGNED16(a) a
  155. #define ATTRIBUTE_ALIGNED64(a) a
  156. #define ATTRIBUTE_ALIGNED128(a) a
  157. #ifndef assert
  158. #include <assert.h>
  159. #endif
  160. #if defined(DEBUG) || defined(_DEBUG)
  161. #define btAssert assert
  162. #else
  163. #define btAssert(x)
  164. #endif
  165. //btFullAssert is optional, slows down a lot
  166. #define btFullAssert(x)
  167. #define btLikely(_c) _c
  168. #define btUnlikely(_c) _c
  169. #endif //__APPLE__
  170. #endif // LIBSPE2
  171. #endif //__CELLOS_LV2__
  172. #endif
  173. // -- GODOT start --
  174. namespace VHACD {
  175. // -- GODOT end --
  176. ///The btScalar type abstracts floating point numbers, to easily switch between double and single floating point precision.
  177. #if defined(BT_USE_DOUBLE_PRECISION)
  178. typedef double btScalar;
  179. //this number could be bigger in double precision
  180. #define BT_LARGE_FLOAT 1e30
  181. #else
  182. typedef float btScalar;
  183. //keep BT_LARGE_FLOAT*BT_LARGE_FLOAT < FLT_MAX
  184. #define BT_LARGE_FLOAT 1e18f
  185. #endif
  186. #define BT_DECLARE_ALIGNED_ALLOCATOR() \
  187. SIMD_FORCE_INLINE void* operator new(size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes, 16); } \
  188. SIMD_FORCE_INLINE void operator delete(void* ptr) { btAlignedFree(ptr); } \
  189. SIMD_FORCE_INLINE void* operator new(size_t, void* ptr) { return ptr; } \
  190. SIMD_FORCE_INLINE void operator delete(void*, void*) {} \
  191. SIMD_FORCE_INLINE void* operator new[](size_t sizeInBytes) { return btAlignedAlloc(sizeInBytes, 16); } \
  192. SIMD_FORCE_INLINE void operator delete[](void* ptr) { btAlignedFree(ptr); } \
  193. SIMD_FORCE_INLINE void* operator new[](size_t, void* ptr) { return ptr; } \
  194. SIMD_FORCE_INLINE void operator delete[](void*, void*) {}
  195. #if defined(BT_USE_DOUBLE_PRECISION) || defined(BT_FORCE_DOUBLE_FUNCTIONS)
  196. SIMD_FORCE_INLINE btScalar btSqrt(btScalar x)
  197. {
  198. return sqrt(x);
  199. }
  200. SIMD_FORCE_INLINE btScalar btFabs(btScalar x) { return fabs(x); }
  201. SIMD_FORCE_INLINE btScalar btCos(btScalar x) { return cos(x); }
  202. SIMD_FORCE_INLINE btScalar btSin(btScalar x) { return sin(x); }
  203. SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tan(x); }
  204. SIMD_FORCE_INLINE btScalar btAcos(btScalar x)
  205. {
  206. if (x < btScalar(-1))
  207. x = btScalar(-1);
  208. if (x > btScalar(1))
  209. x = btScalar(1);
  210. return acos(x);
  211. }
  212. SIMD_FORCE_INLINE btScalar btAsin(btScalar x)
  213. {
  214. if (x < btScalar(-1))
  215. x = btScalar(-1);
  216. if (x > btScalar(1))
  217. x = btScalar(1);
  218. return asin(x);
  219. }
  220. SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atan(x); }
  221. SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2(x, y); }
  222. SIMD_FORCE_INLINE btScalar btExp(btScalar x) { return exp(x); }
  223. SIMD_FORCE_INLINE btScalar btLog(btScalar x) { return log(x); }
  224. SIMD_FORCE_INLINE btScalar btPow(btScalar x, btScalar y) { return pow(x, y); }
  225. SIMD_FORCE_INLINE btScalar btFmod(btScalar x, btScalar y) { return fmod(x, y); }
  226. #else
  227. SIMD_FORCE_INLINE btScalar btSqrt(btScalar y)
  228. {
  229. #ifdef USE_APPROXIMATION
  230. double x, z, tempf;
  231. unsigned long* tfptr = ((unsigned long*)&tempf) + 1;
  232. tempf = y;
  233. *tfptr = (0xbfcdd90a - *tfptr) >> 1; /* estimate of 1/sqrt(y) */
  234. x = tempf;
  235. z = y * btScalar(0.5);
  236. x = (btScalar(1.5) * x) - (x * x) * (x * z); /* iteration formula */
  237. x = (btScalar(1.5) * x) - (x * x) * (x * z);
  238. x = (btScalar(1.5) * x) - (x * x) * (x * z);
  239. x = (btScalar(1.5) * x) - (x * x) * (x * z);
  240. x = (btScalar(1.5) * x) - (x * x) * (x * z);
  241. return x * y;
  242. #else
  243. return sqrtf(y);
  244. #endif
  245. }
  246. SIMD_FORCE_INLINE btScalar btFabs(btScalar x) { return fabsf(x); }
  247. SIMD_FORCE_INLINE btScalar btCos(btScalar x) { return cosf(x); }
  248. SIMD_FORCE_INLINE btScalar btSin(btScalar x) { return sinf(x); }
  249. SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tanf(x); }
  250. SIMD_FORCE_INLINE btScalar btAcos(btScalar x)
  251. {
  252. if (x < btScalar(-1))
  253. x = btScalar(-1);
  254. if (x > btScalar(1))
  255. x = btScalar(1);
  256. return acosf(x);
  257. }
  258. SIMD_FORCE_INLINE btScalar btAsin(btScalar x)
  259. {
  260. if (x < btScalar(-1))
  261. x = btScalar(-1);
  262. if (x > btScalar(1))
  263. x = btScalar(1);
  264. return asinf(x);
  265. }
  266. SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atanf(x); }
  267. SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2f(x, y); }
  268. SIMD_FORCE_INLINE btScalar btExp(btScalar x) { return expf(x); }
  269. SIMD_FORCE_INLINE btScalar btLog(btScalar x) { return logf(x); }
  270. SIMD_FORCE_INLINE btScalar btPow(btScalar x, btScalar y) { return powf(x, y); }
  271. SIMD_FORCE_INLINE btScalar btFmod(btScalar x, btScalar y) { return fmodf(x, y); }
  272. #endif
  273. #define SIMD_2_PI btScalar(6.283185307179586232)
  274. #define SIMD_PI (SIMD_2_PI * btScalar(0.5))
  275. #define SIMD_HALF_PI (SIMD_2_PI * btScalar(0.25))
  276. #define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0))
  277. #define SIMD_DEGS_PER_RAD (btScalar(360.0) / SIMD_2_PI)
  278. #define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490)
  279. #define btRecipSqrt(x) ((btScalar)(btScalar(1.0) / btSqrt(btScalar(x)))) /* reciprocal square root */
  280. #ifdef BT_USE_DOUBLE_PRECISION
  281. #define SIMD_EPSILON DBL_EPSILON
  282. #define SIMD_INFINITY DBL_MAX
  283. #else
  284. #define SIMD_EPSILON FLT_EPSILON
  285. #define SIMD_INFINITY FLT_MAX
  286. #endif
  287. SIMD_FORCE_INLINE btScalar btAtan2Fast(btScalar y, btScalar x)
  288. {
  289. btScalar coeff_1 = SIMD_PI / 4.0f;
  290. btScalar coeff_2 = 3.0f * coeff_1;
  291. btScalar abs_y = btFabs(y);
  292. btScalar angle;
  293. if (x >= 0.0f) {
  294. btScalar r = (x - abs_y) / (x + abs_y);
  295. angle = coeff_1 - coeff_1 * r;
  296. }
  297. else {
  298. btScalar r = (x + abs_y) / (abs_y - x);
  299. angle = coeff_2 - coeff_1 * r;
  300. }
  301. return (y < 0.0f) ? -angle : angle;
  302. }
  303. SIMD_FORCE_INLINE bool btFuzzyZero(btScalar x) { return btFabs(x) < SIMD_EPSILON; }
  304. SIMD_FORCE_INLINE bool btEqual(btScalar a, btScalar eps)
  305. {
  306. return (((a) <= eps) && !((a) < -eps));
  307. }
  308. SIMD_FORCE_INLINE bool btGreaterEqual(btScalar a, btScalar eps)
  309. {
  310. return (!((a) <= eps));
  311. }
  312. SIMD_FORCE_INLINE int32_t btIsNegative(btScalar x)
  313. {
  314. return x < btScalar(0.0) ? 1 : 0;
  315. }
  316. SIMD_FORCE_INLINE btScalar btRadians(btScalar x) { return x * SIMD_RADS_PER_DEG; }
  317. SIMD_FORCE_INLINE btScalar btDegrees(btScalar x) { return x * SIMD_DEGS_PER_RAD; }
  318. #define BT_DECLARE_HANDLE(name) \
  319. typedef struct name##__ { \
  320. int32_t unused; \
  321. } * name
  322. #ifndef btFsel
  323. SIMD_FORCE_INLINE btScalar btFsel(btScalar a, btScalar b, btScalar c)
  324. {
  325. return a >= 0 ? b : c;
  326. }
  327. #endif
  328. #define btFsels(a, b, c) (btScalar) btFsel(a, b, c)
  329. SIMD_FORCE_INLINE bool btMachineIsLittleEndian()
  330. {
  331. long int i = 1;
  332. const char* p = (const char*)&i;
  333. if (p[0] == 1) // Lowest address contains the least significant byte
  334. return true;
  335. else
  336. return false;
  337. }
  338. ///btSelect avoids branches, which makes performance much better for consoles like Playstation 3 and XBox 360
  339. ///Thanks Phil Knight. See also http://www.cellperformance.com/articles/2006/04/more_techniques_for_eliminatin_1.html
  340. SIMD_FORCE_INLINE unsigned btSelect(unsigned condition, unsigned valueIfConditionNonZero, unsigned valueIfConditionZero)
  341. {
  342. // Set testNz to 0xFFFFFFFF if condition is nonzero, 0x00000000 if condition is zero
  343. // Rely on positive value or'ed with its negative having sign bit on
  344. // and zero value or'ed with its negative (which is still zero) having sign bit off
  345. // Use arithmetic shift right, shifting the sign bit through all 32 bits
  346. unsigned testNz = (unsigned)(((int32_t)condition | -(int32_t)condition) >> 31);
  347. unsigned testEqz = ~testNz;
  348. return ((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
  349. }
  350. SIMD_FORCE_INLINE int32_t btSelect(unsigned condition, int32_t valueIfConditionNonZero, int32_t valueIfConditionZero)
  351. {
  352. unsigned testNz = (unsigned)(((int32_t)condition | -(int32_t)condition) >> 31);
  353. unsigned testEqz = ~testNz;
  354. return static_cast<int32_t>((valueIfConditionNonZero & testNz) | (valueIfConditionZero & testEqz));
  355. }
  356. SIMD_FORCE_INLINE float btSelect(unsigned condition, float valueIfConditionNonZero, float valueIfConditionZero)
  357. {
  358. #ifdef BT_HAVE_NATIVE_FSEL
  359. return (float)btFsel((btScalar)condition - btScalar(1.0f), valueIfConditionNonZero, valueIfConditionZero);
  360. #else
  361. return (condition != 0) ? valueIfConditionNonZero : valueIfConditionZero;
  362. #endif
  363. }
  364. template <typename T>
  365. SIMD_FORCE_INLINE void btSwap(T& a, T& b)
  366. {
  367. T tmp = a;
  368. a = b;
  369. b = tmp;
  370. }
  371. //PCK: endian swapping functions
  372. SIMD_FORCE_INLINE unsigned btSwapEndian(unsigned val)
  373. {
  374. return (((val & 0xff000000) >> 24) | ((val & 0x00ff0000) >> 8) | ((val & 0x0000ff00) << 8) | ((val & 0x000000ff) << 24));
  375. }
  376. SIMD_FORCE_INLINE unsigned short btSwapEndian(unsigned short val)
  377. {
  378. return static_cast<unsigned short>(((val & 0xff00) >> 8) | ((val & 0x00ff) << 8));
  379. }
  380. SIMD_FORCE_INLINE unsigned btSwapEndian(int32_t val)
  381. {
  382. return btSwapEndian((unsigned)val);
  383. }
  384. SIMD_FORCE_INLINE unsigned short btSwapEndian(short val)
  385. {
  386. return btSwapEndian((unsigned short)val);
  387. }
  388. ///btSwapFloat uses using char pointers to swap the endianness
  389. ////btSwapFloat/btSwapDouble will NOT return a float, because the machine might 'correct' invalid floating point values
  390. ///Not all values of sign/exponent/mantissa are valid floating point numbers according to IEEE 754.
  391. ///When a floating point unit is faced with an invalid value, it may actually change the value, or worse, throw an exception.
  392. ///In most systems, running user mode code, you wouldn't get an exception, but instead the hardware/os/runtime will 'fix' the number for you.
  393. ///so instead of returning a float/double, we return integer/long long integer
  394. SIMD_FORCE_INLINE uint32_t btSwapEndianFloat(float d)
  395. {
  396. uint32_t a = 0;
  397. unsigned char* dst = (unsigned char*)&a;
  398. unsigned char* src = (unsigned char*)&d;
  399. dst[0] = src[3];
  400. dst[1] = src[2];
  401. dst[2] = src[1];
  402. dst[3] = src[0];
  403. return a;
  404. }
  405. // unswap using char pointers
  406. SIMD_FORCE_INLINE float btUnswapEndianFloat(uint32_t a)
  407. {
  408. float d = 0.0f;
  409. unsigned char* src = (unsigned char*)&a;
  410. unsigned char* dst = (unsigned char*)&d;
  411. dst[0] = src[3];
  412. dst[1] = src[2];
  413. dst[2] = src[1];
  414. dst[3] = src[0];
  415. return d;
  416. }
  417. // swap using char pointers
  418. SIMD_FORCE_INLINE void btSwapEndianDouble(double d, unsigned char* dst)
  419. {
  420. unsigned char* src = (unsigned char*)&d;
  421. dst[0] = src[7];
  422. dst[1] = src[6];
  423. dst[2] = src[5];
  424. dst[3] = src[4];
  425. dst[4] = src[3];
  426. dst[5] = src[2];
  427. dst[6] = src[1];
  428. dst[7] = src[0];
  429. }
  430. // unswap using char pointers
  431. SIMD_FORCE_INLINE double btUnswapEndianDouble(const unsigned char* src)
  432. {
  433. double d = 0.0;
  434. unsigned char* dst = (unsigned char*)&d;
  435. dst[0] = src[7];
  436. dst[1] = src[6];
  437. dst[2] = src[5];
  438. dst[3] = src[4];
  439. dst[4] = src[3];
  440. dst[5] = src[2];
  441. dst[6] = src[1];
  442. dst[7] = src[0];
  443. return d;
  444. }
  445. // returns normalized value in range [-SIMD_PI, SIMD_PI]
  446. SIMD_FORCE_INLINE btScalar btNormalizeAngle(btScalar angleInRadians)
  447. {
  448. angleInRadians = btFmod(angleInRadians, SIMD_2_PI);
  449. if (angleInRadians < -SIMD_PI) {
  450. return angleInRadians + SIMD_2_PI;
  451. }
  452. else if (angleInRadians > SIMD_PI) {
  453. return angleInRadians - SIMD_2_PI;
  454. }
  455. else {
  456. return angleInRadians;
  457. }
  458. }
  459. ///rudimentary class to provide type info
  460. struct btTypedObject {
  461. btTypedObject(int32_t objectType)
  462. : m_objectType(objectType)
  463. {
  464. }
  465. int32_t m_objectType;
  466. inline int32_t getObjectType() const
  467. {
  468. return m_objectType;
  469. }
  470. };
  471. // -- GODOT start --
  472. // Cherry-picked from Bullet 2.88 to fix GH-27926
  473. ///align a pointer to the provided alignment, upwards
  474. template <typename T>
  475. T *btAlignPointer(T *unalignedPtr, size_t alignment)
  476. {
  477. struct btConvertPointerSizeT
  478. {
  479. union {
  480. T *ptr;
  481. size_t integer;
  482. };
  483. };
  484. btConvertPointerSizeT converter;
  485. const size_t bit_mask = ~(alignment - 1);
  486. converter.ptr = unalignedPtr;
  487. converter.integer += alignment - 1;
  488. converter.integer &= bit_mask;
  489. return converter.ptr;
  490. }
  491. // -- GODOT end --
  492. // -- GODOT start --
  493. }; // namespace VHACD
  494. // -- GODOT end --
  495. #endif //BT_SCALAR_H