Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 21, 2011, 6:58:23 PM (14 years ago)
Author:
rgrieder
Message:

Merged revisions 7978 - 8096 from kicklib to kicklib2.

Location:
code/branches/kicklib2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib2

  • code/branches/kicklib2/src/external/bullet/LinearMath/btScalar.h

    r5781 r8284  
    11/*
    2 Copyright (c) 2003-2006 Gino van den Bergen / Erwin Coumans  http://continuousphysics.com/Bullet/
     2Copyright (c) 2003-2009 Erwin Coumans  http://bullet.googlecode.com
    33
    44This software is provided 'as-is', without any express or implied warranty.
     
    1818#define SIMD___SCALAR_H
    1919
     20#ifdef BT_MANAGED_CODE
     21//Aligned data types not supported in managed code
     22#pragma unmanaged
     23#endif
     24
     25
    2026#include <math.h>
    21 
    2227#include <stdlib.h>//size_t for MSVC 6.0
    23 
    2428#include <cstdlib>
    2529#include <cfloat>
    2630#include <float.h>
    2731
    28 #define BT_BULLET_VERSION 274
     32/* SVN $Revision$ on $Date$ from http://bullet.googlecode.com*/
     33#define BT_BULLET_VERSION 277
    2934
    3035inline int      btGetVersion()
     
    3843
    3944
    40 #ifdef WIN32
     45#ifdef _WIN32
    4146
    4247                #if defined(__MINGW32__) || defined(__CYGWIN__) || (defined (_MSC_VER) && _MSC_VER < 1300)
     
    4449                        #define SIMD_FORCE_INLINE inline
    4550                        #define ATTRIBUTE_ALIGNED16(a) a
     51                        #define ATTRIBUTE_ALIGNED64(a) a
    4652                        #define ATTRIBUTE_ALIGNED128(a) a
    4753                #else
     
    5460                        #define SIMD_FORCE_INLINE __forceinline
    5561                        #define ATTRIBUTE_ALIGNED16(a) __declspec(align(16)) a
     62                        #define ATTRIBUTE_ALIGNED64(a) __declspec(align(64)) a
    5663                        #define ATTRIBUTE_ALIGNED128(a) __declspec (align(128)) a
    5764                #ifdef _XBOX
     
    6370                #else
    6471
    65 #if (defined (WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))
     72#if (defined (_WIN32) && (_MSC_VER) && _MSC_VER >= 1400) && (!defined (BT_USE_DOUBLE_PRECISION))
    6673                        #define BT_USE_SSE
    6774                        #include <emmintrin.h>
     
    8794       
    8895#if defined     (__CELLOS_LV2__)
    89                 #define SIMD_FORCE_INLINE inline
     96                #define SIMD_FORCE_INLINE inline __attribute__((always_inline))
    9097                #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
     98                #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
     99                #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
     100                #ifndef assert
     101                #include <assert.h>
     102                #endif
     103#ifdef BT_DEBUG
     104#ifdef __SPU__
     105#include <spu_printf.h>
     106#define printf spu_printf
     107        #define btAssert(x) {if(!(x)){printf("Assert "__FILE__ ":%u ("#x")\n", __LINE__);spu_hcmpeq(0,0);}}
     108#else
     109        #define btAssert assert
     110#endif
     111       
     112#else
     113                #define btAssert(x)
     114#endif
     115                //btFullAssert is optional, slows down a lot
     116                #define btFullAssert(x)
     117
     118                #define btLikely(_c)  _c
     119                #define btUnlikely(_c) _c
     120
     121#else
     122
     123#ifdef USE_LIBSPE2
     124
     125                #define SIMD_FORCE_INLINE __inline
     126                #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
     127                #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
    91128                #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
    92129                #ifndef assert
     
    101138                #define btFullAssert(x)
    102139
    103                 #define btLikely(_c)  _c
    104                 #define btUnlikely(_c) _c
    105 
    106 #else
    107 
    108 #ifdef USE_LIBSPE2
    109 
    110                 #define SIMD_FORCE_INLINE __inline
    111                 #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
    112                 #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
    113                 #ifndef assert
    114                 #include <assert.h>
    115                 #endif
    116 #ifdef BT_DEBUG
    117                 #define btAssert assert
    118 #else
    119                 #define btAssert(x)
    120 #endif
    121                 //btFullAssert is optional, slows down a lot
    122                 #define btFullAssert(x)
    123 
    124140
    125141                #define btLikely(_c)   __builtin_expect((_c), 1)
     
    130146        //non-windows systems
    131147
     148#if (defined (__APPLE__) && defined (__i386__) && (!defined (BT_USE_DOUBLE_PRECISION)))
     149        #define BT_USE_SSE
     150        #include <emmintrin.h>
     151
     152        #define SIMD_FORCE_INLINE inline
     153///@todo: check out alignment methods for other platforms/compilers
     154        #define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
     155        #define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
     156        #define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
     157        #ifndef assert
     158        #include <assert.h>
     159        #endif
     160
     161        #if defined(DEBUG) || defined (_DEBUG)
     162                #define btAssert assert
     163        #else
     164                #define btAssert(x)
     165        #endif
     166
     167        //btFullAssert is optional, slows down a lot
     168        #define btFullAssert(x)
     169        #define btLikely(_c)  _c
     170        #define btUnlikely(_c) _c
     171
     172#else
     173
    132174                #define SIMD_FORCE_INLINE inline
    133175                ///@todo: check out alignment methods for other platforms/compilers
    134176                ///#define ATTRIBUTE_ALIGNED16(a) a __attribute__ ((aligned (16)))
     177                ///#define ATTRIBUTE_ALIGNED64(a) a __attribute__ ((aligned (64)))
    135178                ///#define ATTRIBUTE_ALIGNED128(a) a __attribute__ ((aligned (128)))
    136179                #define ATTRIBUTE_ALIGNED16(a) a
     180                #define ATTRIBUTE_ALIGNED64(a) a
    137181                #define ATTRIBUTE_ALIGNED128(a) a
    138182                #ifndef assert
     
    150194                #define btLikely(_c)  _c
    151195                #define btUnlikely(_c) _c
    152 
     196#endif //__APPLE__
    153197
    154198#endif // LIBSPE2
     
    157201#endif
    158202
    159 /// older compilers (gcc 3.x) and Sun needs double version of sqrt etc.
    160 /// exclude Apple Intel (i's assumed to be a Macbook or new Intel Dual Core Processor)
    161 #if defined (__sun) || defined (__sun__) || defined (__sparc) || (defined (__APPLE__) && ! defined (__i386__))
    162 //use slow double float precision operation on those platforms
    163 #ifndef BT_USE_DOUBLE_PRECISION
    164 #define BT_FORCE_DOUBLE_FUNCTIONS
    165 #endif
    166 #endif
    167203
    168204///The btScalar type abstracts floating point numbers, to easily switch between double and single floating point precision.
    169205#if defined(BT_USE_DOUBLE_PRECISION)
    170206typedef double btScalar;
     207//this number could be bigger in double precision
     208#define BT_LARGE_FLOAT 1e30
    171209#else
    172210typedef float btScalar;
     211//keep BT_LARGE_FLOAT*BT_LARGE_FLOAT < FLT_MAX
     212#define BT_LARGE_FLOAT 1e18f
    173213#endif
    174214
     
    194234SIMD_FORCE_INLINE btScalar btSin(btScalar x) { return sin(x); }
    195235SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tan(x); }
    196 SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { return acos(x); }
    197 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { return asin(x); }
     236SIMD_FORCE_INLINE btScalar btAcos(btScalar x) { if (x<btScalar(-1))     x=btScalar(-1); if (x>btScalar(1))      x=btScalar(1); return acos(x); }
     237SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { if (x<btScalar(-1))     x=btScalar(-1); if (x>btScalar(1))      x=btScalar(1); return asin(x); }
    198238SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atan(x); }
    199239SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2(x, y); }
     
    201241SIMD_FORCE_INLINE btScalar btLog(btScalar x) { return log(x); }
    202242SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return pow(x,y); }
     243SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmod(x,y); }
    203244
    204245#else
     
    213254        *tfptr = (0xbfcdd90a - *tfptr)>>1; /* estimate of 1/sqrt(y) */
    214255        x =  tempf;
    215         z =  y*btScalar(0.5);                        /* hoist out the “/2”    */
     256        z =  y*btScalar(0.5);
    216257        x = (btScalar(1.5)*x)-(x*x)*(x*z);         /* iteration formula     */
    217258        x = (btScalar(1.5)*x)-(x*x)*(x*z);
     
    229270SIMD_FORCE_INLINE btScalar btTan(btScalar x) { return tanf(x); }
    230271SIMD_FORCE_INLINE btScalar btAcos(btScalar x) {
    231         btAssert(x <= btScalar(1.));
     272        if (x<btScalar(-1))     
     273                x=btScalar(-1);
     274        if (x>btScalar(1))     
     275                x=btScalar(1);
    232276        return acosf(x);
    233277}
    234 SIMD_FORCE_INLINE btScalar btAsin(btScalar x) { return asinf(x); }
     278SIMD_FORCE_INLINE btScalar btAsin(btScalar x) {
     279        if (x<btScalar(-1))     
     280                x=btScalar(-1);
     281        if (x>btScalar(1))     
     282                x=btScalar(1);
     283        return asinf(x);
     284}
    235285SIMD_FORCE_INLINE btScalar btAtan(btScalar x) { return atanf(x); }
    236286SIMD_FORCE_INLINE btScalar btAtan2(btScalar x, btScalar y) { return atan2f(x, y); }
     
    242292  SIMD_FORCE_INLINE btScalar btPow(btScalar x,btScalar y) { return powf(x,y); }
    243293  #endif
     294SIMD_FORCE_INLINE btScalar btFmod(btScalar x,btScalar y) { return fmodf(x,y); }
    244295       
    245296#endif
     
    250301#define SIMD_RADS_PER_DEG (SIMD_2_PI / btScalar(360.0))
    251302#define SIMD_DEGS_PER_RAD  (btScalar(360.0) / SIMD_2_PI)
     303#define SIMDSQRT12 btScalar(0.7071067811865475244008443621048490)
     304
     305#define btRecipSqrt(x) ((btScalar)(btScalar(1.0)/btSqrt(btScalar(x))))          /* reciprocal square root */
     306
    252307
    253308#ifdef BT_USE_DOUBLE_PRECISION
     
    440495}
    441496
    442 
     497// returns normalized value in range [-SIMD_PI, SIMD_PI]
     498SIMD_FORCE_INLINE btScalar btNormalizeAngle(btScalar angleInRadians)
     499{
     500        angleInRadians = btFmod(angleInRadians, SIMD_2_PI);
     501        if(angleInRadians < -SIMD_PI)
     502        {
     503                return angleInRadians + SIMD_2_PI;
     504        }
     505        else if(angleInRadians > SIMD_PI)
     506        {
     507                return angleInRadians - SIMD_2_PI;
     508        }
     509        else
     510        {
     511                return angleInRadians;
     512        }
     513}
     514
     515///rudimentary class to provide type info
     516struct btTypedObject
     517{
     518        btTypedObject(int objectType)
     519                :m_objectType(objectType)
     520        {
     521        }
     522        int     m_objectType;
     523        inline int getObjectType() const
     524        {
     525                return m_objectType;
     526        }
     527};
    443528#endif //SIMD___SCALAR_H
Note: See TracChangeset for help on using the changeset viewer.