Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Merged revisions 7978 - 8096 from kicklib to kicklib2.

Location:
code/branches/kicklib2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/kicklib2

  • code/branches/kicklib2/src/external/bullet/BulletCollision/CollisionShapes/btMultiSphereShape.cpp

    r5781 r8284  
    11/*
    22Bullet Continuous Collision Detection and Physics Library
    3 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
     3Copyright (c) 2003-2009 Erwin Coumans  http://bulletphysics.org
    44
    55This software is provided 'as-is', without any express or implied warranty.
     
    1414*/
    1515
     16
     17
    1618#include "btMultiSphereShape.h"
    1719#include "BulletCollision/CollisionShapes/btCollisionMargin.h"
    1820#include "LinearMath/btQuaternion.h"
     21#include "LinearMath/btSerializer.h"
    1922
    20 btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres)
    21 :btConvexInternalShape (), m_inertiaHalfExtents(inertiaHalfExtents)
     23btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres)
     24:btConvexInternalAabbCachingShape ()
    2225{
    2326        m_shapeType = MULTI_SPHERE_SHAPE_PROXYTYPE;
    24         btScalar startMargin = btScalar(1e30);
     27        //btScalar startMargin = btScalar(BT_LARGE_FLOAT);
    2528
    26         m_numSpheres = numSpheres;
    27         for (int i=0;i<m_numSpheres;i++)
     29        m_localPositionArray.resize(numSpheres);
     30        m_radiArray.resize(numSpheres);
     31        for (int i=0;i<numSpheres;i++)
    2832        {
    29                 m_localPositions[i] = positions[i];
    30                 m_radi[i] = radi[i];
    31                 if (radi[i] < startMargin)
    32                         startMargin = radi[i];
     33                m_localPositionArray[i] = positions[i];
     34                m_radiArray[i] = radi[i];
     35               
    3336        }
    34         setMargin(startMargin);
     37
     38        recalcLocalAabb();
    3539
    3640}
    37 
    38 
    3941
    4042 
     
    4446        btVector3 supVec(0,0,0);
    4547
    46         btScalar maxDot(btScalar(-1e30));
     48        btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
    4749
    4850
     
    6163        btScalar newDot;
    6264
    63         const btVector3* pos = &m_localPositions[0];
    64         const btScalar* rad = &m_radi[0];
     65        const btVector3* pos = &m_localPositionArray[0];
     66        const btScalar* rad = &m_radiArray[0];
     67        int numSpheres = m_localPositionArray.size();
    6568
    66         for (i=0;i<m_numSpheres;i++)
     69        for (i=0;i<numSpheres;i++)
    6770        {
    6871                vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
     
    8689        for (int j=0;j<numVectors;j++)
    8790        {
    88                 btScalar maxDot(btScalar(-1e30));
     91                btScalar maxDot(btScalar(-BT_LARGE_FLOAT));
    8992
    9093                const btVector3& vec = vectors[j];
     
    9396                btScalar newDot;
    9497
    95                 const btVector3* pos = &m_localPositions[0];
    96                 const btScalar* rad = &m_radi[0];
    97 
    98                 for (int i=0;i<m_numSpheres;i++)
     98                const btVector3* pos = &m_localPositionArray[0];
     99                const btScalar* rad = &m_radiArray[0];
     100                int numSpheres = m_localPositionArray.size();
     101                for (int i=0;i<numSpheres;i++)
    99102                {
    100103                        vtx = (*pos) +vec*m_localScaling*(*rad) - vec * getMargin();
     
    122125        //as an approximation, take the inertia of the box that bounds the spheres
    123126
    124         btTransform ident;
    125         ident.setIdentity();
    126 //      btVector3 aabbMin,aabbMax;
     127        btVector3 localAabbMin,localAabbMax;
     128        getCachedLocalAabb(localAabbMin,localAabbMax);
     129        btVector3 halfExtents = (localAabbMax-localAabbMin)*btScalar(0.5);
    127130
    128 //      getAabb(ident,aabbMin,aabbMax);
     131        btScalar lx=btScalar(2.)*(halfExtents.x());
     132        btScalar ly=btScalar(2.)*(halfExtents.y());
     133        btScalar lz=btScalar(2.)*(halfExtents.z());
    129134
    130         btVector3 halfExtents = m_inertiaHalfExtents;//(aabbMax - aabbMin)* btScalar(0.5);
    131 
    132         btScalar margin = CONVEX_DISTANCE_MARGIN;
    133 
    134         btScalar lx=btScalar(2.)*(halfExtents[0]+margin);
    135         btScalar ly=btScalar(2.)*(halfExtents[1]+margin);
    136         btScalar lz=btScalar(2.)*(halfExtents[2]+margin);
    137         const btScalar x2 = lx*lx;
    138         const btScalar y2 = ly*ly;
    139         const btScalar z2 = lz*lz;
    140         const btScalar scaledmass = mass * btScalar(.08333333);
    141 
    142         inertia[0] = scaledmass * (y2+z2);
    143         inertia[1] = scaledmass * (x2+z2);
    144         inertia[2] = scaledmass * (x2+y2);
     135        inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz),
     136                                        mass/(btScalar(12.0)) * (lx*lx + lz*lz),
     137                                        mass/(btScalar(12.0)) * (lx*lx + ly*ly));
    145138
    146139}
    147140
    148141
     142///fills the dataBuffer and returns the struct name (and 0 on failure)
     143const char*     btMultiSphereShape::serialize(void* dataBuffer, btSerializer* serializer) const
     144{
     145        btMultiSphereShapeData* shapeData = (btMultiSphereShapeData*) dataBuffer;
     146        btConvexInternalShape::serialize(&shapeData->m_convexInternalShapeData, serializer);
    149147
     148        int numElem = m_localPositionArray.size();
     149        shapeData->m_localPositionArrayPtr = numElem ? (btPositionAndRadius*)serializer->getUniquePointer((void*)&m_localPositionArray[0]):  0;
     150       
     151        shapeData->m_localPositionArraySize = numElem;
     152        if (numElem)
     153        {
     154                btChunk* chunk = serializer->allocate(sizeof(btPositionAndRadius),numElem);
     155                btPositionAndRadius* memPtr = (btPositionAndRadius*)chunk->m_oldPtr;
     156                for (int i=0;i<numElem;i++,memPtr++)
     157                {
     158                        m_localPositionArray[i].serializeFloat(memPtr->m_pos);
     159                        memPtr->m_radius = float(m_radiArray[i]);
     160                }
     161                serializer->finalizeChunk(chunk,"btPositionAndRadius",BT_ARRAY_CODE,(void*)&m_localPositionArray[0]);
     162        }
     163       
     164        return "btMultiSphereShapeData";
     165}
     166
     167
Note: See TracChangeset for help on using the changeset viewer.