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:
@@ -20,6 +20,7 @@ subject to the following restrictions:
|
|||||||
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
|
///btBulletDynamicsCommon.h is the main Bullet include file, contains most common include files.
|
||||||
#include "btBulletDynamicsCommon.h"
|
#include "btBulletDynamicsCommon.h"
|
||||||
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
|
#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
|
||||||
|
#include "BulletCollision/Gimpact/btGImpactShape.h"
|
||||||
|
|
||||||
#include <stdio.h> //printf debugging
|
#include <stdio.h> //printf debugging
|
||||||
#include "GLDebugDrawer.h"
|
#include "GLDebugDrawer.h"
|
||||||
@@ -220,7 +221,10 @@ void RaytestDemo::initPhysics()
|
|||||||
mesh->addTriangle(quad[0],quad[1],quad[2],true);
|
mesh->addTriangle(quad[0],quad[1],quad[2],true);
|
||||||
mesh->addTriangle(quad[0],quad[2],quad[3],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
|
#define NUM_SHAPES 6
|
||||||
btCollisionShape* colShapes[NUM_SHAPES] = {
|
btCollisionShape* colShapes[NUM_SHAPES] = {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ subject to the following restrictions:
|
|||||||
#include "LinearMath/btSerializer.h"
|
#include "LinearMath/btSerializer.h"
|
||||||
#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
|
#include "BulletCollision/CollisionShapes/btConvexPolyhedron.h"
|
||||||
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
|
||||||
|
#include "BulletCollision/Gimpact/btGImpactShape.h"
|
||||||
//#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
|
//#define DISABLE_DBVT_COMPOUNDSHAPE_RAYCAST_ACCELERATION
|
||||||
|
|
||||||
|
|
||||||
@@ -325,26 +325,18 @@ void btCollisionWorld::rayTestSingleInternal(const btTransform& rayFromTrans,con
|
|||||||
} else {
|
} else {
|
||||||
if (collisionShape->isConcave())
|
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
|
//ConvexCast::CastResult
|
||||||
struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback
|
struct BridgeTriangleRaycastCallback : public btTriangleRaycastCallback
|
||||||
{
|
{
|
||||||
btCollisionWorld::RayResultCallback* m_resultCallback;
|
btCollisionWorld::RayResultCallback* m_resultCallback;
|
||||||
const btCollisionObject* m_collisionObject;
|
const btCollisionObject* m_collisionObject;
|
||||||
btTriangleMeshShape* m_triangleMesh;
|
const btConcaveShape* m_triangleMesh;
|
||||||
|
|
||||||
btTransform m_colObjWorldTransform;
|
btTransform m_colObjWorldTransform;
|
||||||
|
|
||||||
BridgeTriangleRaycastCallback( const btVector3& from,const btVector3& to,
|
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
|
//@BP Mod
|
||||||
btTriangleRaycastCallback(from,to, resultCallback->m_flags),
|
btTriangleRaycastCallback(from,to, resultCallback->m_flags),
|
||||||
m_resultCallback(resultCallback),
|
m_resultCallback(resultCallback),
|
||||||
@@ -375,9 +367,27 @@ 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);
|
BridgeTriangleRaycastCallback rcb(rayFromLocal,rayToLocal,&resultCallback,collisionObjectWrap->getCollisionObject(),triangleMesh,colObjWorldTransform);
|
||||||
rcb.m_hitFraction = resultCallback.m_closestHitFraction;
|
rcb.m_hitFraction = resultCallback.m_closestHitFraction;
|
||||||
triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
|
triangleMesh->performRaycast(&rcb,rayFromLocal,rayToLocal);
|
||||||
|
}
|
||||||
|
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
|
}else
|
||||||
{
|
{
|
||||||
//generic (slower) case
|
//generic (slower) case
|
||||||
|
|||||||
@@ -80,6 +80,11 @@ void btConvexTriangleCallback::processTriangle(btVector3* triangle,int
|
|||||||
partId, int triangleIndex)
|
partId, int triangleIndex)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (!TestTriangleAgainstAabb2(triangle, m_aabbMin, m_aabbMax))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//just for debugging purposes
|
//just for debugging purposes
|
||||||
//printf("triangle %d",m_triangleCount++);
|
//printf("triangle %d",m_triangleCount++);
|
||||||
|
|
||||||
@@ -91,6 +96,8 @@ partId, int triangleIndex)
|
|||||||
//const btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
|
//const btCollisionObject* ob = static_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
///debug drawing of the overlapping triangles
|
///debug drawing of the overlapping triangles
|
||||||
if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
|
if (m_dispatchInfoPtr && m_dispatchInfoPtr->m_debugDraw && (m_dispatchInfoPtr->m_debugDraw->getDebugMode() &btIDebugDraw::DBG_DrawWireframe ))
|
||||||
|
|||||||
@@ -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 (*_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;
|
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 :-)
|
static inline uint32_t btGetCpuCapabilities( void )
|
||||||
//Let's always use version 'v1'
|
{
|
||||||
//See https://code.google.com/p/bullet/issues/detail?id=738
|
static uint32_t capabilities = 0;
|
||||||
#ifdef USE_DEVICE_CAPABILITIES
|
static bool testedCapabilities = false;
|
||||||
extern "C" {int _get_cpu_capabilities( void );}
|
|
||||||
#endif //USE_DEVICE_CAPABILITIES
|
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 )
|
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;
|
_maxdot_large = _maxdot_large_v1;
|
||||||
else
|
else
|
||||||
_maxdot_large = _maxdot_large_v0;
|
_maxdot_large = _maxdot_large_v0;
|
||||||
#else
|
|
||||||
_maxdot_large = _maxdot_large_v1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return _maxdot_large(vv, vec, count, dotResult);
|
return _maxdot_large(vv, vec, count, dotResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
static long _mindot_large_sel( const float *vv, const float *vec, unsigned long count, float *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;
|
_mindot_large = _mindot_large_v1;
|
||||||
else
|
else
|
||||||
_mindot_large = _mindot_large_v0;
|
_mindot_large = _mindot_large_v0;
|
||||||
#else
|
|
||||||
_mindot_large = _mindot_large_v1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return _mindot_large(vv, vec, count, dotResult);
|
return _mindot_large(vv, vec, count, dotResult);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user