Apple contribution for OSX SSE and iOS NEON optimizations unit tests, thanks to Jordan Hubbard, Ian Ollmann and Hristo Hristov.
For OSX: cd build ./premake_osx xcode4 for iOS: cd build ./ios_build.sh ./ios_run.sh Also integrated the branches/StackAllocation to make it easier to multi-thread collision detection in the near future. It avoids changing the btCollisionObject while performing collision detection. As this is a large patch, some stuff might be temporarily broken, I'll keep an eye out on issues.
This commit is contained in:
@@ -31,7 +31,10 @@ public:
|
||||
~btHfFluidBuoyantConvexShape ();
|
||||
void generateShape (btScalar radius, btScalar gap);
|
||||
|
||||
btConvexShape* getConvexShape () { return m_convexShape; }
|
||||
const btConvexShape* getConvexShape () const
|
||||
{
|
||||
return m_convexShape;
|
||||
}
|
||||
|
||||
virtual void getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
|
||||
virtual void setMargin(btScalar margin);
|
||||
|
||||
@@ -25,50 +25,50 @@ Experimental Buoyancy fluid demo written by John McCutchan
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "btHfFluid.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
||||
|
||||
btHfFluidBuoyantShapeCollisionAlgorithm::btHfFluidBuoyantShapeCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
|
||||
: btCollisionAlgorithm(ci), m_convexConvexAlgorithm(NULL, ci, col0, col1, simplexSolver, pdSolver,0,0)
|
||||
btHfFluidBuoyantShapeCollisionAlgorithm::btHfFluidBuoyantShapeCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap,btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver)
|
||||
: btCollisionAlgorithm(ci), m_convexConvexAlgorithm(NULL, ci, col0Wrap, col1Wrap, simplexSolver, pdSolver,0,0)
|
||||
{
|
||||
m_collisionObject0 = col0;
|
||||
m_collisionObject1 = col1;
|
||||
m_collisionObject0 = col0Wrap->getCollisionObject();
|
||||
m_collisionObject1 = col1Wrap->getCollisionObject();
|
||||
}
|
||||
|
||||
btHfFluidBuoyantShapeCollisionAlgorithm::~btHfFluidBuoyantShapeCollisionAlgorithm()
|
||||
{
|
||||
}
|
||||
|
||||
void btHfFluidBuoyantShapeCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
void btHfFluidBuoyantShapeCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
{
|
||||
btHfFluidBuoyantConvexShape* tmpShape0 = (btHfFluidBuoyantConvexShape*)body0->getCollisionShape();
|
||||
btHfFluidBuoyantConvexShape* tmpShape1 = (btHfFluidBuoyantConvexShape*)body1->getCollisionShape();
|
||||
btConvexShape* convexShape0 = tmpShape0->getConvexShape();
|
||||
btConvexShape* convexShape1 = tmpShape1->getConvexShape();
|
||||
const btHfFluidBuoyantConvexShape* tmpShape0 = (const btHfFluidBuoyantConvexShape*)body0Wrap->getCollisionShape();
|
||||
const btHfFluidBuoyantConvexShape* tmpShape1 = (const btHfFluidBuoyantConvexShape*)body1Wrap->getCollisionShape();
|
||||
const btConvexShape* convexShape0 = tmpShape0->getConvexShape();
|
||||
const btConvexShape* convexShape1 = tmpShape1->getConvexShape();
|
||||
|
||||
body0->setCollisionShape (convexShape0);
|
||||
body1->setCollisionShape (convexShape1);
|
||||
//body0->setCollisionShape (convexShape0);
|
||||
//body1->setCollisionShape (convexShape1);
|
||||
|
||||
m_convexConvexAlgorithm.processCollision (body0, body1, dispatchInfo,resultOut);
|
||||
btCollisionObjectWrapper ob0(body0Wrap,convexShape0,body0Wrap->getCollisionObject(),body0Wrap->getWorldTransform());
|
||||
btCollisionObjectWrapper ob1(body1Wrap,convexShape1,body1Wrap->getCollisionObject(),body1Wrap->getWorldTransform());
|
||||
m_convexConvexAlgorithm.processCollision (&ob0, &ob1, dispatchInfo,resultOut);
|
||||
|
||||
body0->setCollisionShape (tmpShape0);
|
||||
body1->setCollisionShape (tmpShape1);
|
||||
|
||||
}
|
||||
|
||||
btScalar btHfFluidBuoyantShapeCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
{
|
||||
btAssert(0);
|
||||
|
||||
btHfFluidBuoyantConvexShape* tmpShape0 = (btHfFluidBuoyantConvexShape*)body0->getCollisionShape();
|
||||
btHfFluidBuoyantConvexShape* tmpShape1 = (btHfFluidBuoyantConvexShape*)body1->getCollisionShape();
|
||||
btConvexShape* convexShape0 = tmpShape0->getConvexShape();
|
||||
btConvexShape* convexShape1 = tmpShape1->getConvexShape();
|
||||
|
||||
body0->setCollisionShape (convexShape0);
|
||||
body1->setCollisionShape (convexShape1);
|
||||
const btConvexShape* convexShape0 = tmpShape0->getConvexShape();
|
||||
const btConvexShape* convexShape1 = tmpShape1->getConvexShape();
|
||||
|
||||
|
||||
btScalar toi = btScalar(0.0f);
|
||||
|
||||
toi = m_convexConvexAlgorithm.calculateTimeOfImpact (body0, body1, dispatchInfo, resultOut);
|
||||
|
||||
body0->setCollisionShape (tmpShape0);
|
||||
body1->setCollisionShape (tmpShape1);
|
||||
|
||||
|
||||
return toi;
|
||||
}
|
||||
|
||||
@@ -38,17 +38,17 @@ class btSimplexSolverInterface;
|
||||
/// btHfFluidBuoyantShapeCollisionAlgorithm provides collision detection between btHfFluidBuoyantConvexShape and btHfFluidBuoyantConvexShape
|
||||
class btHfFluidBuoyantShapeCollisionAlgorithm : public btCollisionAlgorithm
|
||||
{
|
||||
btCollisionObject* m_collisionObject0;
|
||||
btCollisionObject* m_collisionObject1;
|
||||
const btCollisionObject* m_collisionObject0;
|
||||
const btCollisionObject* m_collisionObject1;
|
||||
|
||||
btConvexConvexAlgorithm m_convexConvexAlgorithm;
|
||||
public:
|
||||
|
||||
btHfFluidBuoyantShapeCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver);
|
||||
btHfFluidBuoyantShapeCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap, btSimplexSolverInterface* simplexSolver, btConvexPenetrationDepthSolver* pdSolver);
|
||||
|
||||
virtual ~btHfFluidBuoyantShapeCollisionAlgorithm();
|
||||
|
||||
virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
@@ -70,15 +70,15 @@ public:
|
||||
}
|
||||
|
||||
virtual ~CreateFunc() {}
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
||||
{
|
||||
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btHfFluidBuoyantShapeCollisionAlgorithm));
|
||||
if (!m_swapped)
|
||||
{
|
||||
return new(mem) btHfFluidBuoyantShapeCollisionAlgorithm(ci,body0,body1, m_simplexSolver, m_pdSolver);
|
||||
return new(mem) btHfFluidBuoyantShapeCollisionAlgorithm(ci,body0Wrap,body1Wrap, m_simplexSolver, m_pdSolver);
|
||||
} else
|
||||
{
|
||||
return new(mem) btHfFluidBuoyantShapeCollisionAlgorithm(ci,body0,body1, m_simplexSolver, m_pdSolver);
|
||||
return new(mem) btHfFluidBuoyantShapeCollisionAlgorithm(ci,body0Wrap,body1Wrap, m_simplexSolver, m_pdSolver);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -25,54 +25,69 @@ Experimental Buoyancy fluid demo written by John McCutchan
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "btHfFluid.h"
|
||||
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
||||
|
||||
btHfFluidRigidCollisionAlgorithm::~btHfFluidRigidCollisionAlgorithm()
|
||||
{
|
||||
}
|
||||
|
||||
btHfFluidRigidCollisionAlgorithm::btHfFluidRigidCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped)
|
||||
btHfFluidRigidCollisionAlgorithm::btHfFluidRigidCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap, bool isSwapped)
|
||||
: btCollisionAlgorithm(ci), m_isSwapped(isSwapped),
|
||||
m_convexTrianglecallback(ci.m_dispatcher1, col0, col1, !isSwapped) // we flip the isSwapped because we are hf fluid vs. convex and callback expects convex vs. concave
|
||||
m_convexTrianglecallback(ci.m_dispatcher1, col0Wrap, col1Wrap, !isSwapped) // we flip the isSwapped because we are hf fluid vs. convex and callback expects convex vs. concave
|
||||
{
|
||||
m_manifoldPtr = m_convexTrianglecallback.m_manifoldPtr;
|
||||
if (m_isSwapped)
|
||||
{
|
||||
m_hfFluid = static_cast<btHfFluid*>(col1);
|
||||
m_rigidCollisionObject = static_cast<btCollisionObject*>(col0);
|
||||
m_hfFluid = static_cast<const btHfFluid*>(col1Wrap->getCollisionObject());
|
||||
m_rigidCollisionObject = static_cast<const btCollisionObject*>(col0Wrap->getCollisionObject());
|
||||
m_manifoldPtr->setBodies(m_hfFluid,m_rigidCollisionObject);
|
||||
} else {
|
||||
m_hfFluid = static_cast<btHfFluid*>(col0);
|
||||
m_rigidCollisionObject = static_cast<btCollisionObject*>(col1);
|
||||
m_hfFluid = static_cast<const btHfFluid*>(col0Wrap->getCollisionObject());
|
||||
m_rigidCollisionObject = static_cast<const btCollisionObject*>(col1Wrap->getCollisionObject());
|
||||
m_manifoldPtr->setBodies(m_rigidCollisionObject,m_hfFluid);
|
||||
}
|
||||
}
|
||||
|
||||
void btHfFluidRigidCollisionAlgorithm::processGround (const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
{
|
||||
btAssert(0);
|
||||
//needs fixing after btCollisionObjectWrapper introduction
|
||||
#if 0
|
||||
btScalar triangleMargin = m_rigidCollisionObject->getCollisionShape()->getMargin();
|
||||
resultOut->setPersistentManifold(m_manifoldPtr);
|
||||
// to perform the convex shape vs. ground terrain:
|
||||
// we pull the convex shape out of the buoyant shape and replace it temporarily
|
||||
btHfFluidBuoyantConvexShape* tmpShape = (btHfFluidBuoyantConvexShape*)m_rigidCollisionObject->getCollisionShape();
|
||||
btConvexShape* convexShape = ((btHfFluidBuoyantConvexShape*)tmpShape)->getConvexShape();
|
||||
m_rigidCollisionObject->setCollisionShape (convexShape);
|
||||
const btConvexShape* convexShape = ((const btHfFluidBuoyantConvexShape*)tmpShape)->getConvexShape();
|
||||
//m_rigidCollisionObject->setCollisionShape (convexShape);
|
||||
m_convexTrianglecallback.setTimeStepAndCounters (triangleMargin, dispatchInfo, resultOut);
|
||||
m_hfFluid->foreachGroundTriangle (&m_convexTrianglecallback, m_convexTrianglecallback.getAabbMin(),m_convexTrianglecallback.getAabbMax());
|
||||
resultOut->refreshContactPoints();
|
||||
#endif
|
||||
// restore the buoyant shape
|
||||
m_rigidCollisionObject->setCollisionShape (tmpShape);
|
||||
//m_rigidCollisionObject->setCollisionShape (tmpShape);
|
||||
}
|
||||
|
||||
btScalar btHfFluidRigidCollisionAlgorithm::processFluid (const btDispatcherInfo& dispatchInfo, btScalar density, btScalar floatyness)
|
||||
{
|
||||
btAssert(0);
|
||||
//needs fixing after btCollisionObjectWrapper introduction
|
||||
#if 0
|
||||
btRigidBody* rb = btRigidBody::upcast(m_rigidCollisionObject);
|
||||
btHfFluidColumnRigidBodyCallback columnCallback (rb, dispatchInfo.m_debugDraw, density, floatyness);
|
||||
m_hfFluid->foreachFluidColumn (&columnCallback, m_convexTrianglecallback.getAabbMin(), m_convexTrianglecallback.getAabbMax());
|
||||
return columnCallback.getVolume ();
|
||||
#endif
|
||||
return 0.f;
|
||||
|
||||
}
|
||||
|
||||
void btHfFluidRigidCollisionAlgorithm::applyFluidFriction (btScalar mu, btScalar submerged_percentage)
|
||||
{
|
||||
btAssert(0);
|
||||
//needs fixing after btCollisionObjectWrapper introduction
|
||||
#if 0
|
||||
|
||||
btRigidBody* rb = btRigidBody::upcast(m_rigidCollisionObject);
|
||||
btScalar dt = btScalar(1.0f/60.0f);
|
||||
|
||||
@@ -103,10 +118,15 @@ void btHfFluidRigidCollisionAlgorithm::applyFluidFriction (btScalar mu, btScalar
|
||||
rb->applyCentralImpulse (dt * scaled_mu * -rb->getLinearVelocity());
|
||||
rb->applyTorqueImpulse (dt * scaled_mu * -rb->getAngularVelocity());
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void btHfFluidRigidCollisionAlgorithm::processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
void btHfFluidRigidCollisionAlgorithm::processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
{
|
||||
btAssert(0);
|
||||
//needs fixing after btCollisionObjectWrapper introduction
|
||||
#if 0
|
||||
processGround (dispatchInfo, resultOut);
|
||||
btHfFluidBuoyantConvexShape* buoyantShape = (btHfFluidBuoyantConvexShape*)m_rigidCollisionObject->getCollisionShape();
|
||||
btRigidBody* rb = btRigidBody::upcast(m_rigidCollisionObject);
|
||||
@@ -125,6 +145,8 @@ void btHfFluidRigidCollisionAlgorithm::processCollision (btCollisionObject* body
|
||||
applyFluidFriction (mu, submerged_percentage);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
btScalar btHfFluidRigidCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
|
||||
@@ -35,8 +35,8 @@ class btHfFluidRigidCollisionAlgorithm : public btCollisionAlgorithm
|
||||
{
|
||||
btPersistentManifold* m_manifoldPtr;
|
||||
|
||||
btHfFluid* m_hfFluid;
|
||||
btCollisionObject* m_rigidCollisionObject;
|
||||
const btHfFluid* m_hfFluid;
|
||||
const btCollisionObject* m_rigidCollisionObject;
|
||||
|
||||
///for rigid versus fluid (instead of fluid versus rigid), we use this swapped boolean
|
||||
bool m_isSwapped;
|
||||
@@ -48,11 +48,11 @@ class btHfFluidRigidCollisionAlgorithm : public btCollisionAlgorithm
|
||||
btScalar processFluid (const btDispatcherInfo& dispatchInfo, btScalar density, btScalar floatyness);
|
||||
public:
|
||||
|
||||
btHfFluidRigidCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* col0,btCollisionObject* col1, bool isSwapped);
|
||||
btHfFluidRigidCollisionAlgorithm(const btCollisionAlgorithmConstructionInfo& ci,const btCollisionObjectWrapper* col0Wrap,const btCollisionObjectWrapper* col1Wrap, bool isSwapped);
|
||||
|
||||
virtual ~btHfFluidRigidCollisionAlgorithm();
|
||||
|
||||
virtual void processCollision (btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
virtual void processCollision (const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
virtual btScalar calculateTimeOfImpact(btCollisionObject* body0,btCollisionObject* body1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut);
|
||||
|
||||
@@ -64,15 +64,15 @@ public:
|
||||
|
||||
struct CreateFunc :public btCollisionAlgorithmCreateFunc
|
||||
{
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, btCollisionObject* body0,btCollisionObject* body1)
|
||||
virtual btCollisionAlgorithm* CreateCollisionAlgorithm(btCollisionAlgorithmConstructionInfo& ci, const btCollisionObjectWrapper* body0Wrap,const btCollisionObjectWrapper* body1Wrap)
|
||||
{
|
||||
void* mem = ci.m_dispatcher1->allocateCollisionAlgorithm(sizeof(btHfFluidRigidCollisionAlgorithm));
|
||||
if (!m_swapped)
|
||||
{
|
||||
return new(mem) btHfFluidRigidCollisionAlgorithm(ci,body0,body1,false);
|
||||
return new(mem) btHfFluidRigidCollisionAlgorithm(ci,body0Wrap,body1Wrap,false);
|
||||
} else
|
||||
{
|
||||
return new(mem) btHfFluidRigidCollisionAlgorithm(ci,body0,body1,true);
|
||||
return new(mem) btHfFluidRigidCollisionAlgorithm(ci,body0Wrap,body1Wrap,true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -190,7 +190,7 @@ void btHfFluidRigidDynamicsWorld::drawHfFluidBuoyantConvexShape (btIDebugDraw* d
|
||||
}
|
||||
};
|
||||
|
||||
btConvexShape* convexShape = ((btHfFluidBuoyantConvexShape*)object->getCollisionShape())->getConvexShape();
|
||||
const btConvexShape* convexShape = ((const btHfFluidBuoyantConvexShape*)object->getCollisionShape())->getConvexShape();
|
||||
debugDrawObject(object->getWorldTransform(),(btCollisionShape*)convexShape,color);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ void HfFluidDemo_GL_ShapeDrawer::drawOpenGL(btScalar* m, const btCollisionShape*
|
||||
|
||||
if (shape->getShapeType() == HFFLUID_BUOYANT_CONVEX_SHAPE_PROXYTYPE)
|
||||
{
|
||||
btConvexShape* convexShape = ((btHfFluidBuoyantConvexShape*)shape)->getConvexShape();
|
||||
const btConvexShape* convexShape = ((btHfFluidBuoyantConvexShape*)shape)->getConvexShape();
|
||||
btTransform I;
|
||||
I.setIdentity();
|
||||
btScalar mat[16];
|
||||
|
||||
Reference in New Issue
Block a user