More stable parameters for solver (GpuDemo2d)

Added a possibility to switch between GPU/Bullet narrowphase ('j' key)
This commit is contained in:
rponom
2009-05-12 01:54:41 +00:00
parent 34685cb631
commit fcf7bda3b0
4 changed files with 34 additions and 8 deletions

View File

@@ -97,6 +97,7 @@ bool gUseCPUSolver = false;
bool gUseCPUSolver = true; bool gUseCPUSolver = true;
#endif //BT_USE_CUDA #endif //BT_USE_CUDA
bool gUseBulletNarrowphase = false;
#include "oecakeLoader.h" #include "oecakeLoader.h"
@@ -303,6 +304,8 @@ void BasicDemo::initPhysics()
pDdw->setWorldMax(gWorldMax); pDdw->setWorldMax(gWorldMax);
// gUseCPUSolver = true; // gUseCPUSolver = true;
pDdw->setUseCPUSolver(gUseCPUSolver); pDdw->setUseCPUSolver(gUseCPUSolver);
gUseBulletNarrowphase = false;
pDdw->setUseBulletNarrowphase(gUseBulletNarrowphase);
// m_dynamicsWorld->setGravity(btVector3(0,0,0)); // m_dynamicsWorld->setGravity(btVector3(0,0,0));
m_dynamicsWorld->setGravity(btVector3(0,-10.,0)); m_dynamicsWorld->setGravity(btVector3(0,-10.,0));
@@ -586,6 +589,21 @@ void BasicDemo::keyboardCallback(unsigned char key, int x, int y)
pDdw->setUseCPUSolver(gUseCPUSolver); pDdw->setUseCPUSolver(gUseCPUSolver);
break; break;
} }
case 'j' :
{
btGpuDemoDynamicsWorld* pDdw = (btGpuDemoDynamicsWorld*)m_dynamicsWorld;
gUseBulletNarrowphase = !gUseBulletNarrowphase;
pDdw->setUseBulletNarrowphase(gUseBulletNarrowphase);
if(gUseBulletNarrowphase)
{
m_dispatcher->setNearCallback(btCollisionDispatcher::defaultNearCallback);
}
else
{
m_dispatcher->setNearCallback(cudaDemoNearCallback);
}
break;
}
default : default :
{ {
DemoApplication::keyboardCallback(key, x, y); DemoApplication::keyboardCallback(key, x, y);

View File

@@ -174,8 +174,11 @@ BT_GPU___device__ float computeImpulse1(float3 rVel,
float3 cNormal, float3 cNormal,
float dt) float dt)
{ {
const float collisionConstant = 0.1f; // const float collisionConstant = 0.1f;
const float baumgarteConstant = 0.5f; // const float baumgarteConstant = 0.5f;
// const float penetrationError = 0.02f;
const float collisionConstant = -0.1f;
const float baumgarteConstant = 0.3f;
const float penetrationError = 0.02f; const float penetrationError = 0.02f;
float lambdaDt=0; float lambdaDt=0;
@@ -231,12 +234,14 @@ BT_GPU___global__ void collisionWithWallBoxD(float4 *pos,
float3 vPos = aPos + rerVertex; float3 vPos = aPos + rerVertex;
float rad = shape[iVtx].w; float rad = shape[iVtx].w;
float3 vVel =aVel+BT_GPU_cross(BT_GPU_make_float3(0.0f,0.0f,aAngVel),rerVertex); float3 vVel =aVel+BT_GPU_cross(BT_GPU_make_float3(0.0f,0.0f,aAngVel),rerVertex);
float restitution=1.0; // float restitution=1.0;
float restitution=0.3f;
{ {
positionConstraint =vPos.y - rad - gProp.minY; positionConstraint =vPos.y - rad - gProp.minY;
impulse =BT_GPU_make_float31(0.0f); impulse =BT_GPU_make_float31(0.0f);
if(positionConstraint < 0){ if(positionConstraint < 0)
{
float3 groundNormal; float3 groundNormal;
groundNormal = BT_GPU_make_float3(0.0f,1.0f,0.0f); groundNormal = BT_GPU_make_float3(0.0f,1.0f,0.0f);
impulse =groundNormal* impulse =groundNormal*
@@ -266,7 +271,7 @@ BT_GPU___global__ void collisionWithWallBoxD(float4 *pos,
impulse =BT_GPU_make_float31(0.0f); impulse =BT_GPU_make_float31(0.0f);
if(positionConstraint < 0){ if(positionConstraint < 0){
impulse =BT_GPU_make_float3(1.0f,0.0f,0.0f)* impulse =BT_GPU_make_float3(1.0f,0.0f,0.0f)* restitution *
computeImpulse1(vVel,positionConstraint, computeImpulse1(vVel,positionConstraint,
BT_GPU_make_float3(1.0f,0.0f,0.0f), BT_GPU_make_float3(1.0f,0.0f,0.0f),
dt); dt);
@@ -282,7 +287,7 @@ BT_GPU___global__ void collisionWithWallBoxD(float4 *pos,
impulse =BT_GPU_make_float31(0.0f); impulse =BT_GPU_make_float31(0.0f);
if(positionConstraint < 0){ if(positionConstraint < 0){
impulse =BT_GPU_make_float3(-1.0f,0.0f,0.0f)* impulse =BT_GPU_make_float3(-1.0f,0.0f,0.0f)* restitution *
computeImpulse1(vVel,positionConstraint, computeImpulse1(vVel,positionConstraint,
BT_GPU_make_float3(-1.0f,0.0f,0.0f), BT_GPU_make_float3(-1.0f,0.0f,0.0f),
dt); dt);

View File

@@ -431,8 +431,8 @@ void btGpuDemoDynamicsWorld::debugDrawConstraints(int selectedBatch, const float
for(int i = 0; i < numConstraints; i++) for(int i = 0; i < numConstraints; i++)
{ {
int indx = pBatchIds[i]; int indx = pBatchIds[i];
int idA = m_hIds[indx].x-1; int idA = m_hIds[indx].x - 1;
int idB = m_hIds[indx].y-1; int idB = m_hIds[indx].y - 1;
if((idA > 0) && (idB > 0)) if((idA > 0) && (idB > 0))
{ {
btCollisionObject* colObjA = m_collisionObjects[idA]; btCollisionObject* colObjA = m_collisionObjects[idA];

View File

@@ -66,6 +66,7 @@ protected:
int m_numObj; int m_numObj;
int m_numSimStep; int m_numSimStep;
bool m_useCPUSolver; bool m_useCPUSolver;
bool m_useBulletNarrowphase;
float4* m_hPos; float4* m_hPos;
float* m_hRot; float* m_hRot;
@@ -254,11 +255,13 @@ public:
void setWorldMax(const btVector3& worldMax) { m_worldMax = worldMax; } void setWorldMax(const btVector3& worldMax) { m_worldMax = worldMax; }
void grabData(); void grabData();
void grabContactData();
void copyDataToGPU(); void copyDataToGPU();
void setConstraintData(btCudaPartProps& partProps); void setConstraintData(btCudaPartProps& partProps);
void copyDataFromGPU(); void copyDataFromGPU();
void writebackData(); void writebackData();
void setUseCPUSolver(bool useCPU) { m_useCPUSolver = useCPU; } void setUseCPUSolver(bool useCPU) { m_useCPUSolver = useCPU; }
void setUseBulletNarrowphase(bool useBulletNarrowphase) {m_useBulletNarrowphase = useBulletNarrowphase; }
void createBatches2(); void createBatches2();