Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 13, 2008, 11:45:51 PM (16 years ago)
Author:
rgrieder
Message:

Updated to Bullet 2.73 (first part).

Location:
code/branches/physics/src/bullet/BulletCollision/CollisionShapes
Files:
39 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBoxShape.h

    r2192 r2430  
    2020#include "btCollisionMargin.h"
    2121#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h"
    22 #include "LinearMath/btPoint3.h"
     22#include "LinearMath/btVector3.h"
    2323#include "LinearMath/btMinMax.h"
    2424
     
    118118        virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
    119119
    120         virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const
     120        virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const
    121121        {
    122122                //this plane might not be aligned...
     
    191191
    192192       
    193         virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const
     193        virtual void getEdge(int i,btVector3& pa,btVector3& pb) const
    194194        //virtual void getEdge(int i,Edge& edge) const
    195195        {
     
    262262
    263263       
    264         virtual bool isInside(const btPoint3& pt,btScalar tolerance) const
     264        virtual bool isInside(const btVector3& pt,btScalar tolerance) const
    265265        {
    266266                btVector3 halfExtents = getHalfExtentsWithoutMargin();
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btBvhTriangleMeshShape.cpp

    r2192 r2430  
    144144                        {
    145145                                int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
    146 
    147                                 btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
    148 
    149                                 m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());           
     146                               
     147                                if (type == PHY_FLOAT)
     148                                {
     149                                        float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
     150                                       
     151                                        m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());           
     152                                }
     153                                else
     154                                {
     155                                        double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
     156                                       
     157                                        m_triangle[j] = btVector3(btScalar(graphicsbase[0])*meshScaling.getX(),btScalar(graphicsbase[1])*meshScaling.getY(),btScalar(graphicsbase[2])*meshScaling.getZ());             
     158                                }
    150159                        }
    151160
     
    205214                                int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
    206215
    207                                 btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
    208 
    209                                 m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());           
     216                                if (type == PHY_FLOAT)
     217                                {
     218                                        float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
     219
     220                                        m_triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());           
     221                                }
     222                                else
     223                                {
     224                                        double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
     225                                       
     226                                        m_triangle[j] = btVector3(btScalar(graphicsbase[0])*meshScaling.getX(),btScalar(graphicsbase[1])*meshScaling.getY(),btScalar(graphicsbase[2])*meshScaling.getZ());             
     227                                }
    210228                        }
    211229
     
    282300                                printf("%d ,",graphicsindex);
    283301#endif //DEBUG_TRIANGLE_MESH
    284                                 btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
    285 
    286                                 m_triangle[j] = btVector3(
    287                                         graphicsbase[0]*meshScaling.getX(),
    288                                         graphicsbase[1]*meshScaling.getY(),
    289                                         graphicsbase[2]*meshScaling.getZ());
     302                                if (type == PHY_FLOAT)
     303                                {
     304                                        float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
     305                                       
     306                                        m_triangle[j] = btVector3(
     307                                                                                                                                                graphicsbase[0]*meshScaling.getX(),
     308                                                                                                                                                graphicsbase[1]*meshScaling.getY(),
     309                                                                                                                                                graphicsbase[2]*meshScaling.getZ());
     310                                }
     311                                else
     312                                {
     313                                        double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
     314
     315                                        m_triangle[j] = btVector3(
     316                                                btScalar(graphicsbase[0])*meshScaling.getX(),
     317                                                btScalar(graphicsbase[1])*meshScaling.getY(),
     318                                                btScalar(graphicsbase[2])*meshScaling.getZ());
     319                                }
    290320#ifdef DEBUG_TRIANGLE_MESH
    291321                                printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z());
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCapsuleShape.h

    r2192 r2430  
    5050                        halfExtents += btVector3(getMargin(),getMargin(),getMargin());
    5151                        btMatrix3x3 abs_b = t.getBasis().absolute(); 
    52                         btPoint3 center = t.getOrigin();
     52                        btVector3 center = t.getOrigin();
    5353                        btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));             
    5454                       
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.cpp

    r2192 r2430  
    4343}
    4444
     45btScalar        btCollisionShape::getContactBreakingThreshold() const
     46{
     47        ///@todo make this 0.1 configurable
     48        return getAngularMotionDisc() * btScalar(0.1);
     49}
    4550btScalar        btCollisionShape::getAngularMotionDisc() const
    4651{
     52        ///@todo cache this value, to improve performance
    4753        btVector3       center;
    4854        btScalar disc;
     
    6672        // add linear motion
    6773        btVector3 linMotion = linvel*timeStep;
    68         //todo: simd would have a vector max/min operation, instead of per-element access
     74        ///@todo: simd would have a vector max/min operation, instead of per-element access
    6975        if (linMotion.x() > btScalar(0.))
    7076                temporalAabbMaxx += linMotion.x();
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCollisionShape.h

    r2192 r2430  
    2020#include "LinearMath/btVector3.h"
    2121#include "LinearMath/btMatrix3x3.h"
    22 #include "LinearMath/btPoint3.h"
    2322#include "BulletCollision/BroadphaseCollision/btBroadphaseProxy.h" //for the shape types
    2423
     
    4746        ///getAngularMotionDisc returns the maximus radius needed for Conservative Advancement to handle time-of-impact with rotations.
    4847        virtual btScalar        getAngularMotionDisc() const;
     48
     49        virtual btScalar        getContactBreakingThreshold() const;
    4950
    5051
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.cpp

    r2192 r2430  
    1818#include "BulletCollision/BroadphaseCollision/btDbvt.h"
    1919
    20 btCompoundShape::btCompoundShape()
     20btCompoundShape::btCompoundShape(bool enableDynamicAabbTree)
    2121: m_localAabbMin(btScalar(1e30),btScalar(1e30),btScalar(1e30)),
    2222m_localAabbMax(btScalar(-1e30),btScalar(-1e30),btScalar(-1e30)),
     
    2626{
    2727        m_shapeType = COMPOUND_SHAPE_PROXYTYPE;
    28         void* mem = btAlignedAlloc(sizeof(btDbvt),16);
    29         m_dynamicAabbTree = new(mem) btDbvt();
    30         btAssert(mem==m_dynamicAabbTree);
     28
     29        if (enableDynamicAabbTree)
     30        {
     31                void* mem = btAlignedAlloc(sizeof(btDbvt),16);
     32                m_dynamicAabbTree = new(mem) btDbvt();
     33                btAssert(mem==m_dynamicAabbTree);
     34        }
    3135}
    3236
     
    7781}
    7882
     83void    btCompoundShape::updateChildTransform(int childIndex, const btTransform& newChildTransform)
     84{
     85        m_children[childIndex].m_transform = newChildTransform;
     86
     87        if (m_dynamicAabbTree)
     88        {
     89                ///update the dynamic aabb tree
     90                btVector3 localAabbMin,localAabbMax;
     91                m_children[childIndex].m_childShape->getAabb(newChildTransform,localAabbMin,localAabbMax);
     92                ATTRIBUTE_ALIGNED16(btDbvtVolume)       bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
     93                int index = m_children.size()-1;
     94                m_dynamicAabbTree->update(m_children[childIndex].m_node,bounds);
     95        }
     96
     97        recalculateLocalAabb();
     98}
     99
    79100void btCompoundShape::removeChildShapeByIndex(int childShapeIndex)
    80101{
     
    88109
    89110}
     111
     112
    90113
    91114void btCompoundShape::removeChildShape(btCollisionShape* shape)
     
    100123                        m_children.pop_back();
    101124                        //remove it from the m_dynamicAabbTree too
     125                        //@todo: this leads to problems due to caching in the btCompoundCollisionAlgorithm
     126                        //so effectively, removeChildShape is broken at the moment
    102127                        //m_dynamicAabbTree->remove(m_aabbProxies[i]);
    103128                        //m_aabbProxies.swap(i,m_children.size()-1);
     
    142167        btMatrix3x3 abs_b = trans.getBasis().absolute(); 
    143168
    144         btPoint3 center = trans(localCenter);
     169        btVector3 center = trans(localCenter);
    145170
    146171        btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
     
    181206        btScalar totalMass = 0;
    182207        btVector3 center(0, 0, 0);
    183         for (int k = 0; k < n; k++)
     208        int k;
     209
     210        for (k = 0; k < n; k++)
    184211        {
    185212                center += m_children[k].m_transform.getOrigin() * masses[k];
     
    190217
    191218        btMatrix3x3 tensor(0, 0, 0, 0, 0, 0, 0, 0, 0);
    192         for (int k = 0; k < n; k++)
     219        for ( k = 0; k < n; k++)
    193220        {
    194221                btVector3 i;
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCompoundShape.h

    r2192 r2430  
    4747}
    4848
    49 /// btCompoundShape allows to store multiple other btCollisionShapes
     49/// The btCompoundShape allows to store multiple other btCollisionShapes
    5050/// This allows for moving concave collision objects. This is more general then the static concave btBvhTriangleMeshShape.
     51/// It has an (optional) dynamic aabb tree to accelerate early rejection tests.
     52/// @todo: This aabb tree can also be use to speed up ray tests on btCompoundShape, see http://code.google.com/p/bullet/issues/detail?id=25
     53/// Currently, removal of child shapes is only supported when disabling the aabb tree (pass 'false' in the constructor of btCompoundShape)
    5154ATTRIBUTE_ALIGNED16(class) btCompoundShape      : public btCollisionShape
    5255{
    53         //btAlignedObjectArray<btTransform>             m_childTransforms;
    54         //btAlignedObjectArray<btCollisionShape*>       m_childShapes;
    5556        btAlignedObjectArray<btCompoundShapeChild> m_children;
    5657        btVector3                                               m_localAabbMin;
    5758        btVector3                                               m_localAabbMax;
    5859
    59         //btOptimizedBvh*                                       m_aabbTree;
    6060        btDbvt*                                                 m_dynamicAabbTree;
    6161
     
    6363        BT_DECLARE_ALIGNED_ALLOCATOR();
    6464
    65         btCompoundShape();
     65        btCompoundShape(bool enableDynamicAabbTree = true);
    6666
    6767        virtual ~btCompoundShape();
     
    8989        }
    9090
    91         btTransform     getChildTransform(int index)
     91        btTransform&    getChildTransform(int index)
    9292        {
    9393                return m_children[index].m_transform;
    9494        }
    95         const btTransform       getChildTransform(int index) const
     95        const btTransform&      getChildTransform(int index) const
    9696        {
    9797                return m_children[index].m_transform;
    9898        }
     99
     100        ///set a new transform for a child, and update internal data structures (local aabb and dynamic tree)
     101        void    updateChildTransform(int childIndex, const btTransform& newChildTransform);
    99102
    100103
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConcaveShape.h

    r2192 r2430  
    2121#include "btTriangleCallback.h"
    2222
     23/// PHY_ScalarType enumerates possible scalar types.
     24/// See the btStridingMeshInterface or btHeightfieldTerrainShape for its use
     25typedef enum PHY_ScalarType {
     26        PHY_FLOAT,
     27        PHY_DOUBLE,
     28        PHY_INTEGER,
     29        PHY_SHORT,
     30        PHY_FIXEDPOINT88,
     31        PHY_UCHAR
     32} PHY_ScalarType;
    2333
    2434///The btConcaveShape class provides an interface for non-moving (static) concave shapes.
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConeShape.cpp

    r2192 r2430  
    1515
    1616#include "btConeShape.h"
    17 #include "LinearMath/btPoint3.h"
    1817
    1918
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.cpp

    r2192 r2430  
    2323{
    2424        m_shapeType = CONVEX_HULL_SHAPE_PROXYTYPE;
    25         m_points.resize(numPoints);
     25        m_unscaledPoints.resize(numPoints);
    2626
    2727        unsigned char* pointsBaseAddress = (unsigned char*)points;
     
    2929        for (int i=0;i<numPoints;i++)
    3030        {
    31                 btPoint3* point = (btPoint3*)(pointsBaseAddress + i*stride);
    32                 m_points[i] = point[0];
     31                btVector3* point = (btVector3*)(pointsBaseAddress + i*stride);
     32                m_unscaledPoints[i] = point[0];
    3333        }
    3434
     
    4545}
    4646
    47 void btConvexHullShape::addPoint(const btPoint3& point)
     47void btConvexHullShape::addPoint(const btVector3& point)
    4848{
    49         m_points.push_back(point);
     49        m_unscaledPoints.push_back(point);
    5050        recalcLocalAabb();
    5151
     
    6969
    7070
    71         for (int i=0;i<m_points.size();i++)
     71        for (int i=0;i<m_unscaledPoints.size();i++)
    7272        {
    73                 btPoint3 vtx = m_points[i] * m_localScaling;
     73                btVector3 vtx = m_unscaledPoints[i] * m_localScaling;
    7474
    7575                newDot = vec.dot(vtx);
     
    9393                }
    9494        }
    95         for (int i=0;i<m_points.size();i++)
     95        for (int i=0;i<m_unscaledPoints.size();i++)
    9696        {
    97                 btPoint3 vtx = m_points[i] * m_localScaling;
     97                btVector3 vtx = getScaledPoint(i);
    9898
    9999                for (int j=0;j<numVectors;j++)
     
    146146int     btConvexHullShape::getNumVertices() const
    147147{
    148         return m_points.size();
     148        return m_unscaledPoints.size();
    149149}
    150150
    151151int btConvexHullShape::getNumEdges() const
    152152{
    153         return m_points.size();
     153        return m_unscaledPoints.size();
    154154}
    155155
    156 void btConvexHullShape::getEdge(int i,btPoint3& pa,btPoint3& pb) const
     156void btConvexHullShape::getEdge(int i,btVector3& pa,btVector3& pb) const
    157157{
    158158
    159         int index0 = i%m_points.size();
    160         int index1 = (i+1)%m_points.size();
    161         pa = m_points[index0]*m_localScaling;
    162         pb = m_points[index1]*m_localScaling;
     159        int index0 = i%m_unscaledPoints.size();
     160        int index1 = (i+1)%m_unscaledPoints.size();
     161        pa = getScaledPoint(index0);
     162        pb = getScaledPoint(index1);
    163163}
    164164
    165 void btConvexHullShape::getVertex(int i,btPoint3& vtx) const
     165void btConvexHullShape::getVertex(int i,btVector3& vtx) const
    166166{
    167         vtx = m_points[i]*m_localScaling;
     167        vtx = getScaledPoint(i);
    168168}
    169169
     
    173173}
    174174
    175 void btConvexHullShape::getPlane(btVector3& ,btPoint3& ,int ) const
     175void btConvexHullShape::getPlane(btVector3& ,btVector3& ,int ) const
    176176{
    177177
     
    180180
    181181//not yet
    182 bool btConvexHullShape::isInside(const btPoint3& ,btScalar ) const
     182bool btConvexHullShape::isInside(const btVector3& ,btScalar ) const
    183183{
    184184        assert(0);
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexHullShape.h

    r2192 r2430  
    2525ATTRIBUTE_ALIGNED16(class) btConvexHullShape : public btPolyhedralConvexShape
    2626{
    27         btAlignedObjectArray<btPoint3>  m_points;
     27        btAlignedObjectArray<btVector3> m_unscaledPoints;
    2828
    2929public:
     
    3434        ///It is easier to not pass any points in the constructor, and just add one point at a time, using addPoint.
    3535        ///btConvexHullShape make an internal copy of the points.
    36         btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(btPoint3));
     36        btConvexHullShape(const btScalar* points=0,int numPoints=0, int stride=sizeof(btVector3));
    3737
    38         void addPoint(const btPoint3& point);
     38        void addPoint(const btVector3& point);
    3939
    40         btPoint3* getPoints()
     40       
     41        btVector3* getUnscaledPoints()
    4142        {
    42                 return &m_points[0];
     43                return &m_unscaledPoints[0];
    4344        }
    4445
    45         const btPoint3* getPoints() const
     46        const btVector3* getUnscaledPoints() const
    4647        {
    47                 return &m_points[0];
     48                return &m_unscaledPoints[0];
    4849        }
    4950
    50         int getNumPoints() const
     51        ///getPoints is obsolete, please use getUnscaledPoints
     52        const btVector3* getPoints() const
    5153        {
    52                 return m_points.size();
     54                return getUnscaledPoints();
     55        }
     56
     57       
     58
     59
     60        SIMD_FORCE_INLINE       btVector3 getScaledPoint(int i) const
     61        {
     62                return m_unscaledPoints[i] * m_localScaling;
     63        }
     64
     65        SIMD_FORCE_INLINE       int getNumPoints() const
     66        {
     67                return m_unscaledPoints.size();
    5368        }
    5469
     
    6580        virtual int     getNumVertices() const;
    6681        virtual int getNumEdges() const;
    67         virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
    68         virtual void getVertex(int i,btPoint3& vtx) const;
     82        virtual void getEdge(int i,btVector3& pa,btVector3& pb) const;
     83        virtual void getVertex(int i,btVector3& vtx) const;
    6984        virtual int     getNumPlanes() const;
    70         virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
    71         virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
     85        virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const;
     86        virtual bool isInside(const btVector3& pt,btScalar tolerance) const;
    7287
    7388        ///in case we receive negative scaling
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.cpp

    r2192 r2430  
    1818
    1919
     20
    2021btConvexInternalShape::btConvexInternalShape()
    21 : btConvexShape (), m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
     22: m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.)),
    2223m_collisionMargin(CONVEX_DISTANCE_MARGIN)
    2324{
     
    4950                minAabb[i] = tmp[i]-margin;
    5051        }
    51 };
     52}
     53
    5254
    5355
     
    7173
    7274#else
     75        btAssert(0);
    7376        return btVector3(0,0,0);
    7477#endif //__SPU__
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexInternalShape.h

    r2192 r2430  
    3131        }
    3232
    33 
    3433        virtual btVector3       localGetSupportingVertex(const btVector3& vec)const;
    35 #ifndef __SPU__
    36         virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0;
    37        
    38         //notice that the vectors should be unit length
    39         virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
    40 #endif //#ifndef __SPU__
    4134
    4235        const btVector3& getImplicitShapeDimensions() const
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.cpp

    r2192 r2430  
    1818#include "LinearMath/btQuaternion.h"
    1919
    20 btConvexPointCloudShape::btConvexPointCloudShape (btVector3* points,int numPoints) : btPolyhedralConvexShape ()
    21 {
    22         m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
    23         m_points = points;
    24         m_numPoints = numPoints;
    25 
    26         recalcLocalAabb();
    27 }
    28 
    29 void btConvexPointCloudShape::setPoints (btVector3* points, int numPoints)
    30 {
    31         m_points = points;
    32         m_numPoints = numPoints;
    33 
    34         recalcLocalAabb();
    35 }
    36 
    37 
    3820void btConvexPointCloudShape::setLocalScaling(const btVector3& scaling)
    3921{
     
    4224}
    4325
     26#ifndef __SPU__
    4427btVector3       btConvexPointCloudShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
    4528{
     
    6144        for (int i=0;i<m_numPoints;i++)
    6245        {
    63                 btPoint3 vtx = m_points[i] * m_localScaling;
     46                btVector3 vtx = getScaledPoint(i);
    6447
    6548                newDot = vec.dot(vtx);
     
    8568        for (int i=0;i<m_numPoints;i++)
    8669        {
    87                 btPoint3 vtx = m_points[i] * m_localScaling;
     70                btVector3 vtx = getScaledPoint(i);
    8871
    8972                for (int j=0;j<numVectors;j++)
     
    125108
    126109
    127 
     110#endif
    128111
    129112
     
    144127}
    145128
    146 void btConvexPointCloudShape::getEdge(int i,btPoint3& pa,btPoint3& pb) const
     129void btConvexPointCloudShape::getEdge(int i,btVector3& pa,btVector3& pb) const
    147130{
    148131        btAssert (0);
    149132}
    150133
    151 void btConvexPointCloudShape::getVertex(int i,btPoint3& vtx) const
     134void btConvexPointCloudShape::getVertex(int i,btVector3& vtx) const
    152135{
    153         vtx = m_points[i]*m_localScaling;
     136        vtx = m_unscaledPoints[i]*m_localScaling;
    154137}
    155138
     
    159142}
    160143
    161 void btConvexPointCloudShape::getPlane(btVector3& ,btPoint3& ,int ) const
     144void btConvexPointCloudShape::getPlane(btVector3& ,btVector3& ,int ) const
    162145{
    163146
     
    166149
    167150//not yet
    168 bool btConvexPointCloudShape::isInside(const btPoint3& ,btScalar ) const
     151bool btConvexPointCloudShape::isInside(const btVector3& ,btScalar ) const
    169152{
    170153        assert(0);
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexPointCloudShape.h

    r2192 r2430  
    2424ATTRIBUTE_ALIGNED16(class) btConvexPointCloudShape : public btPolyhedralConvexShape
    2525{
    26         btVector3* m_points;
     26        btVector3* m_unscaledPoints;
    2727        int m_numPoints;
     28
    2829public:
    2930        BT_DECLARE_ALIGNED_ALLOCATOR();
    3031
    31         btConvexPointCloudShape(btVector3* points,int numPoints);
     32        btConvexPointCloudShape(btVector3* points,int numPoints, const btVector3& localScaling,bool computeAabb = true)
     33        {
     34                m_localScaling = localScaling;
     35                m_shapeType = CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE;
     36                m_unscaledPoints = points;
     37                m_numPoints = numPoints;
    3238
    33         void setPoints (btVector3* points, int numPoints);
    34 
    35         btPoint3* getPoints()
    36         {
    37                 return m_points;
     39                if (computeAabb)
     40                        recalcLocalAabb();
    3841        }
    3942
    40         const btPoint3* getPoints() const
     43        void setPoints (btVector3* points, int numPoints, bool computeAabb = true)
    4144        {
    42                 return m_points;
     45                m_unscaledPoints = points;
     46                m_numPoints = numPoints;
     47
     48                if (computeAabb)
     49                        recalcLocalAabb();
    4350        }
    4451
    45         int getNumPoints() const
     52        SIMD_FORCE_INLINE       btVector3* getUnscaledPoints()
     53        {
     54                return m_unscaledPoints;
     55        }
     56
     57        SIMD_FORCE_INLINE       const btVector3* getUnscaledPoints() const
     58        {
     59                return m_unscaledPoints;
     60        }
     61
     62        SIMD_FORCE_INLINE       int getNumPoints() const
    4663        {
    4764                return m_numPoints;
    4865        }
    4966
     67        SIMD_FORCE_INLINE       btVector3       getScaledPoint( int index) const
     68        {
     69                return m_unscaledPoints[index] * m_localScaling;
     70        }
     71
     72#ifndef __SPU__
    5073        virtual btVector3       localGetSupportingVertex(const btVector3& vec)const;
    5174        virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
    5275        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
     76#endif
    5377
    5478
     
    5882        virtual int     getNumVertices() const;
    5983        virtual int getNumEdges() const;
    60         virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
    61         virtual void getVertex(int i,btPoint3& vtx) const;
     84        virtual void getEdge(int i,btVector3& pa,btVector3& pb) const;
     85        virtual void getVertex(int i,btVector3& vtx) const;
    6286        virtual int     getNumPlanes() const;
    63         virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
    64         virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
     87        virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const;
     88        virtual bool isInside(const btVector3& pt,btScalar tolerance) const;
    6589
    6690        ///in case we receive negative scaling
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.cpp

    r2192 r2430  
    1515
    1616#include "btConvexShape.h"
    17 #include "btConvexInternalShape.h"
    1817#include "btTriangleShape.h"
    1918#include "btSphereShape.h"
     
    2322#include "btConvexPointCloudShape.h"
    2423
    25 static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints)
     24btConvexShape::btConvexShape ()
     25{
     26}
     27
     28btConvexShape::~btConvexShape()
     29{
     30
     31}
     32
     33
     34
     35static btVector3 convexHullSupport (const btVector3& localDir, const btVector3* points, int numPoints, const btVector3& localScaling)
    2636{
    2737        btVector3 supVec(btScalar(0.),btScalar(0.),btScalar(0.));
     
    4252        for (int i=0;i<numPoints;i++)
    4353        {
    44                 btPoint3 vtx = points[i];// * m_localScaling;
     54                btVector3 vtx = points[i] * localScaling;
    4555
    4656                newDot = vec.dot(vtx);
     
    6272                return btVector3(0,0,0);
    6373    }
    64         break;
    6574        case BOX_SHAPE_PROXYTYPE:
    6675        {
    67                 btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
     76                btBoxShape* convexShape = (btBoxShape*)this;
    6877                const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();
    6978
     
    7281                        btFsels(localDir.z(), halfExtents.z(), -halfExtents.z()));
    7382        }
    74         break;
    7583        case TRIANGLE_SHAPE_PROXYTYPE:
    7684        {
     
    8290                return btVector3(sup.getX(),sup.getY(),sup.getZ());
    8391        }
    84         break;
    8592        case CYLINDER_SHAPE_PROXYTYPE:
    8693        {
     
    143150                }
    144151        }
    145         break;
    146152        case CAPSULE_SHAPE_PROXYTYPE:
    147153        {
     
    200206                return btVector3(supVec.getX(),supVec.getY(),supVec.getZ());   
    201207        }
    202         break;
    203208        case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
    204209        {
    205210                btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this;
    206                 btVector3* points = convexPointCloudShape->getPoints ();
     211                btVector3* points = convexPointCloudShape->getUnscaledPoints ();
    207212                int numPoints = convexPointCloudShape->getNumPoints ();
    208                 return convexHullSupport (localDir, points, numPoints);
     213                return convexHullSupport (localDir, points, numPoints,convexPointCloudShape->getLocalScalingNV());
    209214        }
    210215        case CONVEX_HULL_SHAPE_PROXYTYPE:
    211216        {
    212217                btConvexHullShape* convexHullShape = (btConvexHullShape*)this;
    213                 btPoint3* points = convexHullShape->getPoints ();
     218                btVector3* points = convexHullShape->getUnscaledPoints();
    214219                int numPoints = convexHullShape->getNumPoints ();
    215                 return convexHullSupport (localDir, points, numPoints);
    216         }
    217         break;
     220                return convexHullSupport (localDir, points, numPoints,convexHullShape->getLocalScalingNV());
     221        }
    218222    default:
    219223#ifndef __SPU__
     
    222226                btAssert (0);
    223227#endif
    224         break;
    225228        }
    226229
    227230        // should never reach here
    228231        btAssert (0);
    229         return btPoint3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
     232        return btVector3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
    230233}
    231234
     
    238241        }
    239242        localDirNorm.normalize ();
    240         switch (m_shapeType)
    241         {
    242     case SPHERE_SHAPE_PROXYTYPE:
    243         {
    244                 return btVector3(0,0,0) + getMarginNonVirtual() * localDirNorm;
    245     }
    246         break;
    247         case BOX_SHAPE_PROXYTYPE:
    248         {
    249                 btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
    250                 const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();
    251 
    252                 return btVector3(localDir.getX() < 0.0f ? -halfExtents.x() : halfExtents.x(),
    253                                                 localDir.getY() < 0.0f ? -halfExtents.y() : halfExtents.y(),
    254                                                 localDir.getZ() < 0.0f ? -halfExtents.z() : halfExtents.z()) + getMarginNonVirtual() * localDirNorm;
    255         }
    256         break;
    257         case TRIANGLE_SHAPE_PROXYTYPE:
    258         {
    259                 btTriangleShape* triangleShape = (btTriangleShape*)this;
    260                 btVector3 dir(localDir.getX(),localDir.getY(),localDir.getZ());
    261                 btVector3* vertices = &triangleShape->m_vertices1[0];
    262                 btVector3 dots(dir.dot(vertices[0]), dir.dot(vertices[1]), dir.dot(vertices[2]));
    263                 btVector3 sup = vertices[dots.maxAxis()];
    264                 return btVector3(sup.getX(),sup.getY(),sup.getZ()) + getMarginNonVirtual() * localDirNorm;
    265         }
    266         break;
    267         case CYLINDER_SHAPE_PROXYTYPE:
    268         {
    269                 btCylinderShape* cylShape = (btCylinderShape*)this;
    270                 //mapping of halfextents/dimension onto radius/height depends on how cylinder local orientation is (upAxis)
    271 
    272                 btVector3 halfExtents = cylShape->getImplicitShapeDimensions();
    273                 btVector3 v(localDir.getX(),localDir.getY(),localDir.getZ());
    274                 int cylinderUpAxis = cylShape->getUpAxis();
    275                 int XX(1),YY(0),ZZ(2);
    276 
    277                 switch (cylinderUpAxis)
    278                 {
    279                 case 0:
    280                 {
    281                         XX = 1;
    282                         YY = 0;
    283                         ZZ = 2;
    284                 }
    285                 break;
    286                 case 1:
    287                 {
    288                         XX = 0;
    289                         YY = 1;
    290                         ZZ = 2;
    291                 }
    292                 break;
    293                 case 2:
    294                 {
    295                         XX = 0;
    296                         YY = 2;
    297                         ZZ = 1;
    298                        
    299                 }
    300                 break;
    301                 default:
    302                         btAssert(0);
    303                 break;
    304                 };
    305 
    306                 btScalar radius = halfExtents[XX];
    307                 btScalar halfHeight = halfExtents[cylinderUpAxis];
    308 
    309                 btVector3 tmp;
    310                 btScalar d ;
    311 
    312                 btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
    313                 if (s != btScalar(0.0))
    314                 {
    315                         d = radius / s; 
    316                         tmp[XX] = v[XX] * d;
    317                         tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
    318                         tmp[ZZ] = v[ZZ] * d;
    319                         return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()) + getMarginNonVirtual() * localDirNorm;
    320                 } else {
    321                         tmp[XX] = radius;
    322                         tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
    323                         tmp[ZZ] = btScalar(0.0);
    324                         return btVector3(tmp.getX(),tmp.getY(),tmp.getZ()) + getMarginNonVirtual() * localDirNorm;
    325                 }
    326         }
    327         break;
    328         case CAPSULE_SHAPE_PROXYTYPE:
    329         {
    330                 btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ());
    331 
    332                 btCapsuleShape* capsuleShape = (btCapsuleShape*)this;
    333                 btVector3 halfExtents = capsuleShape->getImplicitShapeDimensions();
    334                 btScalar halfHeight = capsuleShape->getHalfHeight();
    335                 int capsuleUpAxis = capsuleShape->getUpAxis();
    336 
    337                 btScalar radius = capsuleShape->getRadius();
    338                 btVector3 supVec(0,0,0);
    339 
    340                 btScalar maxDot(btScalar(-1e30));
    341 
    342                 btVector3 vec = vec0;
    343                 btScalar lenSqr = vec.length2();
    344                 if (lenSqr < btScalar(0.0001))
    345                 {
    346                         vec.setValue(1,0,0);
    347                 } else
    348                 {
    349                         btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
    350                         vec *= rlen;
    351                 }
    352                 btVector3 vtx;
    353                 btScalar newDot;
    354                 {
    355                         btVector3 pos(0,0,0);
    356                         pos[capsuleUpAxis] = halfHeight;
    357 
    358                         vtx = pos +vec*(radius);
    359                         newDot = vec.dot(vtx);
    360                         if (newDot > maxDot)
    361                         {
    362                                 maxDot = newDot;
    363                                 supVec = vtx;
    364                         }
    365                 }
    366                 {
    367                         btVector3 pos(0,0,0);
    368                         pos[capsuleUpAxis] = -halfHeight;
    369 
    370                         vtx = pos +vec*(radius);
    371                         newDot = vec.dot(vtx);
    372                         if (newDot > maxDot)
    373                         {
    374                                 maxDot = newDot;
    375                                 supVec = vtx;
    376                         }
    377                 }
    378                 return btVector3(supVec.getX(),supVec.getY(),supVec.getZ()) + getMarginNonVirtual() * localDirNorm;
    379         }
    380         break;
    381         case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
    382         {
    383                 btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this;
    384                 btVector3* points = convexPointCloudShape->getPoints ();
    385                 int numPoints = convexPointCloudShape->getNumPoints ();
    386                 return convexHullSupport (localDir, points, numPoints) + getMarginNonVirtual() * localDirNorm;
    387         }
    388         case CONVEX_HULL_SHAPE_PROXYTYPE:
    389         {
    390                 btConvexHullShape* convexHullShape = (btConvexHullShape*)this;
    391                 btPoint3* points = convexHullShape->getPoints ();
    392                 int numPoints = convexHullShape->getNumPoints ();
    393                 return convexHullSupport (localDir, points, numPoints) + getMarginNonVirtual() * localDirNorm;
    394         }
    395         break;
    396     default:
    397 #ifndef __SPU__
    398                 return this->localGetSupportingVertex (localDir);
    399 #else
    400                 btAssert (0);
    401 #endif
    402         break;
    403         }
    404 
    405         // should never reach here
    406         btAssert (0);
    407         return btPoint3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
     243
     244        return localGetSupportVertexWithoutMarginNonVirtual(localDirNorm)+ getMarginNonVirtual() * localDirNorm;
    408245}
    409246
     
    418255                return sphereShape->getRadius ();
    419256        }
    420         break;
    421257        case BOX_SHAPE_PROXYTYPE:
    422258        {
    423                 btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
     259                btBoxShape* convexShape = (btBoxShape*)this;
    424260                return convexShape->getMarginNV ();
    425261        }
    426         break;
    427262        case TRIANGLE_SHAPE_PROXYTYPE:
    428263        {
     
    430265                return triangleShape->getMarginNV ();
    431266        }
    432         break;
    433267        case CYLINDER_SHAPE_PROXYTYPE:
    434268        {
     
    436270                return cylShape->getMarginNV();
    437271        }
    438         break;
    439272        case CAPSULE_SHAPE_PROXYTYPE:
    440273        {
     
    442275                return capsuleShape->getMarginNV();
    443276        }
    444         break;
    445277        case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
    446278        /* fall through */
     
    450282                return convexHullShape->getMarginNV();
    451283        }
    452         break;
    453284    default:
    454285#ifndef __SPU__
     
    457288                btAssert (0);
    458289#endif
    459         break;
    460290        }
    461291
     
    484314        case BOX_SHAPE_PROXYTYPE:
    485315        {
    486                 btConvexInternalShape* convexShape = (btConvexInternalShape*)this;
     316                btBoxShape* convexShape = (btBoxShape*)this;
    487317                float margin=convexShape->getMarginNonVirtual();
    488318                btVector3 halfExtents = convexShape->getImplicitShapeDimensions();
    489319                halfExtents += btVector3(margin,margin,margin);
    490320                btMatrix3x3 abs_b = t.getBasis().absolute(); 
    491                 btPoint3 center = t.getOrigin();
     321                btVector3 center = t.getOrigin();
    492322                btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));
    493323               
     
    496326                break;
    497327        }
    498         break;
    499328        case TRIANGLE_SHAPE_PROXYTYPE:
    500329        {
     
    524353                halfExtents += btVector3(capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual(),capsuleShape->getMarginNonVirtual());
    525354                btMatrix3x3 abs_b = t.getBasis().absolute(); 
    526                 btPoint3 center = t.getOrigin();
     355                btVector3 center = t.getOrigin();
    527356                btVector3 extent = btVector3(abs_b[0].dot(halfExtents),abs_b[1].dot(halfExtents),abs_b[2].dot(halfExtents));                   
    528357                aabbMin = center - extent;
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexShape.h

    r2192 r2430  
    2525#include "LinearMath/btAlignedAllocator.h"
    2626
    27 //todo: get rid of this btConvexCastResult thing!
    28 struct btConvexCastResult;
    2927#define MAX_PREFERRED_PENETRATION_DIRECTIONS 10
    3028
     
    3937        BT_DECLARE_ALIGNED_ALLOCATOR();
    4038
    41         btConvexShape ()
    42         {
    43         }
     39        btConvexShape ();
    4440
    45         virtual ~btConvexShape()
    46         {
     41        virtual ~btConvexShape();
    4742
    48         }
     43        virtual btVector3       localGetSupportingVertex(const btVector3& vec)const = 0;
    4944
    50 
    51         virtual btVector3       localGetSupportingVertex(const btVector3& vec)const =0;
    52 #ifndef __SPU__
    53         virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec) const= 0;
    54        
    55         //notice that the vectors should be unit length
    56         virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
    57 #endif //#ifndef __SPU__
     45        ////////
     46        #ifndef __SPU__
     47        virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec) const=0;
     48        #endif //#ifndef __SPU__
    5849
    5950        btVector3 localGetSupportVertexWithoutMarginNonVirtual (const btVector3& vec) const;
     
    6152        btScalar getMarginNonVirtual () const;
    6253        void getAabbNonVirtual (const btTransform& t, btVector3& aabbMin, btVector3& aabbMax) const;
     54
     55       
     56        //notice that the vectors should be unit length
     57        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const= 0;
    6358
    6459        ///getAabb's default implementation is brute force, expected derived classes to implement a fast dedicated version
     
    7873        virtual void    getPreferredPenetrationDirection(int index, btVector3& penetrationVector) const=0;
    7974
     75
     76       
     77       
    8078};
    8179
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.cpp

    r2192 r2430  
    109109        }
    110110       
    111         //todo: could do the batch inside the callback!
     111        ///@todo: could do the batch inside the callback!
    112112
    113113
     
    164164}
    165165
    166 void btConvexTriangleMeshShape::getEdge(int ,btPoint3& ,btPoint3& ) const
     166void btConvexTriangleMeshShape::getEdge(int ,btVector3& ,btVector3& ) const
    167167{
    168168        btAssert(0);   
    169169}
    170170
    171 void btConvexTriangleMeshShape::getVertex(int ,btPoint3& ) const
     171void btConvexTriangleMeshShape::getVertex(int ,btVector3& ) const
    172172{
    173173        btAssert(0);
     
    179179}
    180180
    181 void btConvexTriangleMeshShape::getPlane(btVector3& ,btPoint3& ,int  ) const
     181void btConvexTriangleMeshShape::getPlane(btVector3& ,btVector3& ,int  ) const
    182182{
    183183        btAssert(0);
     
    185185
    186186//not yet
    187 bool btConvexTriangleMeshShape::isInside(const btPoint3& ,btScalar ) const
     187bool btConvexTriangleMeshShape::isInside(const btVector3& ,btScalar ) const
    188188{
    189189        btAssert(0);
     
    270270         btVector3 b = triangle[1] - center;
    271271         btVector3 c = triangle[2] - center;
    272          btVector3 abc = a + b + c;
    273272         btScalar volNeg = -btFabs(a.triple(b, c)) * btScalar(1. / 6);
    274273         for (int j = 0; j < 3; j++)
     
    276275            for (int k = 0; k <= j; k++)
    277276            {
    278                i[j][k] = i[k][j] = volNeg * (center[j] * center[k]
    279                  + btScalar(0.25) * (center[j] * abc[k] + center[k] * abc[j])
    280                   + btScalar(0.1) * (a[j] * a[k] + b[j] * b[k] + c[j] * c[k])
     277               i[j][k] = i[k][j] = volNeg * (btScalar(0.1) * (a[j] * a[k] + b[j] * b[k] + c[j] * c[k])
    281278                  + btScalar(0.05) * (a[j] * b[k] + a[k] * b[j] + a[j] * c[k] + a[k] * c[j] + b[j] * c[k] + b[k] * c[j]));
    282279            }
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btConvexTriangleMeshShape.h

    r2192 r2430  
    3535        virtual int     getNumVertices() const;
    3636        virtual int getNumEdges() const;
    37         virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
    38         virtual void getVertex(int i,btPoint3& vtx) const;
     37        virtual void getEdge(int i,btVector3& pa,btVector3& pb) const;
     38        virtual void getVertex(int i,btVector3& vtx) const;
    3939        virtual int     getNumPlanes() const;
    40         virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const;
    41         virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
     40        virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const;
     41        virtual bool isInside(const btVector3& pt,btScalar tolerance) const;
    4242
    4343       
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btCylinderShape.cpp

    r2192 r2430  
    1414*/
    1515#include "btCylinderShape.h"
    16 #include "LinearMath/btPoint3.h"
    1716
    1817btCylinderShape::btCylinderShape (const btVector3& halfExtents)
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btEmptyShape.h

    r2192 r2430  
    5757        }
    5858
     59        virtual void processAllTriangles(btTriangleCallback* ,const btVector3& ,const btVector3& ) const
     60        {
     61        }
    5962
    6063protected:
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.cpp

    r2192 r2430  
    1919
    2020
     21
     22btHeightfieldTerrainShape::btHeightfieldTerrainShape
     23(
     24int heightStickWidth, int heightStickLength, void* heightfieldData,
     25btScalar heightScale, btScalar minHeight, btScalar maxHeight,int upAxis,
     26PHY_ScalarType hdt, bool flipQuadEdges
     27)
     28{
     29        initialize(heightStickWidth, heightStickLength, heightfieldData,
     30                   heightScale, minHeight, maxHeight, upAxis, hdt,
     31                   flipQuadEdges);
     32}
     33
     34
     35
    2136btHeightfieldTerrainShape::btHeightfieldTerrainShape(int heightStickWidth, int heightStickLength,void* heightfieldData,btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges)
    22 : btConcaveShape (), m_heightStickWidth(heightStickWidth),
    23 m_heightStickLength(heightStickLength),
    24 m_maxHeight(maxHeight),
    25 m_width((btScalar)heightStickWidth-1),
    26 m_length((btScalar)heightStickLength-1),
    27 m_heightfieldDataUnknown(heightfieldData),
    28 m_useFloatData(useFloatData),
    29 m_flipQuadEdges(flipQuadEdges),
    30 m_useDiamondSubdivision(false),
    31 m_upAxis(upAxis),
    32 m_localScaling(btScalar(1.),btScalar(1.),btScalar(1.))
    33 {
     37{
     38        // legacy constructor: support only float or unsigned char,
     39        //      and min height is zero
     40        PHY_ScalarType hdt = (useFloatData) ? PHY_FLOAT : PHY_UCHAR;
     41        btScalar minHeight = 0.0;
     42
     43        // previously, height = uchar * maxHeight / 65535.
     44        // So to preserve legacy behavior, heightScale = maxHeight / 65535
     45        btScalar heightScale = maxHeight / 65535;
     46
     47        initialize(heightStickWidth, heightStickLength, heightfieldData,
     48                   heightScale, minHeight, maxHeight, upAxis, hdt,
     49                   flipQuadEdges);
     50}
     51
     52
     53
     54void btHeightfieldTerrainShape::initialize
     55(
     56int heightStickWidth, int heightStickLength, void* heightfieldData,
     57btScalar heightScale, btScalar minHeight, btScalar maxHeight, int upAxis,
     58PHY_ScalarType hdt, bool flipQuadEdges
     59)
     60{
     61        // validation
     62        btAssert(heightStickWidth > 1 && "bad width");
     63        btAssert(heightStickLength > 1 && "bad length");
     64        btAssert(heightfieldData && "null heightfield data");
     65        // btAssert(heightScale) -- do we care?  Trust caller here
     66        btAssert(minHeight <= maxHeight && "bad min/max height");
     67        btAssert(upAxis >= 0 && upAxis < 3 &&
     68            "bad upAxis--should be in range [0,2]");
     69        btAssert(hdt != PHY_UCHAR || hdt != PHY_FLOAT || hdt != PHY_SHORT &&
     70            "Bad height data type enum");
     71
     72        // initialize member variables
    3473        m_shapeType = TERRAIN_SHAPE_PROXYTYPE;
    35 
    36         btScalar        quantizationMargin = 1.f;
    37 
    38         //enlarge the AABB to avoid division by zero when initializing the quantization values
    39         btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
    40 
    41         btVector3       halfExtents(0,0,0);
    42 
     74        m_heightStickWidth = heightStickWidth;
     75        m_heightStickLength = heightStickLength;
     76        m_minHeight = minHeight;
     77        m_maxHeight = maxHeight;
     78        m_width = (btScalar) (heightStickWidth - 1);
     79        m_length = (btScalar) (heightStickLength - 1);
     80        m_heightScale = heightScale;
     81        m_heightfieldDataUnknown = heightfieldData;
     82        m_heightDataType = hdt;
     83        m_flipQuadEdges = flipQuadEdges;
     84        m_useDiamondSubdivision = false;
     85        m_upAxis = upAxis;
     86        m_localScaling.setValue(btScalar(1.), btScalar(1.), btScalar(1.));
     87
     88        // determine min/max axis-aligned bounding box (aabb) values
    4389        switch (m_upAxis)
    4490        {
    4591        case 0:
    4692                {
    47                         halfExtents.setValue(
    48                                 btScalar(m_maxHeight),
    49                                 btScalar(m_width), //?? don't know if this should change
    50                                 btScalar(m_length));
     93                        m_localAabbMin.setValue(m_minHeight, 0, 0);
     94                        m_localAabbMax.setValue(m_maxHeight, m_width, m_length);
    5195                        break;
    5296                }
    5397        case 1:
    5498                {
    55                         halfExtents.setValue(
    56                                 btScalar(m_width),
    57                                 btScalar(m_maxHeight),
    58                                 btScalar(m_length));
     99                        m_localAabbMin.setValue(0, m_minHeight, 0);
     100                        m_localAabbMax.setValue(m_width, m_maxHeight, m_length);
    59101                        break;
    60102                };
    61103        case 2:
    62104                {
    63                         halfExtents.setValue(
    64                                 btScalar(m_width),
    65                                 btScalar(m_length),
    66                                 btScalar(m_maxHeight)
    67                         );
     105                        m_localAabbMin.setValue(0, 0, m_minHeight);
     106                        m_localAabbMax.setValue(m_width, m_length, m_maxHeight);
    68107                        break;
    69108                }
     
    71110                {
    72111                        //need to get valid m_upAxis
    73                         btAssert(0);
    74                 }
    75         }
    76 
    77         halfExtents*= btScalar(0.5);
    78        
    79         m_localAabbMin = -halfExtents - clampValue;
    80         m_localAabbMax = halfExtents + clampValue;
    81         btVector3 aabbSize = m_localAabbMax - m_localAabbMin;
    82 
    83 }
     112                        btAssert(0 && "Bad m_upAxis");
     113                }
     114        }
     115
     116        // remember origin (defined as exact middle of aabb)
     117        m_localOrigin = btScalar(0.5) * (m_localAabbMin + m_localAabbMax);
     118}
     119
    84120
    85121
     
    93129{
    94130        btVector3 halfExtents = (m_localAabbMax-m_localAabbMin)* m_localScaling * btScalar(0.5);
    95         halfExtents += btVector3(getMargin(),getMargin(),getMargin());
     131
     132        btVector3 localOrigin(0, 0, 0);
     133        localOrigin[m_upAxis] = (m_minHeight + m_maxHeight) * btScalar(0.5);
     134        localOrigin *= m_localScaling;
    96135
    97136        btMatrix3x3 abs_b = t.getBasis().absolute(); 
    98         btPoint3 center = t.getOrigin();
     137        btVector3 center = t.getOrigin();
    99138        btVector3 extent = btVector3(abs_b[0].dot(halfExtents),
    100139                   abs_b[1].dot(halfExtents),
    101140                  abs_b[2].dot(halfExtents));
    102        
     141        extent += btVector3(getMargin(),getMargin(),getMargin());
    103142
    104143        aabbMin = center - extent;
    105144        aabbMax = center + extent;
    106 
    107 
    108145}
    109146
     
    111148{
    112149        btScalar val = 0.f;
    113         if (m_useFloatData)
     150        switch (m_heightDataType)
    114151        {
    115                 val = m_heightfieldDataFloat[(y*m_heightStickWidth)+x];
    116         } else
    117         {
    118                 //assume unsigned short int
    119                 unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_heightStickWidth)+x];
    120                 val = heightFieldValue* (m_maxHeight/btScalar(65535));
    121         }
     152        case PHY_FLOAT:
     153                {
     154                        val = m_heightfieldDataFloat[(y*m_heightStickWidth)+x];
     155                        break;
     156                }
     157
     158        case PHY_UCHAR:
     159                {
     160                        unsigned char heightFieldValue = m_heightfieldDataUnsignedChar[(y*m_heightStickWidth)+x];
     161                        val = heightFieldValue * m_heightScale;
     162                        break;
     163                }
     164
     165        case PHY_SHORT:
     166                {
     167                        short hfValue = m_heightfieldDataShort[(y * m_heightStickWidth) + x];
     168                        val = hfValue * m_heightScale;
     169                        break;
     170                }
     171
     172        default:
     173                {
     174                        btAssert(!"Bad m_heightDataType");
     175                }
     176        }
     177
    122178        return val;
    123179}
     
    179235
    180236
     237
     238static inline int
     239getQuantized
     240(
     241float x
     242)
     243{
     244        if (x < 0.0) {
     245                return (int) (x - 0.5);
     246        }
     247        return (int) (x + 0.5);
     248}
     249
     250
     251
     252/// given input vector, return quantized version
     253/**
     254  This routine is basically determining the gridpoint indices for a given
     255  input vector, answering the question: "which gridpoint is closest to the
     256  provided point?".
     257
     258  "with clamp" means that we restrict the point to be in the heightfield's
     259  axis-aligned bounding box.
     260 */
    181261void btHeightfieldTerrainShape::quantizeWithClamp(int* out, const btVector3& point,int /*isMax*/) const
    182262{
     
    185265        clampedPoint.setMin(m_localAabbMax);
    186266
    187         btVector3 v = (clampedPoint);// - m_bvhAabbMin) * m_bvhQuantization;
    188 
    189         //TODO: optimization: check out how to removed this btFabs
     267        out[0] = getQuantized(clampedPoint.getX());
     268        out[1] = getQuantized(clampedPoint.getY());
     269        out[2] = getQuantized(clampedPoint.getZ());
    190270               
    191         out[0] = (int)(v.getX() + v.getX() / btFabs(v.getX())* btScalar(0.5) );
    192         out[1] = (int)(v.getY() + v.getY() / btFabs(v.getY())* btScalar(0.5) );
    193         out[2] = (int)(v.getZ() + v.getZ() / btFabs(v.getZ())* btScalar(0.5) );
    194        
    195 }
    196 
    197 
     271}
     272
     273
     274
     275/// process all triangles within the provided axis-aligned bounding box
     276/**
     277  basic algorithm:
     278    - convert input aabb to local coordinates (scale down and shift for local origin)
     279    - convert input aabb to a range of heightfield grid points (quantize)
     280    - iterate over all triangles in that subset of the grid
     281 */
    198282void    btHeightfieldTerrainShape::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const
    199283{
    200         (void)callback;
    201         (void)aabbMax;
    202         (void)aabbMin;
     284        // scale down the input aabb's so they are in local (non-scaled) coordinates
     285        btVector3       localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
     286        btVector3       localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
     287
     288        // account for local origin
     289        localAabbMin += m_localOrigin;
     290        localAabbMax += m_localOrigin;
    203291
    204292        //quantize the aabbMin and aabbMax, and adjust the start/end ranges
    205 
    206293        int     quantizedAabbMin[3];
    207294        int     quantizedAabbMax[3];
    208 
    209         btVector3       localAabbMin = aabbMin*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
    210         btVector3       localAabbMax = aabbMax*btVector3(1.f/m_localScaling[0],1.f/m_localScaling[1],1.f/m_localScaling[2]);
    211        
    212295        quantizeWithClamp(quantizedAabbMin, localAabbMin,0);
    213296        quantizeWithClamp(quantizedAabbMax, localAabbMax,1);
    214297       
    215        
     298        // expand the min/max quantized values
     299        // this is to catch the case where the input aabb falls between grid points!
     300        for (int i = 0; i < 3; ++i) {
     301                quantizedAabbMin[i]--;
     302                quantizedAabbMax[i]++;
     303        }       
    216304
    217305        int startX=0;
     
    224312        case 0:
    225313                {
    226                         quantizedAabbMin[1]+=m_heightStickWidth/2-1;
    227                         quantizedAabbMax[1]+=m_heightStickWidth/2+1;
    228                         quantizedAabbMin[2]+=m_heightStickLength/2-1;
    229                         quantizedAabbMax[2]+=m_heightStickLength/2+1;
    230 
    231314                        if (quantizedAabbMin[1]>startX)
    232315                                startX = quantizedAabbMin[1];
     
    241324        case 1:
    242325                {
    243                         quantizedAabbMin[0]+=m_heightStickWidth/2-1;
    244                         quantizedAabbMax[0]+=m_heightStickWidth/2+1;
    245                         quantizedAabbMin[2]+=m_heightStickLength/2-1;
    246                         quantizedAabbMax[2]+=m_heightStickLength/2+1;
    247 
    248326                        if (quantizedAabbMin[0]>startX)
    249327                                startX = quantizedAabbMin[0];
     
    258336        case 2:
    259337                {
    260                         quantizedAabbMin[0]+=m_heightStickWidth/2-1;
    261                         quantizedAabbMax[0]+=m_heightStickWidth/2+1;
    262                         quantizedAabbMin[1]+=m_heightStickLength/2-1;
    263                         quantizedAabbMax[1]+=m_heightStickLength/2+1;
    264 
    265338                        if (quantizedAabbMin[0]>startX)
    266339                                startX = quantizedAabbMin[0];
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btHeightfieldTerrainShape.h

    r2192 r2430  
    1919#include "btConcaveShape.h"
    2020
    21 ///The btHeightfieldTerrainShape simulates a 2D heightfield terrain collision shape. You can also use the more general btBvhTriangleMeshShape instead.
    22 ///An example implementation of btHeightfieldTerrainShape is provided in Demos/VehicleDemo/VehicleDemo.cpp
     21///btHeightfieldTerrainShape simulates a 2D heightfield terrain
     22/**
     23  The caller is responsible for maintaining the heightfield array; this
     24  class does not make a copy.
     25
     26  The heightfield can be dynamic so long as the min/max height values
     27  capture the extremes (heights must always be in that range).
     28
     29  The local origin of the heightfield is assumed to be the exact
     30  center (as determined by width and length and height, with each
     31  axis multiplied by the localScaling).
     32
     33  Most (but not all) rendering and heightfield libraries assume upAxis = 1
     34  (that is, the y-axis is "up").  This class allows any of the 3 coordinates
     35  to be "up".  Make sure your choice of axis is consistent with your rendering
     36  system.
     37
     38  The heightfield heights are determined from the data type used for the
     39  heightfieldData array. 
     40
     41   - PHY_UCHAR: height at a point is the uchar value at the
     42       grid point, multipled by heightScale.  uchar isn't recommended
     43       because of its inability to deal with negative values, and
     44       low resolution (8-bit).
     45
     46   - PHY_SHORT: height at a point is the short int value at that grid
     47       point, multipled by heightScale.
     48
     49   - PHY_FLOAT: height at a point is the float value at that grid
     50       point.  heightScale is ignored when using the float heightfield
     51       data type.
     52
     53  Whatever the caller specifies as minHeight and maxHeight will be honored.
     54  The class will not inspect the heightfield to discover the actual minimum
     55  or maximum heights.  These values are used to determine the heightfield's
     56  axis-aligned bounding box, multiplied by localScaling.
     57
     58  For usage and testing see the TerrainDemo.
     59 */
    2360class btHeightfieldTerrainShape : public btConcaveShape
    2461{
     
    2663        btVector3       m_localAabbMin;
    2764        btVector3       m_localAabbMax;
    28        
     65        btVector3       m_localOrigin;
     66
    2967        ///terrain data
    3068        int     m_heightStickWidth;
    3169        int m_heightStickLength;
     70        btScalar        m_minHeight;
    3271        btScalar        m_maxHeight;
    3372        btScalar m_width;
    3473        btScalar m_length;
     74        btScalar m_heightScale;
    3575        union
    3676        {
    3777                unsigned char*  m_heightfieldDataUnsignedChar;
     78                short*          m_heightfieldDataShort;
    3879                btScalar*                       m_heightfieldDataFloat;
    3980                void*                   m_heightfieldDataUnknown;
    4081        };
    41        
    42         bool    m_useFloatData;
     82
     83        PHY_ScalarType  m_heightDataType;       
    4384        bool    m_flipQuadEdges;
    4485  bool  m_useDiamondSubdivision;
     
    5293        void            getVertex(int x,int y,btVector3& vertex) const;
    5394
    54         inline bool testQuantizedAabbAgainstQuantizedAabb(int* aabbMin1, int* aabbMax1,const  int* aabbMin2,const  int* aabbMax2) const
    55         {
    56                 bool overlap = true;
    57                 overlap = (aabbMin1[0] > aabbMax2[0] || aabbMax1[0] < aabbMin2[0]) ? false : overlap;
    58                 overlap = (aabbMin1[2] > aabbMax2[2] || aabbMax1[2] < aabbMin2[2]) ? false : overlap;
    59                 overlap = (aabbMin1[1] > aabbMax2[1] || aabbMax1[1] < aabbMin2[1]) ? false : overlap;
    60                 return overlap;
    61         }
     95
     96
     97        /// protected initialization
     98        /**
     99          Handles the work of constructors so that public constructors can be
     100          backwards-compatible without a lot of copy/paste.
     101         */
     102        void initialize(int heightStickWidth, int heightStickLength,
     103                        void* heightfieldData, btScalar heightScale,
     104                        btScalar minHeight, btScalar maxHeight, int upAxis,
     105                        PHY_ScalarType heightDataType, bool flipQuadEdges);
    62106
    63107public:
    64         btHeightfieldTerrainShape(int heightStickWidth,int heightStickHeight,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
     108        /// preferred constructor
     109        /**
     110          This constructor supports a range of heightfield
     111          data types, and allows for a non-zero minimum height value.
     112          heightScale is needed for any integer-based heightfield data types.
     113         */
     114        btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,
     115                                  void* heightfieldData, btScalar heightScale,
     116                                  btScalar minHeight, btScalar maxHeight,
     117                                  int upAxis, PHY_ScalarType heightDataType,
     118                                  bool flipQuadEdges);
     119
     120        /// legacy constructor
     121        /**
     122          The legacy constructor assumes the heightfield has a minimum height
     123          of zero.  Only unsigned char or floats are supported.  For legacy
     124          compatibility reasons, heightScale is calculated as maxHeight / 65535
     125          (and is only used when useFloatData = false).
     126         */
     127        btHeightfieldTerrainShape(int heightStickWidth,int heightStickLength,void* heightfieldData, btScalar maxHeight,int upAxis,bool useFloatData,bool flipQuadEdges);
    65128
    66129        virtual ~btHeightfieldTerrainShape();
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btMinkowskiSumShape.cpp

    r2192 r2430  
    3636void    btMinkowskiSumShape::batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const
    3737{
    38         //todo: could make recursive use of batching. probably this shape is not used frequently.
     38        ///@todo: could make recursive use of batching. probably this shape is not used frequently.
    3939        for (int i=0;i<numVectors;i++)
    4040        {
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btOptimizedBvh.cpp

    r2192 r2430  
    320320                                       
    321321                                        int graphicsindex = indicestype==PHY_SHORT?((unsigned short*)gfxbase)[j]:gfxbase[j];
    322                                         btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
    323 #ifdef DEBUG_PATCH_COLORS
    324                                         btVector3 mycolor = color[index&3];
    325                                         graphicsbase[8] = mycolor.getX();
    326                                         graphicsbase[9] = mycolor.getY();
    327                                         graphicsbase[10] = mycolor.getZ();
    328 #endif //DEBUG_PATCH_COLORS
    329 
    330 
    331                                         triangleVerts[j] = btVector3(
    332                                                 graphicsbase[0]*meshScaling.getX(),
    333                                                 graphicsbase[1]*meshScaling.getY(),
    334                                                 graphicsbase[2]*meshScaling.getZ());
     322                                        if (type == PHY_FLOAT)
     323                                        {
     324                                                float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
     325                                                triangleVerts[j] = btVector3(
     326                                                        graphicsbase[0]*meshScaling.getX(),
     327                                                        graphicsbase[1]*meshScaling.getY(),
     328                                                        graphicsbase[2]*meshScaling.getZ());
     329                                        }
     330                                        else
     331                                        {
     332                                                double* graphicsbase = (double*)(vertexbase+graphicsindex*stride);
     333                                                triangleVerts[j] = btVector3( btScalar(graphicsbase[0]*meshScaling.getX()), btScalar(graphicsbase[1]*meshScaling.getY()), btScalar(graphicsbase[2]*meshScaling.getZ()));
     334                                        }
    335335                                }
    336336
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.cpp

    r2192 r2430  
    1616#include "BulletCollision/CollisionShapes/btPolyhedralConvexShape.h"
    1717
    18 btPolyhedralConvexShape::btPolyhedralConvexShape()
    19 :btConvexInternalShape(),
     18btPolyhedralConvexShape::btPolyhedralConvexShape() :btConvexInternalShape(),
    2019m_localAabbMin(1,1,1),
    2120m_localAabbMax(-1,-1,-1),
     
    2524
    2625}
    27 
    2826
    2927
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btPolyhedralConvexShape.h

    r2192 r2430  
    1717#define BU_SHAPE
    1818
    19 #include "LinearMath/btPoint3.h"
    2019#include "LinearMath/btMatrix3x3.h"
    2120#include "LinearMath/btAabbUtil2.h"
     
    3231        bool            m_isLocalAabbValid;
    3332
    34         btPolyhedralConvexShape();
    3533public:
    3634
    37        
     35        btPolyhedralConvexShape();
    3836
    3937        //brute force implementations
     38
    4039        virtual btVector3       localGetSupportingVertexWithoutMargin(const btVector3& vec)const;
    4140        virtual void    batchedUnitVectorGetSupportingVertexWithoutMargin(const btVector3* vectors,btVector3* supportVerticesOut,int numVectors) const;
     41
    4242       
    4343        virtual void    calculateLocalInertia(btScalar mass,btVector3& inertia) const;
    4444
     45
     46        void setCachedLocalAabb (const btVector3& aabbMin, const btVector3& aabbMax)
     47        {
     48                m_isLocalAabbValid = true;
     49                m_localAabbMin = aabbMin;
     50                m_localAabbMax = aabbMax;
     51        }
     52
     53        inline void getCachedLocalAabb (btVector3& aabbMin, btVector3& aabbMax) const
     54        {
     55                btAssert(m_isLocalAabbValid);
     56                aabbMin = m_localAabbMin;
     57                aabbMax = m_localAabbMax;
     58        }
    4559
    4660        inline void getNonvirtualAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax, btScalar margin) const
     
    6175        virtual int     getNumVertices() const = 0 ;
    6276        virtual int getNumEdges() const = 0;
    63         virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const = 0;
    64         virtual void getVertex(int i,btPoint3& vtx) const = 0;
     77        virtual void getEdge(int i,btVector3& pa,btVector3& pb) const = 0;
     78        virtual void getVertex(int i,btVector3& vtx) const = 0;
    6579        virtual int     getNumPlanes() const = 0;
    66         virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i ) const = 0;
     80        virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i ) const = 0;
    6781//      virtual int getIndex(int i) const = 0 ;
    6882
    69         virtual bool isInside(const btPoint3& pt,btScalar tolerance) const = 0;
     83        virtual bool isInside(const btVector3& pt,btScalar tolerance) const = 0;
    7084       
    7185        /// optional Hull is for optional Separating Axis Test Hull collision detection, see Hull.cpp
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.cpp

    r2192 r2430  
    1616#include "btScaledBvhTriangleMeshShape.h"
    1717
    18 btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,btVector3 localScaling)
     18btScaledBvhTriangleMeshShape::btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,const btVector3& localScaling)
    1919:m_localScaling(localScaling),m_bvhTriMeshShape(childShape)
    2020{
     
    3535public:
    3636
    37         btScaledTriangleCallback(btTriangleCallback* originalCallback,btVector3 localScaling)
     37        btScaledTriangleCallback(btTriangleCallback* originalCallback,const btVector3& localScaling)
    3838                :m_originalCallback(originalCallback),
    3939                m_localScaling(localScaling)
     
    9494        btMatrix3x3 abs_b = trans.getBasis().absolute(); 
    9595
    96         btPoint3 center = trans(localCenter);
     96        btVector3 center = trans(localCenter);
    9797
    9898        btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h

    r2192 r2430  
    3333
    3434
    35         btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,btVector3 localScaling);
     35        btScaledBvhTriangleMeshShape(btBvhTriangleMeshShape* childShape,const btVector3& localScaling);
    3636
    3737        virtual ~btScaledBvhTriangleMeshShape();
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.cpp

    r2192 r2430  
    1818
    1919#include "LinearMath/btQuaternion.h"
    20 
    21 
    22 btSphereShape ::btSphereShape (btScalar radius) : btConvexInternalShape ()
    23 {
    24         m_shapeType = SPHERE_SHAPE_PROXYTYPE;
    25         m_implicitShapeDimensions.setX(radius);
    26         m_collisionMargin = radius;
    27 }
    2820
    2921btVector3       btSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec)const
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btSphereShape.h

    r2192 r2430  
    2828        BT_DECLARE_ALIGNED_ALLOCATOR();
    2929
    30         btSphereShape (btScalar radius);
    31        
     30        btSphereShape (btScalar radius) : btConvexInternalShape ()
     31        {
     32                m_shapeType = SPHERE_SHAPE_PROXYTYPE;
     33                m_implicitShapeDimensions.setX(radius);
     34                m_collisionMargin = radius;
     35        }
    3236       
    3337        virtual btVector3       localGetSupportingVertex(const btVector3& vec)const;
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btStridingMeshInterface.h

    r2192 r2430  
    1919#include "LinearMath/btVector3.h"
    2020#include "btTriangleCallback.h"
     21#include "btConcaveShape.h"
    2122
    22 /// PHY_ScalarType enumerates possible scalar types.
    23 /// See the btStridingMeshInterface for its use
    24 typedef enum PHY_ScalarType {
    25         PHY_FLOAT,
    26         PHY_DOUBLE,
    27         PHY_INTEGER,
    28         PHY_SHORT,
    29         PHY_FIXEDPOINT88
    30 } PHY_ScalarType;
     23
    3124
    3225///     The btStridingMeshInterface is the interface class for high performance generic access to triangle meshes, used in combination with btBvhTriangleMeshShape and some other collision shapes.
     
    7871
    7972                virtual bool    hasPremadeAabb() const { return false; }
    80                 virtual void    setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const {}
    81                 virtual void    getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const {}
     73                virtual void    setPremadeAabb(const btVector3& aabbMin, const btVector3& aabbMax ) const
     74                {
     75                        (void) aabbMin;
     76                        (void) aabbMax;
     77                }
     78                virtual void    getPremadeAabb(btVector3* aabbMin, btVector3* aabbMax ) const
     79        {
     80            (void) aabbMin;
     81            (void) aabbMax;
     82        }
    8283
    8384                const btVector3&        getScaling() const {
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.cpp

    r2192 r2430  
    2323}
    2424
    25 btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0) : btPolyhedralConvexShape (),
    26 m_numVertices(0)
    27 {
    28         m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
    29         addVertex(pt0);
    30 }
    31 
    32 btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1) : btPolyhedralConvexShape (),
     25btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0) : btPolyhedralConvexShape (),
     26m_numVertices(0)
     27{
     28        m_shapeType = TETRAHEDRAL_SHAPE_PROXYTYPE;
     29        addVertex(pt0);
     30}
     31
     32btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1) : btPolyhedralConvexShape (),
    3333m_numVertices(0)
    3434{
     
    3838}
    3939
    40 btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2) : btPolyhedralConvexShape (),
     40btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2) : btPolyhedralConvexShape (),
    4141m_numVertices(0)
    4242{
     
    4747}
    4848
    49 btBU_Simplex1to4::btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2,const btPoint3& pt3) : btPolyhedralConvexShape (),
     49btBU_Simplex1to4::btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3) : btPolyhedralConvexShape (),
    5050m_numVertices(0)
    5151{
     
    6161
    6262
    63 void btBU_Simplex1to4::addVertex(const btPoint3& pt)
     63void btBU_Simplex1to4::addVertex(const btVector3& pt)
    6464{
    6565        m_vertices[m_numVertices++] = pt;
     
    9393}
    9494
    95 void btBU_Simplex1to4::getEdge(int i,btPoint3& pa,btPoint3& pb) const
     95void btBU_Simplex1to4::getEdge(int i,btVector3& pa,btVector3& pb) const
    9696{
    9797       
     
    157157}
    158158
    159 void btBU_Simplex1to4::getVertex(int i,btPoint3& vtx) const
     159void btBU_Simplex1to4::getVertex(int i,btVector3& vtx) const
    160160{
    161161        vtx = m_vertices[i];
     
    184184
    185185
    186 void btBU_Simplex1to4::getPlane(btVector3&, btPoint3& ,int ) const
     186void btBU_Simplex1to4::getPlane(btVector3&, btVector3& ,int ) const
    187187{
    188188       
     
    194194}
    195195
    196 bool btBU_Simplex1to4::isInside(const btPoint3& ,btScalar ) const
     196bool btBU_Simplex1to4::isInside(const btVector3& ,btScalar ) const
    197197{
    198198        return false;
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTetrahedronShape.h

    r2192 r2430  
    2828
    2929        int     m_numVertices;
    30         btPoint3        m_vertices[4];
     30        btVector3       m_vertices[4];
    3131
    3232public:
    3333        btBU_Simplex1to4();
    3434
    35         btBU_Simplex1to4(const btPoint3& pt0);
    36         btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1);
    37         btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2);
    38         btBU_Simplex1to4(const btPoint3& pt0,const btPoint3& pt1,const btPoint3& pt2,const btPoint3& pt3);
     35        btBU_Simplex1to4(const btVector3& pt0);
     36        btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1);
     37        btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2);
     38        btBU_Simplex1to4(const btVector3& pt0,const btVector3& pt1,const btVector3& pt2,const btVector3& pt3);
    3939
    4040   
     
    4646
    4747
    48         void addVertex(const btPoint3& pt);
     48        void addVertex(const btVector3& pt);
    4949
    5050        //PolyhedralConvexShape interface
     
    5454        virtual int getNumEdges() const;
    5555
    56         virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const;
     56        virtual void getEdge(int i,btVector3& pa,btVector3& pb) const;
    5757       
    58         virtual void getVertex(int i,btPoint3& vtx) const;
     58        virtual void getVertex(int i,btVector3& vtx) const;
    5959
    6060        virtual int     getNumPlanes() const;
    6161
    62         virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i) const;
     62        virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i) const;
    6363
    6464        virtual int getIndex(int i) const;
    6565
    66         virtual bool isInside(const btPoint3& pt,btScalar tolerance) const;
     66        virtual bool isInside(const btVector3& pt,btScalar tolerance) const;
    6767
    6868
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleBuffer.h

    r2192 r2430  
    2929};
    3030
    31 ///btTriangleBuffer can be useful to collect and store overlapping triangles between AABB and concave objects that support 'processAllTriangles'
     31///The btTriangleBuffer callback can be useful to collect and store overlapping triangles between AABB and concave objects that support 'processAllTriangles'
    3232///Example usage of this class:
    3333///                     btTriangleBuffer        triBuf;
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.cpp

    r2192 r2430  
    7575}
    7676
    77 int     btTriangleMesh::findOrAddVertex(const btVector3& vertex)
     77
     78int     btTriangleMesh::findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices)
    7879{
    7980        //return index of new/existing vertex
    80         //todo: could use acceleration structure for this
     81        ///@todo: could use acceleration structure for this
    8182        if (m_use4componentVertices)
    8283        {
    83                 for (int i=0;i< m_4componentVertices.size();i++)
    84                 {
    85                         if ((m_4componentVertices[i]-vertex).length2() <= m_weldingThreshold)
     84                if (removeDuplicateVertices)
    8685                        {
    87                                 return i;
     86                        for (int i=0;i< m_4componentVertices.size();i++)
     87                        {
     88                                if ((m_4componentVertices[i]-vertex).length2() <= m_weldingThreshold)
     89                                {
     90                                        return i;
     91                                }
    8892                        }
    8993                }
     
    97101        {
    98102               
    99                 for (int i=0;i< m_3componentVertices.size();i+=3)
     103                if (removeDuplicateVertices)
    100104                {
    101                         btVector3 vtx(m_3componentVertices[i],m_3componentVertices[i+1],m_3componentVertices[i+2]);
    102                         if ((vtx-vertex).length2() <= m_weldingThreshold)
     105                        for (int i=0;i< m_3componentVertices.size();i+=3)
    103106                        {
    104                                 return i/3;
     107                                btVector3 vtx(m_3componentVertices[i],m_3componentVertices[i+1],m_3componentVertices[i+2]);
     108                                if ((vtx-vertex).length2() <= m_weldingThreshold)
     109                                {
     110                                        return i/3;
     111                                }
    105112                        }
    106                 }
     113        }
    107114                m_3componentVertices.push_back(vertex.getX());
    108115                m_3componentVertices.push_back(vertex.getY());
     
    115122}
    116123               
    117 void    btTriangleMesh::addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2)
     124void    btTriangleMesh::addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2,bool removeDuplicateVertices)
    118125{
    119126        m_indexedMeshes[0].m_numTriangles++;
    120                
    121         addIndex(findOrAddVertex(vertex0));
    122         addIndex(findOrAddVertex(vertex1));
    123         addIndex(findOrAddVertex(vertex2));
     127        addIndex(findOrAddVertex(vertex0,removeDuplicateVertices));
     128        addIndex(findOrAddVertex(vertex1,removeDuplicateVertices));
     129        addIndex(findOrAddVertex(vertex2,removeDuplicateVertices));
    124130}
    125131
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMesh.h

    r2192 r2430  
    2626///If you want to share triangle/index data between graphics mesh and collision mesh (btBvhTriangleMeshShape), you can directly use btTriangleIndexVertexArray or derive your own class from btStridingMeshInterface.
    2727///Performance of btTriangleMesh and btTriangleIndexVertexArray used in a btBvhTriangleMeshShape is the same.
    28 ///It has a brute-force option to weld together closeby vertices.
    2928class btTriangleMesh : public btTriangleIndexVertexArray
    3029{
     
    4342                btTriangleMesh (bool use32bitIndices=true,bool use4componentVertices=true);
    4443
    45                 int             findOrAddVertex(const btVector3& vertex);
     44                int             findOrAddVertex(const btVector3& vertex, bool removeDuplicateVertices);
    4645                void    addIndex(int index);
    4746
     
    5554                        return m_use4componentVertices;
    5655                }
    57                
    58                 void    addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2);
     56                ///By default addTriangle won't search for duplicate vertices, because the search is very slow for large triangle meshes.
     57                ///In general it is better to directly use btTriangleIndexVertexArray instead.
     58                void    addTriangle(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2, bool removeDuplicateVertices=false);
    5959               
    6060                int getNumTriangles() const;
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleMeshShape.cpp

    r2192 r2430  
    5454        btMatrix3x3 abs_b = trans.getBasis().absolute(); 
    5555
    56         btPoint3 center = trans(localCenter);
     56        btVector3 center = trans(localCenter);
    5757
    5858        btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
  • code/branches/physics/src/bullet/BulletCollision/CollisionShapes/btTriangleShape.h

    r2192 r2430  
    4747        }
    4848       
    49         virtual void getEdge(int i,btPoint3& pa,btPoint3& pb) const
     49        virtual void getEdge(int i,btVector3& pa,btVector3& pb) const
    5050        {
    5151                getVertex(i,pa);
     
    8989
    9090
    91         virtual void getPlane(btVector3& planeNormal,btPoint3& planeSupport,int i) const
     91        virtual void getPlane(btVector3& planeNormal,btVector3& planeSupport,int i) const
    9292        {
    9393                getPlaneEquation(i,planeNormal,planeSupport);
     
    105105        }
    106106
    107         virtual void getPlaneEquation(int i, btVector3& planeNormal,btPoint3& planeSupport) const
     107        virtual void getPlaneEquation(int i, btVector3& planeNormal,btVector3& planeSupport) const
    108108        {
    109109                (void)i;
     
    119119        }
    120120
    121                 virtual bool isInside(const btPoint3& pt,btScalar tolerance) const
     121                virtual bool isInside(const btVector3& pt,btScalar tolerance) const
    122122        {
    123123                btVector3 normal;
     
    133133                        for (i=0;i<3;i++)
    134134                        {
    135                                 btPoint3 pa,pb;
     135                                btVector3 pa,pb;
    136136                                getEdge(i,pa,pb);
    137137                                btVector3 edge = pb-pa;
Note: See TracChangeset for help on using the changeset viewer.