- Added btRigidBodyConstructionInfo, to make it easier to set individual setting (and leave other untouched) during rigid body construction.
This was harder using default arguments. Thanks Vangelis Kokkevis for pointing this out. - Fixed memoryleak in the ConstraintDemo and Raytracer demo. - fixed issue with clearing forces/gravity at the end of the stepSimulation, instead of during internalSingleStepSimulation. Thanks chunky for pointing this out: http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1780 - Disabled additional damping in rigid body by default, but enable it in most demos. Set btRigidBodyConstructionInfo m_additionalDamping to true to enable this. - Removed obsolete QUICKPROF BEGIN/END_PROFILE, and enabled BT_PROFILE. Profiling is enabled by default (see Bullet/Demos/OpenGL/DemoApplication.cpp how to use this). User can switch off profiling by enabling define BT_NO_PROFILE in Bullet/src/btQuickprof.h.
This commit is contained in:
@@ -99,15 +99,17 @@ btDemoEntry g_demoEntries[] =
|
||||
{
|
||||
{"DynamicControlDemo",MotorDemo::Create},
|
||||
{"RagdollDemo",RagdollDemo::Create},
|
||||
{"BasicDemo", BasicDemo::Create},
|
||||
{"CcdPhysicsDemo", CcdPhysicsDemo::Create},
|
||||
{"ConcaveDemo",ConcaveDemo::Create},
|
||||
{"ConcaveRaycastDemo",ConcaveRaycastDemo::Create},
|
||||
{"ConcaveConvexcastDemo",ConcaveConvexcastDemo::Create},
|
||||
{"ConvexDecomposition",ConvexDecompositionDemo::Create},
|
||||
{"BasicDemo", BasicDemo::Create},
|
||||
{"BspDemo", BspDemo::Create},
|
||||
{"Gimpact Test", GimpactConcaveDemo::Create},
|
||||
#ifndef BT_USE_DOUBLE_PRECISION
|
||||
{"MultiThreaded", MultiThreadedDemo::Create},
|
||||
#endif //BT_USE_DOUBLE_PRECISION
|
||||
{"Raytracer Test",Raytracer::Create},
|
||||
{"GjkConvexCast",LinearConvexCastDemo::Create},
|
||||
{"VehicleDemo",VehicleDemo::Create},
|
||||
|
||||
@@ -125,7 +125,8 @@ void BasicDemo::initPhysics()
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||
btRigidBody* body = new btRigidBody(mass,myMotionState,groundShape,localInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
//add the body to the dynamics world
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
@@ -171,7 +172,8 @@ void BasicDemo::initPhysics()
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody* body = new btRigidBody(mass,myMotionState,colShape,localInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,8 @@ class MyColladaConverter : public ColladaConverter
|
||||
{
|
||||
if (!bodyOther)
|
||||
{
|
||||
bodyOther = new btRigidBody(0,0,0);
|
||||
btRigidBody::btRigidBodyConstructionInfo cinfo(0,0,0);
|
||||
bodyOther = new btRigidBody(cinfo);
|
||||
|
||||
bodyOther->setWorldTransform(bodyRef->getWorldTransform());
|
||||
localAttachmentOther = localAttachmentFrameRef;
|
||||
|
||||
@@ -114,7 +114,6 @@ void ConstraintDemo::initPhysics()
|
||||
}
|
||||
|
||||
|
||||
|
||||
//create a slider, using the generic D6 constraint
|
||||
{
|
||||
mass = 1.f;
|
||||
@@ -130,6 +129,7 @@ void ConstraintDemo::initPhysics()
|
||||
d6body0 = localCreateRigidBody( mass,trans,shape);
|
||||
d6body0->setActivationState(DISABLE_DEACTIVATION);
|
||||
btRigidBody* fixedBody1 = localCreateRigidBody(0,trans,0);
|
||||
m_dynamicsWorld->addRigidBody(fixedBody1);
|
||||
|
||||
btTransform frameInA, frameInB;
|
||||
frameInA = btTransform::getIdentity();
|
||||
@@ -154,8 +154,17 @@ ConstraintDemo::~ConstraintDemo()
|
||||
{
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
|
||||
//removed/delete constraints
|
||||
for (i=m_dynamicsWorld->getNumConstraints()-1; i>=0 ;i--)
|
||||
{
|
||||
btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i);
|
||||
m_dynamicsWorld->removeConstraint(constraint);
|
||||
delete constraint;
|
||||
}
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
@@ -168,6 +177,9 @@ ConstraintDemo::~ConstraintDemo()
|
||||
delete obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//delete collision shapes
|
||||
for (int j=0;j<m_collisionShapes.size();j++)
|
||||
{
|
||||
|
||||
@@ -96,7 +96,8 @@ class TestRig
|
||||
shape->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody* body = new btRigidBody(mass,myMotionState,shape,localInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
m_ownerWorld->addRigidBody(body);
|
||||
|
||||
|
||||
@@ -363,7 +363,9 @@ btRigidBody* RagDoll::localCreateRigidBody (btScalar mass, const btTransform& st
|
||||
shape->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody* body = new btRigidBody(mass,myMotionState,shape,localInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
|
||||
rbInfo.m_additionalDamping = true;
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
m_ownerWorld->addRigidBody(body);
|
||||
|
||||
|
||||
@@ -69,7 +69,8 @@ int main(int argc, char** argv)
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
|
||||
btRigidBody* body = new btRigidBody(mass,myMotionState,groundShape,localInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
//add the body to the dynamics world
|
||||
dynamicsWorld->addRigidBody(body);
|
||||
@@ -100,7 +101,8 @@ int main(int argc, char** argv)
|
||||
|
||||
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody* body = new btRigidBody(mass,myMotionState,colShape,localInertia);
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
dynamicsWorld->addRigidBody(body);
|
||||
}
|
||||
|
||||
@@ -13,32 +13,11 @@ subject to the following restrictions:
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
//enable just one, DO_BENCHMARK_PYRAMIDS or DO_WALL
|
||||
#define DO_BENCHMARK_PYRAMIDS 1
|
||||
//#define DO_WALL 1
|
||||
|
||||
//Note: some of those settings need 'DO_WALL' demo
|
||||
//#define USE_KINEMATIC_GROUND 1
|
||||
//#define PRINT_CONTACT_STATISTICS 1
|
||||
//#define REGISTER_BOX_BOX 1 //needs to be used in combination with REGISTER_CUSTOM_COLLISION_ALGORITHM
|
||||
//#define USER_DEFINED_FRICTION_MODEL 1
|
||||
//#define USE_CUSTOM_NEAR_CALLBACK 1
|
||||
//#define CENTER_OF_MASS_SHIFT 1
|
||||
//#define VERBOSE_TIMESTEPPING_CONSOLEOUTPUT 1
|
||||
|
||||
//#define USE_PARALLEL_SOLVER 1 //experimental parallel solver
|
||||
#define USE_PARALLEL_DISPATCHER 1
|
||||
|
||||
//following define allows to compare/replace Bullet's constraint solver with ODE quickstep
|
||||
//this define requires to either add the libquickstep library (win32, see msvc/8/libquickstep.vcproj) or manually add the files from Extras/quickstep
|
||||
//#define COMPARE_WITH_QUICKSTEP 1
|
||||
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
#include "BulletCollision/CollisionDispatch/btSphereSphereCollisionAlgorithm.h"
|
||||
#ifdef REGISTER_BOX_BOX
|
||||
#include "../Extras/AlternativeCollisionAlgorithms/BoxBoxCollisionAlgorithm.h"
|
||||
#endif //REGISTER_BOX_BOX
|
||||
#include "BulletCollision/CollisionDispatch/btSphereTriangleCollisionAlgorithm.h"
|
||||
|
||||
#ifdef USE_PARALLEL_DISPATCHER
|
||||
@@ -65,9 +44,6 @@ subject to the following restrictions:
|
||||
#endif//USE_PARALLEL_DISPATCHER
|
||||
|
||||
|
||||
#ifdef COMPARE_WITH_QUICKSTEP
|
||||
#include "../Extras/quickstep/OdeConstraintSolver.h"
|
||||
#endif //COMPARE_WITH_QUICKSTEP
|
||||
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
@@ -133,10 +109,6 @@ void MultiThreadedDemo::createStack( btCollisionShape* boxShape, float halfCubeS
|
||||
|
||||
btRigidBody* body = 0;
|
||||
body = localCreateRigidBody(mass,trans,boxShape);
|
||||
#ifdef USER_DEFINED_FRICTION_MODEL
|
||||
///Advanced use: override the friction solver
|
||||
body->m_frictionSolverType = USER_CONTACT_SOLVER_TYPE1;
|
||||
#endif //USER_DEFINED_FRICTION_MODEL
|
||||
|
||||
}
|
||||
}
|
||||
@@ -164,25 +136,6 @@ void MultiThreadedDemo::clientMoveAndDisplay()
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
||||
#ifdef USE_KINEMATIC_GROUND
|
||||
//btQuaternion kinRotation(btVector3(0,0,1),0.);
|
||||
btVector3 kinTranslation(-0.01,0,0);
|
||||
//kinematic object
|
||||
btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[0];
|
||||
//is this a rigidbody with a motionstate? then use the motionstate to update positions!
|
||||
if (btRigidBody::upcast(colObj) && btRigidBody::upcast(colObj)->getMotionState())
|
||||
{
|
||||
btTransform newTrans;
|
||||
btRigidBody::upcast(colObj)->getMotionState()->getWorldTransform(newTrans);
|
||||
newTrans.getOrigin()+=kinTranslation;
|
||||
btRigidBody::upcast(colObj)->getMotionState()->setWorldTransform(newTrans);
|
||||
} else
|
||||
{
|
||||
m_dynamicsWorld->getCollisionObjectArray()[0]->getWorldTransform().getOrigin() += kinTranslation;
|
||||
}
|
||||
|
||||
#endif //USE_KINEMATIC_GROUND
|
||||
|
||||
|
||||
float dt = m_clock.getTimeMicroseconds() * 0.000001f;
|
||||
m_clock.reset();
|
||||
@@ -243,12 +196,6 @@ void MultiThreadedDemo::clientMoveAndDisplay()
|
||||
btProfiler::endBlock("render");
|
||||
#endif
|
||||
glFlush();
|
||||
//some additional debugging info
|
||||
#ifdef PRINT_CONTACT_STATISTICS
|
||||
printf("num manifolds: %i\n",gNumManifold);
|
||||
printf("num gOverlappingPairs: %i\n",gOverlappingPairs);
|
||||
printf("num gTotalContactPoints : %i\n",gTotalContactPoints );
|
||||
#endif //PRINT_CONTACT_STATISTICS
|
||||
|
||||
gTotalContactPoints = 0;
|
||||
glutSwapBuffers();
|
||||
@@ -291,21 +238,13 @@ void MultiThreadedDemo::initPhysics()
|
||||
m_collisionShapes.push_back(new btBoxShape (btVector3(200,CUBE_HALF_EXTENTS,200)));
|
||||
#endif
|
||||
|
||||
#ifdef DO_BENCHMARK_PYRAMIDS
|
||||
m_collisionShapes.push_back(new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)));
|
||||
#else
|
||||
m_collisionShapes.push_back(new btCylinderShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)));
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef DO_BENCHMARK_PYRAMIDS
|
||||
setCameraDistance(32.5f);
|
||||
#endif
|
||||
|
||||
#ifdef DO_BENCHMARK_PYRAMIDS
|
||||
m_azi = 90.f;
|
||||
#endif //DO_BENCHMARK_PYRAMIDS
|
||||
|
||||
m_dispatcher=0;
|
||||
m_collisionConfiguration = new btDefaultCollisionConfiguration();
|
||||
@@ -360,28 +299,12 @@ int maxNumOutstandingTasks = 4;
|
||||
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
|
||||
#endif //USE_PARALLEL_DISPATCHER
|
||||
|
||||
#ifdef USE_CUSTOM_NEAR_CALLBACK
|
||||
//this is optional
|
||||
m_dispatcher->setNearCallback(customNearCallback);
|
||||
#endif
|
||||
|
||||
btVector3 worldAabbMin(-1000,-1000,-1000);
|
||||
btVector3 worldAabbMax(1000,1000,1000);
|
||||
|
||||
m_broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
|
||||
/// For large worlds or over 16384 objects, use the bt32BitAxisSweep3 broadphase
|
||||
// m_broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
|
||||
/// When trying to debug broadphase issues, try to use the btSimpleBroadphase
|
||||
// m_broadphase = new btSimpleBroadphase;
|
||||
|
||||
//box-box is in Extras/AlternativeCollisionAlgorithms:it requires inclusion of those files
|
||||
#ifdef REGISTER_BOX_BOX
|
||||
m_dispatcher->registerCollisionCreateFunc(BOX_SHAPE_PROXYTYPE,BOX_SHAPE_PROXYTYPE,new BoxBoxCollisionAlgorithm::CreateFunc);
|
||||
#endif //REGISTER_BOX_BOX
|
||||
|
||||
#ifdef COMPARE_WITH_QUICKSTEP
|
||||
m_solver = new OdeConstraintSolver();
|
||||
#else
|
||||
|
||||
|
||||
#ifdef USE_PARALLEL_SOLVER
|
||||
@@ -411,9 +334,6 @@ int maxNumOutstandingTasks = 4;
|
||||
|
||||
#endif //USE_PARALLEL_SOLVER
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
|
||||
m_dynamicsWorld = world;
|
||||
|
||||
@@ -441,7 +361,6 @@ int maxNumOutstandingTasks = 4;
|
||||
}
|
||||
|
||||
|
||||
#ifdef DO_BENCHMARK_PYRAMIDS
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
|
||||
@@ -463,9 +382,6 @@ int maxNumOutstandingTasks = 4;
|
||||
float zPos = (i-numWalls/2) * wallDistance;
|
||||
createStack(m_collisionShapes[shapeIndex[1]],halfExtents,wallHeight,zPos);
|
||||
}
|
||||
// createStack(m_collisionShapes[shapeIndex[1]],halfExtends,20,10);
|
||||
|
||||
// createStack(m_collisionShapes[shapeIndex[1]],halfExtends,20,20);
|
||||
#define DESTROYER_BALL 1
|
||||
#ifdef DESTROYER_BALL
|
||||
btTransform sphereTrans;
|
||||
@@ -476,7 +392,6 @@ int maxNumOutstandingTasks = 4;
|
||||
btRigidBody* ballBody = localCreateRigidBody(10000.f,sphereTrans,ball);
|
||||
ballBody->setLinearVelocity(btVector3(0,0,-10));
|
||||
#endif
|
||||
#endif //DO_BENCHMARK_PYRAMIDS
|
||||
// clientResetScene();
|
||||
|
||||
|
||||
|
||||
@@ -489,7 +489,7 @@ void DemoApplication::shootBox(const btVector3& destination)
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
{
|
||||
float mass = 100.f;
|
||||
float mass = 10.f;
|
||||
btTransform startTransform;
|
||||
startTransform.setIdentity();
|
||||
btVector3 camPos = getCameraPosition();
|
||||
@@ -502,7 +502,7 @@ void DemoApplication::shootBox(const btVector3& destination)
|
||||
btConvexShape* childShape = new btBoxShape(btVector3(1.f,1.f,1.f));
|
||||
m_shootBoxShape = new btUniformScalingShape(childShape,0.5f);
|
||||
#else
|
||||
m_shootBoxShape = new btBoxShape(btVector3(0.5f,0.5f,0.5f));
|
||||
m_shootBoxShape = new btBoxShape(btVector3(1.f,1.f,1.f));
|
||||
#endif//
|
||||
}
|
||||
|
||||
@@ -736,7 +736,7 @@ btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform
|
||||
#define USE_MOTIONSTATE 1
|
||||
#ifdef USE_MOTIONSTATE
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody* body = new btRigidBody(mass,myMotionState,shape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(btRigidBody::btRigidBodyConstructionInfo(mass,myMotionState,shape,localInertia));
|
||||
|
||||
#else
|
||||
btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
|
||||
|
||||
@@ -98,7 +98,9 @@ class RagDoll
|
||||
shape->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody* body = new btRigidBody(mass,myMotionState,shape,localInertia);
|
||||
|
||||
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,shape,localInertia);
|
||||
btRigidBody* body = new btRigidBody(rbInfo);
|
||||
|
||||
m_ownerWorld->addRigidBody(body);
|
||||
|
||||
|
||||
@@ -133,6 +133,28 @@ void Raytracer::initPhysics()
|
||||
Raytracer::~Raytracer()
|
||||
{
|
||||
|
||||
//cleanup in the reverse order of creation/initialization
|
||||
|
||||
//remove the rigidbodies from the dynamics world and delete them
|
||||
int i;
|
||||
for (i=m_collisionWorld->getNumCollisionObjects()-1; i>=0 ;i--)
|
||||
{
|
||||
btCollisionObject* obj = m_collisionWorld->getCollisionObjectArray()[i];
|
||||
m_collisionWorld->removeCollisionObject( obj );
|
||||
delete obj;
|
||||
}
|
||||
|
||||
//delete collision world
|
||||
delete m_collisionWorld;
|
||||
|
||||
//delete broadphase
|
||||
delete m_overlappingPairCache;
|
||||
|
||||
//delete dispatcher
|
||||
delete m_dispatcher;
|
||||
|
||||
delete m_collisionConfiguration;
|
||||
|
||||
delete raytracePicture;
|
||||
raytracePicture=0;
|
||||
}
|
||||
|
||||
@@ -147,9 +147,6 @@ VehicleDemo::~VehicleDemo()
|
||||
|
||||
void VehicleDemo::initPhysics()
|
||||
{
|
||||
|
||||
extern btScalar gJitterVelocityDampingFactor;
|
||||
gJitterVelocityDampingFactor = 1.f;
|
||||
|
||||
#ifdef FORCE_ZAXIS_UP
|
||||
m_cameraUp = btVector3(0,0,1);
|
||||
|
||||
Reference in New Issue
Block a user