Added a possibility to build appGpu2dDemo with CUDA solver.

It is disabled by default, see Demos/Gpu2dDemo/btGpuDemoDynamicsWorld.h for instructions how to enable it

Cleaned up Extras/CUDA folder and libbulletcuda project
This commit is contained in:
rponom
2009-05-14 20:20:56 +00:00
parent 42ece54556
commit a95b2a33bd
35 changed files with 528 additions and 5845 deletions

View File

@@ -13,9 +13,9 @@ subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
#include "BulletMultiThreaded/btGpuDefines.h"
#include "BulletMultiThreaded/btGpuUtilsSharedDefs.h"
#include "BulletMultiThreaded/btGpuUtilsSharedCode.h"
//#include "BulletMultiThreaded/btGpuDefines.h"
//#include "BulletMultiThreaded/btGpuUtilsSharedDefs.h"
//#include "BulletMultiThreaded/btGpuUtilsSharedCode.h"
//----------------------------------------------------------------------------------------
@@ -144,6 +144,7 @@ public:
}
btMultiSphereShape* multiSphere = new btMultiSphereShape(inertiaHalfExtents,positions,radii,numSpheres);
m_demo->addCollisionShape(multiSphere);
btVector3 localInertia(0,0,0);
if (mass)
@@ -241,6 +242,13 @@ void BasicDemo::displayCallback(void) {
btOverlappingPairCache* gPairCache;
static btScalar fRandMinMax(btScalar fMin, btScalar fMax)
{
btScalar fr = btScalar(rand()) / btScalar(RAND_MAX);
return fMax - (fMax - fMin) * fr;
}
void BasicDemo::initPhysics()
{
setTexturing(false);
@@ -363,6 +371,31 @@ void BasicDemo::initPhysics()
{
loader.processFile("../../test1.oec");
}
#if 0 // perfomance test : work-in-progress
{ // add more object, but share their shapes
int numNewObjects = 500;
mass = 1.f;
for(int n_obj = 0; n_obj < numNewObjects; n_obj++)
{
btDefaultMotionState* myMotionState= 0;
btVector3 localInertia(0,0,0);
btTransform worldTransform;
worldTransform.setIdentity();
btScalar fx = fRandMinMax(-30., 30.);
btScalar fy = fRandMinMax(5., 30.);
worldTransform.setOrigin(btVector3(fx, fy, 0.f));
int sz = m_collisionShapes.size();
btMultiSphereShape* multiSphere = (btMultiSphereShape*)m_collisionShapes[1];
myMotionState = new btDefaultMotionState(worldTransform);
multiSphere->calculateLocalInertia(mass, localInertia);
btRigidBody* body = new btRigidBody(mass,myMotionState,multiSphere,localInertia);
body->setLinearFactor(btVector3(1,1,0));
body->setAngularFactor(btVector3(0,0,1));
body->setWorldTransform(worldTransform);
getDynamicsWorld()->addRigidBody(body);
}
}
#endif
#else
#if (!SPEC_TEST)

View File

@@ -21,8 +21,8 @@ subject to the following restrictions:
#ifdef BT_USE_CUDA
#include "btCudaDemoPairCache.h"
#include <vector_types.h>
//#include "btCudaDemoPairCache.h"
//#include <vector_types.h>
#endif //BT_USE_CUDA
class btBroadphaseInterface;
@@ -88,7 +88,7 @@ class BasicDemo : public GlutDemoApplication
void DrawConstraintInfo();
void outputDebugInfo(int & xOffset,int & yStart, int yIncr);
virtual void renderme();
void addCollisionShape(btCollisionShape* pShape) { m_collisionShapes.push_back(pShape); }
};

View File

@@ -1,46 +0,0 @@
/*
Impulse based Rigid body simulation using CUDA
Copyright (c) 2007 Takahiro Harada http://www.iii.u-tokyo.ac.jp/~takahiroharada/projects/impulseCUDA.html
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include <cstdlib>
#include <cstdio>
#include <string.h>
#include "../../Extras/CUDA/cutil_math.h"
#include "math_constants.h"
#include <vector_types.h>
//----------------------------------------------------------------------------------------
#include "../../Extras/CUDA/btCudaDefines.h"
//----------------------------------------------------------------------------------------
#include "../../src/BulletMultiThreaded/btGpuUtilsSharedDefs.h"
#include "btGpuDemo2dSharedTypes.h"
#include "btGpuDemo2dSharedDefs.h"
//----------------------------------------------------------------------------------------
texture<float4, 1, cudaReadModeElementType> posTex;
//----------------------------------------------------------------------------------------
#include "btGpuDemo2dSharedCode.h"
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------

View File

@@ -19,7 +19,7 @@ subject to the following restrictions:
#define FRICTION_BOX_GROUND_FACT 0.05f
#define FRICTION_BOX_BOX_FACT 0.05f
#define USE_CENTERS 1
#include "LinearMath/btMinMax.h"
//#include "LinearMath/btMinMax.h"
//------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------
@@ -187,7 +187,8 @@ BT_GPU___device__ float computeImpulse1(float3 rVel,
if(positionConstraint > 0)
return lambdaDt;
positionConstraint = btMin(0.0f,positionConstraint+penetrationError);
// positionConstraint = btMin(0.0f,positionConstraint+penetrationError);
positionConstraint = (positionConstraint+penetrationError) < 0.f ? (positionConstraint+penetrationError) : 0.0f;
lambdaDt = -(BT_GPU_dot(cNormal,rVel)*(1+collisionConstant));
lambdaDt -= (baumgarteConstant/dt*positionConstraint);
@@ -328,8 +329,6 @@ BT_GPU___device__ void collisionResolutionBox( int constrId,
int bId=constraints[constrId].y;
float3 aPos=BT_GPU_make_float34(BT_GPU_FETCH4(pos,aId));
float3 bPos=BT_GPU_make_float34(BT_GPU_FETCH4(pos,bId));
float aRot=rotation[aId];
float bRot=rotation[bId];
float3 aVel=BT_GPU_make_float34(vel[aId]);
float3 bVel=BT_GPU_make_float34(vel[bId]);
float aAngVel=angularVel[aId];
@@ -354,7 +353,8 @@ BT_GPU___device__ void collisionResolutionBox( int constrId,
{
float rLambdaDt=lambdaDtBox[(MAX_VTX_PER_OBJ)*(2*constrId)+iVtx];
float pLambdaDt=rLambdaDt;
rLambdaDt=btMax(pLambdaDt+lambdaDt,0.0f);
// rLambdaDt=btMax(pLambdaDt+lambdaDt,0.0f);
rLambdaDt=(pLambdaDt+lambdaDt) > 0.0f ? (pLambdaDt+lambdaDt) : 0.0f;
lambdaDt=rLambdaDt-pLambdaDt;
lambdaDtBox[(MAX_VTX_PER_OBJ)*(2*constrId)+iVtx]=rLambdaDt;
}

View File

@@ -413,7 +413,7 @@ void btGpuDemoDynamicsWorld::solveConstraints2(btContactSolverInfo& solverInfo)
for(int i=0;i<nIter;i++)
{
btCuda_collisionWithWallBox(m_dcPos, m_dcVel, m_dcRot, m_dcAngVel,m_dShapeBuffer, m_dShapeIds,
btCuda_collisionWithWallBox(m_dcPos, m_dcVel, m_dcRot, m_dcAngVel,m_dShapeBuffer, m_dShapeIds, m_dInvMass,
partProps, boxProps, m_numObj + 1, timeStep);
int* pBatchIds = m_dBatchIds;
for(int iBatch=0;iBatch < m_maxBatches;iBatch++)
@@ -423,7 +423,7 @@ void btGpuDemoDynamicsWorld::solveConstraints2(btContactSolverInfo& solverInfo)
m_dcPos, m_dcVel,
m_dcRot, m_dcAngVel,
m_dLambdaDtBox,
m_dContact,
m_dContact, m_dInvMass,
partProps, iBatch, timeStep);
pBatchIds += numConstraints;
}

View File

@@ -25,17 +25,27 @@ subject to the following restrictions:
#include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"
//#define BT_USE_CUDA 1
// To enable CUDA :
// 1. Uncomment //#define BT_USE_CUDA 1
// 2. Build and add libbulletcuda (Extras/CUDA) to project
// 3. Add $(CUDA_LIB_PATH) and cudart.lib to linker properties
#ifdef BT_USE_CUDA
#include "btCudaDemoPairCache.h"
#include <vector_types.h>
#define BT_GPU_PREF(func) btCuda_##func
#include "../../src/BulletMultiThreaded/btGpuUtilsSharedDefs.h"
// #include "btCudaDemoPairCache.h"
// #include <vector_types.h>
#include "BulletMultiThreaded/btGpuDefines.h"
#undef BT_GPU_PREF
#define BT_GPU_PREF(func) btCuda_##func
#include "BulletMultiThreaded/btGpuUtilsSharedDefs.h"
#else
#include "BulletMultiThreaded/btGpuDefines.h"
#include "../../src/BulletMultiThreaded/btGpuUtilsSharedDefs.h"
#include "BulletMultiThreaded/btGpuDefines.h"
#include "../../src/BulletMultiThreaded/btGpuUtilsSharedDefs.h"
#endif
#undef BT_GPU_PREF
//----------------------------------------------------------------------------------------