Allocate large arrays of btVector3s on the heap instead of the stack. Fixes Issue #193
This commit is contained in:
@@ -913,6 +913,8 @@ btHfFluidColumnRigidBodyCallback::btHfFluidColumnRigidBodyCallback (btRigidBody*
|
|||||||
m_density = density;
|
m_density = density;
|
||||||
m_floatyness = floatyness;
|
m_floatyness = floatyness;
|
||||||
m_numVoxels = m_buoyantShape->getNumVoxels ();
|
m_numVoxels = m_buoyantShape->getNumVoxels ();
|
||||||
|
m_voxelPositionsXformed = (btVector3*)btAlignedAlloc(sizeof(btVector3)*m_numVoxels, 16);
|
||||||
|
m_voxelSubmerged = (bool*)btAlignedAlloc(sizeof(bool)*m_numVoxels, 16);
|
||||||
for (int i = 0; i < m_numVoxels; i++)
|
for (int i = 0; i < m_numVoxels; i++)
|
||||||
{
|
{
|
||||||
btVector3 p = m_buoyantShape->getVoxelPositionsArray()[i];
|
btVector3 p = m_buoyantShape->getVoxelPositionsArray()[i];
|
||||||
@@ -923,6 +925,14 @@ btHfFluidColumnRigidBodyCallback::btHfFluidColumnRigidBodyCallback (btRigidBody*
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btHfFluidColumnRigidBodyCallback::~btHfFluidColumnRigidBodyCallback ()
|
||||||
|
{
|
||||||
|
if (m_voxelPositionsXformed)
|
||||||
|
btAlignedFree (m_voxelPositionsXformed);
|
||||||
|
if (m_voxelSubmerged)
|
||||||
|
btAlignedFree (m_voxelSubmerged);
|
||||||
|
}
|
||||||
|
|
||||||
static bool sphereVsAABB (const btVector3& aabbMin, const btVector3& aabbMax, const btVector3& sphereCenter, const btScalar sphereRadius)
|
static bool sphereVsAABB (const btVector3& aabbMin, const btVector3& aabbMax, const btVector3& sphereCenter, const btScalar sphereRadius)
|
||||||
{
|
{
|
||||||
btScalar totalDistance = 0;
|
btScalar totalDistance = 0;
|
||||||
|
|||||||
@@ -207,8 +207,8 @@ protected:
|
|||||||
btHfFluidBuoyantConvexShape* m_buoyantShape;
|
btHfFluidBuoyantConvexShape* m_buoyantShape;
|
||||||
btIDebugDraw* m_debugDraw;
|
btIDebugDraw* m_debugDraw;
|
||||||
int m_numVoxels;
|
int m_numVoxels;
|
||||||
btVector3 m_voxelPositionsXformed[32*32*32];
|
btVector3* m_voxelPositionsXformed;
|
||||||
bool m_voxelSubmerged[32*32*32];
|
bool* m_voxelSubmerged;
|
||||||
btVector3 m_aabbMin;
|
btVector3 m_aabbMin;
|
||||||
btVector3 m_aabbMax;
|
btVector3 m_aabbMax;
|
||||||
btScalar m_volume;
|
btScalar m_volume;
|
||||||
@@ -216,6 +216,7 @@ protected:
|
|||||||
btScalar m_floatyness;
|
btScalar m_floatyness;
|
||||||
public:
|
public:
|
||||||
btHfFluidColumnRigidBodyCallback (btRigidBody* rigidBody, btIDebugDraw* debugDraw, btScalar density, btScalar floatyness);
|
btHfFluidColumnRigidBodyCallback (btRigidBody* rigidBody, btIDebugDraw* debugDraw, btScalar density, btScalar floatyness);
|
||||||
|
~btHfFluidColumnRigidBodyCallback ();
|
||||||
bool processColumn (btHfFluid* fluid, int w, int l);
|
bool processColumn (btHfFluid* fluid, int w, int l);
|
||||||
btScalar getVolume () const { return m_volume; }
|
btScalar getVolume () const { return m_volume; }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,10 +15,18 @@ btHfFluidBuoyantConvexShape::btHfFluidBuoyantConvexShape (btConvexShape* convexS
|
|||||||
m_convexShape = convexShape;
|
m_convexShape = convexShape;
|
||||||
m_shapeType = HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE;
|
m_shapeType = HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE;
|
||||||
m_radius = btScalar(0.f);
|
m_radius = btScalar(0.f);
|
||||||
|
m_numVoxels = 0;
|
||||||
|
m_voxelPositions = NULL;
|
||||||
m_totalVolume = btScalar(0.0f);
|
m_totalVolume = btScalar(0.0f);
|
||||||
m_floatyness = btScalar(1.5f);
|
m_floatyness = btScalar(1.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
btHfFluidBuoyantConvexShape::~btHfFluidBuoyantConvexShape ()
|
||||||
|
{
|
||||||
|
if (m_voxelPositions)
|
||||||
|
btAlignedFree (m_voxelPositions);
|
||||||
|
}
|
||||||
|
|
||||||
void btHfFluidBuoyantConvexShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
|
void btHfFluidBuoyantConvexShape::getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const
|
||||||
{
|
{
|
||||||
return m_convexShape->getAabb (t, aabbMin, aabbMax);
|
return m_convexShape->getAabb (t, aabbMin, aabbMax);
|
||||||
@@ -128,6 +136,7 @@ void btHfFluidBuoyantConvexShape::generateShape (btScalar radius, btScalar gap)
|
|||||||
|
|
||||||
btVoronoiSimplexSolver simplexSolver;
|
btVoronoiSimplexSolver simplexSolver;
|
||||||
btSphereShape sphereShape(radius);
|
btSphereShape sphereShape(radius);
|
||||||
|
btVector3* voxelPositions = (btVector3*)btAlignedAlloc (sizeof(btVector3)*MAX_VOXEL_DIMENSION*MAX_VOXEL_DIMENSION*MAX_VOXEL_DIMENSION,16);
|
||||||
for (int i = 0; i < MAX_VOXEL_DIMENSION; i++)
|
for (int i = 0; i < MAX_VOXEL_DIMENSION; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < MAX_VOXEL_DIMENSION; j++)
|
for (int j = 0; j < MAX_VOXEL_DIMENSION; j++)
|
||||||
@@ -150,13 +159,19 @@ void btHfFluidBuoyantConvexShape::generateShape (btScalar radius, btScalar gap)
|
|||||||
|
|
||||||
if (intersect (&simplexSolver, T, sT, m_convexShape, &sphereShape))
|
if (intersect (&simplexSolver, T, sT, m_convexShape, &sphereShape))
|
||||||
{
|
{
|
||||||
m_voxelPositions[m_numVoxels] = point;
|
voxelPositions[m_numVoxels] = point;
|
||||||
m_numVoxels++;
|
m_numVoxels++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_voxelPositions = (btVector3*)btAlignedAlloc (sizeof(btVector3)*m_numVoxels, 16);
|
||||||
|
for (int i = 0; i < m_numVoxels;i++)
|
||||||
|
{
|
||||||
|
m_voxelPositions[i] = voxelPositions[i];
|
||||||
|
}
|
||||||
|
btAlignedFree (voxelPositions);
|
||||||
m_volumePerVoxel = btScalar(4.0f)/btScalar(3.0f)*SIMD_PI*radius*radius*radius;
|
m_volumePerVoxel = btScalar(4.0f)/btScalar(3.0f)*SIMD_PI*radius*radius*radius;
|
||||||
m_totalVolume = m_numVoxels * m_volumePerVoxel;
|
m_totalVolume = m_numVoxels * m_volumePerVoxel;
|
||||||
m_radius = radius;
|
m_radius = radius;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class btHfFluidBuoyantConvexShape : public btCollisionShape
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
btHfFluidBuoyantConvexShape (btConvexShape* convexShape);
|
btHfFluidBuoyantConvexShape (btConvexShape* convexShape);
|
||||||
|
~btHfFluidBuoyantConvexShape ();
|
||||||
void generateShape (btScalar radius, btScalar gap);
|
void generateShape (btScalar radius, btScalar gap);
|
||||||
|
|
||||||
btConvexShape* getConvexShape () { return m_convexShape; }
|
btConvexShape* getConvexShape () { return m_convexShape; }
|
||||||
@@ -39,7 +39,7 @@ protected:
|
|||||||
btScalar m_totalVolume;
|
btScalar m_totalVolume;
|
||||||
btScalar m_volumePerVoxel;
|
btScalar m_volumePerVoxel;
|
||||||
int m_numVoxels;
|
int m_numVoxels;
|
||||||
btVector3 m_voxelPositions[MAX_VOXEL_DIMENSION*MAX_VOXEL_DIMENSION*MAX_VOXEL_DIMENSION];
|
btVector3* m_voxelPositions;
|
||||||
btConvexShape* m_convexShape;
|
btConvexShape* m_convexShape;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user