Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 27, 2011, 7:43:24 AM (14 years ago)
Author:
rgrieder
Message:

Updated Bullet Physics Engine from v2.74 to v2.77

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib/src/external/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp

    r5781 r7983  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    2222#include "btConvexPointCloudShape.h"
    2323
     24///not supported on IBM SDK, until we fix the alignment of btVector3
     25#if defined (__CELLOS_LV2__) && defined (__SPU__)
     26#include <spu_intrinsics.h>
     27static inline vec_float4 vec_dot3( vec_float4 vec0, vec_float4 vec1 )
     28{
     29    vec_float4 result;
     30    result = spu_mul( vec0, vec1 );
     31    result = spu_madd( spu_rlqwbyte( vec0, 4 ), spu_rlqwbyte( vec1, 4 ), result );
     32    return spu_madd( spu_rlqwbyte( vec0, 8 ), spu_rlqwbyte( vec1, 8 ), result );
     33}
     34#endif //__SPU__
     35
    2436btConvexShape::btConvexShape ()
    2537{
     
    3345
    3446
    35 static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints, const btVector3& localScaling)
    36 {
    37         btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
    38         btScalar newDot,maxDot = btScalar(-1e30);
    39 
    40         btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ());
    41         btVector3 vec = vec0;
    42         btScalar lenSqr = vec.length2();
    43         if (lenSqr < btScalar(0.0001))
    44         {
    45                 vec.setValue(1,0,0);
    46         } else {
    47                 btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
    48                 vec *= rlen;
    49         }
    50 
     47static btVector3 convexHullSupport (const btVector3& localDirOrg, const btVector3* points, int numPoints, const btVector3& localScaling)
     48{       
     49
     50        btVector3 vec = localDirOrg * localScaling;
     51
     52#if defined (__CELLOS_LV2__) && defined (__SPU__)
     53
     54        btVector3 localDir = vec;
     55
     56        vec_float4 v_distMax = {-FLT_MAX,0,0,0};
     57        vec_int4 v_idxMax = {-999,0,0,0};
     58        int v=0;
     59        int numverts = numPoints;
     60
     61        for(;v<(int)numverts-4;v+=4) {
     62                vec_float4 p0 = vec_dot3(points[v  ].get128(),localDir.get128());
     63                vec_float4 p1 = vec_dot3(points[v+1].get128(),localDir.get128());
     64                vec_float4 p2 = vec_dot3(points[v+2].get128(),localDir.get128());
     65                vec_float4 p3 = vec_dot3(points[v+3].get128(),localDir.get128());
     66                const vec_int4 i0 = {v  ,0,0,0};
     67                const vec_int4 i1 = {v+1,0,0,0};
     68                const vec_int4 i2 = {v+2,0,0,0};
     69                const vec_int4 i3 = {v+3,0,0,0};
     70                vec_uint4  retGt01 = spu_cmpgt(p0,p1);
     71                vec_float4 pmax01 = spu_sel(p1,p0,retGt01);
     72                vec_int4   imax01 = spu_sel(i1,i0,retGt01);
     73                vec_uint4  retGt23 = spu_cmpgt(p2,p3);
     74                vec_float4 pmax23 = spu_sel(p3,p2,retGt23);
     75                vec_int4   imax23 = spu_sel(i3,i2,retGt23);
     76                vec_uint4  retGt0123 = spu_cmpgt(pmax01,pmax23);
     77                vec_float4 pmax0123 = spu_sel(pmax23,pmax01,retGt0123);
     78                vec_int4   imax0123 = spu_sel(imax23,imax01,retGt0123);
     79                vec_uint4  retGtMax = spu_cmpgt(v_distMax,pmax0123);
     80                v_distMax = spu_sel(pmax0123,v_distMax,retGtMax);
     81                v_idxMax = spu_sel(imax0123,v_idxMax,retGtMax);
     82        }
     83        for(;v<(int)numverts;v++) {
     84                vec_float4 p = vec_dot3(points[v].get128(),localDir.get128());
     85                const vec_int4 i = {v,0,0,0};
     86                vec_uint4  retGtMax = spu_cmpgt(v_distMax,p);
     87                v_distMax = spu_sel(p,v_distMax,retGtMax);
     88                v_idxMax = spu_sel(i,v_idxMax,retGtMax);
     89        }
     90        int ptIndex = spu_extract(v_idxMax,0);
     91        const btVector3& supVec= points[ptIndex] * localScaling;
     92        return supVec;
     93#else
     94
     95        btScalar newDot,maxDot = btScalar(-BT_LARGE_FLOAT);
     96        int ptIndex = -1;
    5197
    5298        for (int i=0;i<numPoints;i++)
    5399        {
    54                 btVector3 vtx = points[i] * localScaling;
    55 
    56                 newDot = vec.dot(vtx);
     100
     101                newDot = vec.dot(points[i]);
    57102                if (newDot > maxDot)
    58103                {
    59104                        maxDot = newDot;
    60                         supVec = vtx;
    61                 }
    62         }
    63         return btVector3(supVec.getX(),supVec.getY(),supVec.getZ());
     105                        ptIndex = i;
     106                }
     107        }
     108        btAssert(ptIndex >= 0);
     109        btVector3 supVec = points[ptIndex] * localScaling;
     110        return supVec;
     111#endif //__SPU__
    64112}
    65113
     
    161209                btVector3 supVec(0,0,0);
    162210
    163                 btScalar maxDot(btScalar(-1e30));
     211                btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
    164212
    165213                btVector3 vec = vec0;
     
    293341        return btScalar(0.0f);
    294342}
    295 
     343#ifndef __SPU__
    296344void btConvexShape::getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const
    297345{
     
    361409        case CONVEX_HULL_SHAPE_PROXYTYPE:
    362410        {
    363                 btPolyhedralConvexShape* convexHullShape = (btPolyhedralConvexShape*)this;
     411                btPolyhedralConvexAabbCachingShape* convexHullShape = (btPolyhedralConvexAabbCachingShape*)this;
    364412                btScalar margin = convexHullShape->getMarginNonVirtual();
    365413                convexHullShape->getNonvirtualAabb (t, aabbMin, aabbMax, margin);
     
    378426        btAssert (0);
    379427}
     428
     429#endif //__SPU__
Note: See TracChangeset for help on using the changeset viewer.