move OpenCL initialization for the unit tests in a shared header file, and support some basic command-line arguments
--cl_device=1 --cl_platform=1 --allow_opencl_cpu add chaindemo, test for mass ratios restore sleeping/activation mode in featherstone demo Use _VARIADIC_MAX=10 to avoid Google Test issues with Visual Studio 2012, thanks to Mobeen for the report Enable verbose printf for unit tests
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
#include "../bullet2/RagdollDemo/RagdollDemo.h"
|
||||
#include "../bullet2/LuaDemo/LuaDemo.h"
|
||||
|
||||
#include "../bullet2/ChainDemo/ChainDemo.h"
|
||||
|
||||
struct BulletDemoEntry
|
||||
{
|
||||
@@ -24,6 +24,7 @@ static BulletDemoEntry allDemos[]=
|
||||
|
||||
//{"emptydemo",EmptyBulletDemo::MyCreateFunc},
|
||||
{"BasicDemo",BasicDemo::MyCreateFunc},
|
||||
//{"ChainDemo",ChainDemo::MyCreateFunc},
|
||||
{"HingeDemo",HingeDemo::MyCreateFunc},
|
||||
{"Ragdoll",RagDollDemo::MyCreateFunc},
|
||||
{"MultiBody1",FeatherstoneDemo1::MyCreateFunc},
|
||||
|
||||
@@ -14,6 +14,8 @@ static int sCurrentDemoIndex = 0;
|
||||
static BulletDemoInterface* sCurrentDemo = 0;
|
||||
static b3AlignedObjectArray<const char*> allNames;
|
||||
|
||||
|
||||
bool drawGUI=true;
|
||||
extern bool useShadowMap;
|
||||
static bool wireframe=false;
|
||||
static bool pauseSimulation=false;
|
||||
@@ -128,8 +130,10 @@ void MyComboBoxCallback(int comboId, const char* item)
|
||||
|
||||
}
|
||||
|
||||
extern bool sOpenGLVerbose;
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
sOpenGLVerbose = false;
|
||||
|
||||
float dt = 1./120.f;
|
||||
int width = 1024;
|
||||
@@ -175,12 +179,17 @@ int main(int argc, char* argv[])
|
||||
app->m_instancingRenderer->updateCamera();
|
||||
|
||||
app->drawGrid();
|
||||
|
||||
if (0)
|
||||
{
|
||||
char bla[1024];
|
||||
static int frameCount = 0;
|
||||
frameCount++;
|
||||
sprintf(bla,"Simple test frame %d", frameCount);
|
||||
|
||||
app->drawText(bla,10,10);
|
||||
}
|
||||
|
||||
if (sCurrentDemo)
|
||||
{
|
||||
if (!pauseSimulation)
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
"../bullet2/BasicDemo/BasicDemo.h",
|
||||
"../bullet2/BasicDemo/HingeDemo.cpp",
|
||||
"../bullet2/BasicDemo/HingeDemo.h",
|
||||
"../bullet2/BasicDemo/ChainDemo.cpp",
|
||||
"../bullet2/BasicDemo/ChainDemo.h",
|
||||
|
||||
"../bullet2/RagdollDemo/RagdollDemo.cpp",
|
||||
"../bullet2/RagdollDemo/RagdollDemo.h",
|
||||
"../bullet2/LuaDemo/LuaDemo.cpp",
|
||||
|
||||
@@ -112,8 +112,7 @@ static BroadphaseEntry allBroadphases[]=
|
||||
{"GPU Brute Force",b3GpuSapBroadphase::CreateFuncBruteForceGpu},
|
||||
{"GPU 1-SAP Original",b3GpuSapBroadphase::CreateFuncOriginal},
|
||||
{"GPU 1-SAP Barrier",b3GpuSapBroadphase::CreateFuncBarrier},
|
||||
{"GPU 1-SAP LDS",b3GpuSapBroadphase::CreateFuncLocalMemory},
|
||||
{"GPU 1-SAP LDS Batch",b3GpuSapBroadphase::CreateFuncLocalMemoryBatchWrite},
|
||||
{"GPU 1-SAP LDS",b3GpuSapBroadphase::CreateFuncLocalMemory}
|
||||
};
|
||||
|
||||
|
||||
|
||||
201
Demos3/bullet2/ChainDemo/ChainDemo.cpp
Normal file
201
Demos3/bullet2/ChainDemo/ChainDemo.cpp
Normal file
@@ -0,0 +1,201 @@
|
||||
#include "ChainDemo.h"
|
||||
#include "OpenGLWindow/SimpleOpenGL3App.h"
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "LinearMath/btVector3.h"
|
||||
|
||||
#include "BulletDynamics/ConstraintSolver/btNNCGConstraintSolver.h"
|
||||
#include "BulletDynamics/MLCPSolvers/btDantzigSolver.h"
|
||||
#include "BulletDynamics/MLCPSolvers/btLemkeSolver.h"
|
||||
#include "BulletDynamics/MLCPSolvers/btSolveProjectedGaussSeidel.h"
|
||||
#include "BulletDynamics/MLCPSolvers/btMLCPSolver.h"
|
||||
|
||||
|
||||
#define NUM_SPHERES 10
|
||||
|
||||
static const float scaling=0.35f;
|
||||
|
||||
ChainDemo::ChainDemo(SimpleOpenGL3App* app)
|
||||
:Bullet2RigidBodyDemo(app)
|
||||
{
|
||||
}
|
||||
|
||||
ChainDemo::~ChainDemo()
|
||||
{
|
||||
}
|
||||
|
||||
void ChainDemo::createGround(int cubeShapeId)
|
||||
{
|
||||
{
|
||||
float color[]={0.3,0.3,1,1};
|
||||
float halfExtents[]={50,1,50,1};
|
||||
btTransform groundTransform;
|
||||
groundTransform.setIdentity();
|
||||
groundTransform.setOrigin(btVector3(0,-5,0));
|
||||
m_glApp->m_instancingRenderer->registerGraphicsInstance(cubeShapeId,groundTransform.getOrigin(),groundTransform.getRotation(),color,halfExtents);
|
||||
btBoxShape* groundShape = new btBoxShape(btVector3(btScalar(halfExtents[0]),btScalar(halfExtents[1]),btScalar(halfExtents[2])));
|
||||
//We can also use DemoApplication::localCreateRigidBody, but for clarity it is provided here:
|
||||
{
|
||||
btScalar mass(0.);
|
||||
//rigidbody is dynamic if and only if mass is non zero, otherwise static
|
||||
bool isDynamic = (mass != 0.f);
|
||||
btVector3 localInertia(0,0,0);
|
||||
if (isDynamic)
|
||||
groundShape->calculateLocalInertia(mass,localInertia);
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
//add the body to the dynamics world
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
body->setActivationState(DISABLE_DEACTIVATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
void ChainDemo::initPhysics()
|
||||
{
|
||||
// Bullet2RigidBodyDemo::initPhysics();
|
||||
|
||||
m_config = new btDefaultCollisionConfiguration;
|
||||
m_dispatcher = new btCollisionDispatcher(m_config);
|
||||
m_bp = new btDbvtBroadphase();
|
||||
//m_solver = new btNNCGConstraintSolver();
|
||||
m_solver = new btSequentialImpulseConstraintSolver();
|
||||
// btDantzigSolver* mlcp = new btDantzigSolver();
|
||||
//btLemkeSolver* mlcp = new btLemkeSolver();
|
||||
//m_solver = new btMLCPSolver(mlcp);
|
||||
// m_solver = new btSequentialImpulseConstraintSolver();
|
||||
//btMultiBodyConstraintSolver* solver = new btMultiBodyConstraintSolver();
|
||||
//m_solver = solver;
|
||||
|
||||
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_bp,m_solver,m_config);
|
||||
m_dynamicsWorld->getSolverInfo().m_numIterations = 1000;
|
||||
m_dynamicsWorld->getSolverInfo().m_splitImpulse = false;
|
||||
|
||||
int curColor=0;
|
||||
//create ground
|
||||
btScalar radius=scaling;
|
||||
int unitCubeShapeId = m_glApp->registerCubeShape();
|
||||
|
||||
float pos[]={0,0,0};
|
||||
float orn[]={0,0,0,1};
|
||||
|
||||
|
||||
//eateGround(unitCubeShapeId);
|
||||
|
||||
int sphereShapeId = m_glApp->registerGraphicsSphereShape(radius,false);
|
||||
|
||||
{
|
||||
float halfExtents[]={scaling,scaling,scaling,1};
|
||||
btVector4 colors[4] =
|
||||
{
|
||||
btVector4(1,0,0,1),
|
||||
btVector4(0,1,0,1),
|
||||
btVector4(0,1,1,1),
|
||||
btVector4(1,1,0,1),
|
||||
};
|
||||
|
||||
|
||||
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
|
||||
|
||||
btCollisionShape* colShape = new btSphereShape(scaling);
|
||||
|
||||
btScalar largeMass[]={1000,10,100,1000};
|
||||
for (int i=0;i<1;i++)
|
||||
{
|
||||
|
||||
btAlignedObjectArray<btRigidBody*> bodies;
|
||||
for (int k=0;k<NUM_SPHERES;k++)
|
||||
{
|
||||
btVector3 localInertia(0,0,0);
|
||||
btScalar mass = 0.f;
|
||||
curColor = 1;
|
||||
|
||||
switch (k)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
mass = largeMass[i];
|
||||
curColor = 0;
|
||||
break;
|
||||
}
|
||||
case NUM_SPHERES-1:
|
||||
{
|
||||
mass = 0.f;
|
||||
curColor = 2;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
curColor = 1;
|
||||
mass = 1.f;
|
||||
}
|
||||
};
|
||||
|
||||
if (mass)
|
||||
colShape ->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
btVector4 color = colors[curColor];
|
||||
|
||||
startTransform.setOrigin(btVector3(
|
||||
btScalar(7.5+-i*5),
|
||||
btScalar(6.*scaling+2.0*scaling*k),
|
||||
btScalar(0)));
|
||||
|
||||
m_glApp->m_instancingRenderer->registerGraphicsInstance(sphereShapeId,startTransform.getOrigin(),startTransform.getRotation(),color,halfExtents);
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
bodies.push_back(body);
|
||||
body->setActivationState(DISABLE_DEACTIVATION);
|
||||
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
}
|
||||
|
||||
//add constraints
|
||||
btVector3 pivotInA(0,radius,0);
|
||||
btVector3 pivotInB(0,-radius,0);
|
||||
for (int k=0;k<NUM_SPHERES-1;k++)
|
||||
{
|
||||
btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*bodies[k],*bodies[k+1],pivotInA,pivotInB);
|
||||
m_dynamicsWorld->addConstraint(p2p,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_glApp->m_instancingRenderer->writeTransforms();
|
||||
}
|
||||
void ChainDemo::exitPhysics()
|
||||
{
|
||||
|
||||
Bullet2RigidBodyDemo::exitPhysics();
|
||||
}
|
||||
void ChainDemo::renderScene()
|
||||
{
|
||||
//sync graphics -> physics world transforms
|
||||
{
|
||||
for (int i=0;i<m_dynamicsWorld->getNumCollisionObjects();i++)
|
||||
{
|
||||
btVector3 pos = m_dynamicsWorld->getCollisionObjectArray()[i]->getWorldTransform().getOrigin();
|
||||
btQuaternion orn = m_dynamicsWorld->getCollisionObjectArray()[i]->getWorldTransform().getRotation();
|
||||
m_glApp->m_instancingRenderer->writeSingleInstanceTransformToCPU(pos,orn,i);
|
||||
}
|
||||
m_glApp->m_instancingRenderer->writeTransforms();
|
||||
}
|
||||
|
||||
m_glApp->m_instancingRenderer->renderScene();
|
||||
}
|
||||
|
||||
|
||||
void ChainDemo::stepSimulation(float dt)
|
||||
{
|
||||
m_dynamicsWorld->stepSimulation(dt,10,1./240.);
|
||||
//m_dynamicsWorld->stepSimulation(dt,10,1./60.);
|
||||
}
|
||||
|
||||
|
||||
|
||||
31
Demos3/bullet2/ChainDemo/ChainDemo.h
Normal file
31
Demos3/bullet2/ChainDemo/ChainDemo.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef CHAIN_DEMO_H
|
||||
#define CHAIN_DEMO_H
|
||||
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "../BasicDemo/Bullet2RigidBodyDemo.h"
|
||||
|
||||
|
||||
|
||||
class ChainDemo : public Bullet2RigidBodyDemo
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
static BulletDemoInterface* MyCreateFunc(SimpleOpenGL3App* app)
|
||||
{
|
||||
return new ChainDemo(app);
|
||||
}
|
||||
|
||||
ChainDemo(SimpleOpenGL3App* app);
|
||||
virtual ~ChainDemo();
|
||||
|
||||
void createGround(int cubeShapeId);
|
||||
|
||||
virtual void initPhysics();
|
||||
virtual void exitPhysics();
|
||||
virtual void renderScene();
|
||||
virtual void stepSimulation(float dt);
|
||||
};
|
||||
|
||||
|
||||
#endif //CHAIN_DEMO_H
|
||||
@@ -29,6 +29,7 @@ static float friction = 1.;
|
||||
#include "BulletCollision/CollisionShapes/btShapeHull.h"
|
||||
|
||||
#define CONSTRAINT_DEBUG_SIZE 0.2f
|
||||
static bool prevCanSleep = false;
|
||||
|
||||
struct GraphicsVertex
|
||||
{
|
||||
@@ -243,6 +244,8 @@ bool Bullet2MultiBodyDemo::mouseButtonCallback(int button, int state, float x, f
|
||||
btMultiBodyLinkCollider* multiCol = (btMultiBodyLinkCollider*)btMultiBodyLinkCollider::upcast(rayCallback.m_collisionObject);
|
||||
if (multiCol && multiCol->m_multiBody)
|
||||
{
|
||||
|
||||
prevCanSleep = multiCol->m_multiBody->getCanSleep();
|
||||
multiCol->m_multiBody->setCanSleep(false);
|
||||
|
||||
btVector3 pivotInA = multiCol->m_multiBody->worldPosToLocal(multiCol->m_link, pickPos);
|
||||
@@ -285,7 +288,7 @@ bool Bullet2MultiBodyDemo::mouseButtonCallback(int button, int state, float x, f
|
||||
|
||||
if (m_pickingMultiBodyPoint2Point)
|
||||
{
|
||||
m_pickingMultiBodyPoint2Point->getMultiBodyA()->setCanSleep(true);
|
||||
m_pickingMultiBodyPoint2Point->getMultiBodyA()->setCanSleep(prevCanSleep);
|
||||
btMultiBodyDynamicsWorld* world = (btMultiBodyDynamicsWorld*) m_dynamicsWorld;
|
||||
world->removeMultiBodyConstraint(m_pickingMultiBodyPoint2Point);
|
||||
delete m_pickingMultiBodyPoint2Point;
|
||||
|
||||
Reference in New Issue
Block a user