Fix Issue 712, related to NVIDIA CUDA check in CMakeLists.txt

Enable btGImpact raycast optimization, thanks to C0DEFACE, see Issue 664
Cull triangle/AABB for concave/heightfield shapes, thanks to Danny Chapman
fix btGetCpuCapabilities, thanks to Ian Ollman! See https://code.google.com/p/bullet/issues/detail?id=738
This commit is contained in:
erwin.coumans
2013-09-10 23:09:24 +00:00
parent 7633dc8b13
commit 7195b54d13
5 changed files with 70 additions and 40 deletions

View File

@@ -20,6 +20,7 @@ subject to the following restrictions:
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
#include "btBulletDynamicsCommon.h"
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
#include "BulletCollision/Gimpact/btGImpactShape.h"
#include <stdio.h> //printf debugging
#include "GLDebugDrawer.h"
@@ -220,7 +221,10 @@ void RaytestDemo::initPhysics()
mesh->addTriangle(quad[0],quad[1],quad[2],true);
mesh->addTriangle(quad[0],quad[2],quad[3],true);
btBvhTriangleMeshShape* trimesh = new btBvhTriangleMeshShape(mesh,true,true);
//btBvhTriangleMeshShape* trimesh = new btBvhTriangleMeshShape(mesh,true,true);
btGImpactMeshShape * trimesh = new btGImpactMeshShape(mesh);
trimesh->updateBound();
#define NUM_SHAPES 6
btCollisionShape* colShapes[NUM_SHAPES] = {

View File

@@ -34,7 +34,7 @@ subject to the following restrictions:
#include "LinearMath/btSerializer.h"
#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
#include "BulletCollision/Gimpact/btGImpactShape.h"
//#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
@@ -325,26 +325,18 @@ void btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,con
} else {
if (collisionShape->isConcave())
{
// BT_PROFILE("rayTestConcave");
if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
{
///optimized version for btBvhTriangleMeshShape
btBvhTriangleMeshShape* triangleMesh = (btBvhTriangleMeshShape*)collisionShape;
btTransform worldTocollisionObject = colObjWorldTransform.inverse();
btVector3 rayFromLocal = worldTocollisionObject * rayFromTrans.getOrigin();
btVector3 rayToLocal = worldTocollisionObject * rayToTrans.getOrigin();
//ConvexCast::CastResult
struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback
{
btCollisionWorld::RayResultCallback* m_resultCallback;
const btCollisionObject* m_collisionObject;
btTriangleMeshShape* m_triangleMesh;
const btConcaveShape* m_triangleMesh;
btTransform m_colObjWorldTransform;
BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
btCollisionWorld::RayResultCallback* resultCallback, const btCollisionObject* collisionObject,btTriangleMeshShape* triangleMesh,const btTransform& colObjWorldTransform):
btCollisionWorld::RayResultCallback* resultCallback, const btCollisionObject* collisionObject,const btConcaveShape* triangleMesh,const btTransform& colObjWorldTransform):
//@BP Mod
btTriangleRaycastCallback(from,to, resultCallback->m_flags),
m_resultCallback(resultCallback),
@@ -375,10 +367,28 @@ void btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,con
};
btTransform worldTocollisionObject = colObjWorldTransform.inverse();
btVector3 rayFromLocal = worldTocollisionObject * rayFromTrans.getOrigin();
btVector3 rayToLocal = worldTocollisionObject * rayToTrans.getOrigin();
// BT_PROFILE("rayTestConcave");
if (collisionShape->getShapeType()==TRIANGLE_MESH_SHAPE_PROXYTYPE)
{
///optimized version for btBvhTriangleMeshShape
btBvhTriangleMeshShape* triangleMesh = (btBvhTriangleMeshShape*)collisionShape;
BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObjectWrap->getCollisionObject(),triangleMesh,colObjWorldTransform);
rcb.m_hitFraction = resultCallback.m_closestHitFraction;
triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
} else
}
else if(collisionShape->getShapeType()==GIMPACT_SHAPE_PROXYTYPE)
{
btGImpactMeshShape* concaveShape = (btGImpactMeshShape*)collisionShape;
BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObjectWrap->getCollisionObject(),concaveShape, colObjWorldTransform);
rcb.m_hitFraction = resultCallback.m_closestHitFraction;
concaveShape->processAllTrianglesRay(&rcb,rayFromLocal,rayToLocal);
}else
{
//generic (slower) case
btConcaveShape* concaveShape = (btConcaveShape*)collisionShape;

View File

@@ -80,6 +80,11 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int
partId, int triangleIndex)
{
if (!TestTriangleAgainstAabb2(triangle, m_aabbMin, m_aabbMax))
{
return;
}
//just for debugging purposes
//printf("triangle %d",m_triangleCount++);
@@ -91,6 +96,8 @@ partId, int triangleIndex)
//const btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
#if 0
///debug drawing of the overlapping triangles
if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))

View File

@@ -835,39 +835,48 @@ static long _mindot_large_sel( const float *vv, const float *vec, unsigned long
long (*_maxdot_large)( const float *vv, const float *vec, unsigned long count, float *dotResult ) = _maxdot_large_sel;
long (*_mindot_large)( const float *vv, const float *vec, unsigned long count, float *dotResult ) = _mindot_large_sel;
//Apple doesn't allow to use this internal API and rejects Apps.
//thanks Apple for rejecting your own contribution :-)
//Let's always use version 'v1'
//See https://code.google.com/p/bullet/issues/detail?id=738
#ifdef USE_DEVICE_CAPABILITIES
extern "C" {int _get_cpu_capabilities( void );}
#endif //USE_DEVICE_CAPABILITIES
static inline uint32_t btGetCpuCapabilities( void )
{
static uint32_t capabilities = 0;
static bool testedCapabilities = false;
if( 0 == testedCapabilities)
{
uint32_t hasFeature = 0;
size_t featureSize = sizeof( hasFeature );
int err = sysctlbyname( "hw.optional.neon_hpfp", &hasFeature, &featureSize, NULL, 0 );
if( 0 == err && hasFeature)
capabilities |= 0x2000;
testedCapabilities = true;
}
return capabilities;
}
static long _maxdot_large_sel( const float *vv, const float *vec, unsigned long count, float *dotResult )
{
#ifdef USE_DEVICE_CAPABILITIES
if( _get_cpu_capabilities() & 0x2000 )
if( btGetCpuCapabilities() & 0x2000 )
_maxdot_large = _maxdot_large_v1;
else
_maxdot_large = _maxdot_large_v0;
#else
_maxdot_large = _maxdot_large_v1;
#endif
return _maxdot_large(vv, vec, count, dotResult);
}
static long _mindot_large_sel( const float *vv, const float *vec, unsigned long count, float *dotResult )
{
#ifdef USE_DEVICE_CAPABILITIES
if( _get_cpu_capabilities() & 0x2000 )
if( btGetCpuCapabilities() & 0x2000 )
_mindot_large = _mindot_large_v1;
else
_mindot_large = _mindot_large_v0;
#else
_mindot_large = _mindot_large_v1;
#endif
return _mindot_large(vv, vec, count, dotResult);
}