Remove first argument from btMultiSphereShape, calculate local inertia approximation from aabb.
If user wants more accurate inertia tensor for multi-sphere shape, use btCompoundShape instead (amd btCompoundShape::calculatePrincipalAxisTransform) Thanks rcharlton for bringing this up. Erwin
This commit is contained in:
@@ -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 ();
|
||||
|
||||
@@ -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);
|
||||
@@ -39,8 +39,6 @@ btMultiSphereShape::btMultiSphereShape (const btVector3& inertiaHalfExtents,cons
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
btVector3 btMultiSphereShape::localGetSupportingVertexWithoutMargin(const btVector3& vec0)const
|
||||
{
|
||||
int i;
|
||||
@@ -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));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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<btVector3> m_localPositionArray;
|
||||
btAlignedObjectArray<btScalar> 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;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user