diff --git a/Demos/CharacterDemo/DynamicCharacterController.cpp b/Demos/CharacterDemo/DynamicCharacterController.cpp index abea84eb9..ce8ed96ef 100644 --- a/Demos/CharacterDemo/DynamicCharacterController.cpp +++ b/Demos/CharacterDemo/DynamicCharacterController.cpp @@ -33,7 +33,7 @@ void DynamicCharacterController::setup (btScalar height, btScalar width, btScala m_halfHeight = height/btScalar(2.0); - m_shape = new btMultiSphereShape (btVector3(width/btScalar(2.0), height/btScalar(2.0), width/btScalar(2.0)), &spherePositions[0], &sphereRadii[0], 2); + m_shape = new btMultiSphereShape (&spherePositions[0], &sphereRadii[0], 2); btTransform startTransform; startTransform.setIdentity (); diff --git a/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp b/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp index 7788f2d9c..baebfb092 100644 --- a/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp +++ b/src/BulletCollision/CollisionShapes/btMultiSphereShape.cpp @@ -19,8 +19,8 @@ subject to the following restrictions: #include "BulletCollision/CollisionShapes/btCollisionMargin.h" #include "LinearMath/btQuaternion.h" -btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres) -:btConvexInternalAabbCachingShape (), m_inertiaHalfExtents(inertiaHalfExtents) +btMultiSphereShape::btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres) +:btConvexInternalAabbCachingShape () { m_shapeType = MULTI_SPHERE_SHAPE_PROXYTYPE; btScalar startMargin = btScalar(BT_LARGE_FLOAT); @@ -38,8 +38,6 @@ btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,cons } - - btVector3 btMultiSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const { @@ -125,27 +123,17 @@ void btMultiSphereShape::calculateLocalInertia(btScalar mass,btVector3& inertia) { //as an approximation, take the inertia of the box that bounds the spheres - btTransform ident; - ident.setIdentity(); -// btVector3 aabbMin,aabbMax; + btVector3 localAabbMin,localAabbMax; + getCachedLocalAabb(localAabbMin,localAabbMax); + btVector3 halfExtents = (localAabbMax-localAabbMin)*btScalar(0.5); -// getAabb(ident,aabbMin,aabbMax); + btScalar lx=btScalar(2.)*(halfExtents.x()); + btScalar ly=btScalar(2.)*(halfExtents.y()); + btScalar lz=btScalar(2.)*(halfExtents.z()); - btVector3 halfExtents = m_inertiaHalfExtents;//(aabbMax - aabbMin)* btScalar(0.5); - - btScalar margin = CONVEX_DISTANCE_MARGIN; - - btScalar lx=btScalar(2.)*(halfExtents[0]+margin); - btScalar ly=btScalar(2.)*(halfExtents[1]+margin); - btScalar lz=btScalar(2.)*(halfExtents[2]+margin); - const btScalar x2 = lx*lx; - const btScalar y2 = ly*ly; - const btScalar z2 = lz*lz; - const btScalar scaledmass = mass * btScalar(.08333333); - - inertia[0] = scaledmass * (y2+z2); - inertia[1] = scaledmass * (x2+z2); - inertia[2] = scaledmass * (x2+y2); + inertia.setValue(mass/(btScalar(12.0)) * (ly*ly + lz*lz), + mass/(btScalar(12.0)) * (lx*lx + lz*lz), + mass/(btScalar(12.0)) * (lx*lx + ly*ly)); } diff --git a/src/BulletCollision/CollisionShapes/btMultiSphereShape.h b/src/BulletCollision/CollisionShapes/btMultiSphereShape.h index ae8e5c26f..f1c4cbf34 100644 --- a/src/BulletCollision/CollisionShapes/btMultiSphereShape.h +++ b/src/BulletCollision/CollisionShapes/btMultiSphereShape.h @@ -22,21 +22,15 @@ subject to the following restrictions: #include "LinearMath/btAabbUtil2.h" ///The btMultiSphereShape represents the convex hull of a collection of spheres. You can create special capsules or other smooth volumes. -///It is possible to animate the spheres for deformation. +///It is possible to animate the spheres for deformation, but call 'recalcLocalAabb' after changing any sphere position/radius class btMultiSphereShape : public btConvexInternalAabbCachingShape - { - - btAlignedObjectArray m_localPositionArray; btAlignedObjectArray m_radiArray; - btVector3 m_inertiaHalfExtents; - - - + public: - btMultiSphereShape (const btVector3& inertiaHalfExtents,const btVector3* positions,const btScalar* radi,int numSpheres); + btMultiSphereShape (const btVector3* positions,const btScalar* radi,int numSpheres); ///CollisionShape Interface virtual void calculateLocalInertia(btScalar mass,btVector3& inertia) const; diff --git a/src/BulletDynamics/Dynamics/Bullet-C-API.cpp b/src/BulletDynamics/Dynamics/Bullet-C-API.cpp index 56026bf39..32b63f195 100644 --- a/src/BulletDynamics/Dynamics/Bullet-C-API.cpp +++ b/src/BulletDynamics/Dynamics/Bullet-C-API.cpp @@ -181,12 +181,12 @@ plCollisionShapeHandle plNewBoxShape(plReal x, plReal y, plReal z) plCollisionShapeHandle plNewCapsuleShape(plReal radius, plReal height) { //capsule is convex hull of 2 spheres, so use btMultiSphereShape - btVector3 inertiaHalfExtents(radius,height,radius); + const int numSpheres = 2; btVector3 positions[numSpheres] = {btVector3(0,height,0),btVector3(0,-height,0)}; btScalar radi[numSpheres] = {radius,radius}; void* mem = btAlignedAlloc(sizeof(btMultiSphereShape),16); - return (plCollisionShapeHandle) new (mem)btMultiSphereShape(inertiaHalfExtents,positions,radi,numSpheres); + return (plCollisionShapeHandle) new (mem)btMultiSphereShape(positions,radi,numSpheres); } plCollisionShapeHandle plNewConeShape(plReal radius, plReal height) {