processed a lot of feedback: added 'realtime' simulation with fixed substeps (and clamping maximum number of substeps), this means that when stepSimulation is called with smaller timesteps then 'fixed substep' the motionstate is interpolated.
renamed m_ccdSweptSphereRadius, enabled wireframe debugDrawObject (using debugDrawer)
This commit is contained in:
@@ -38,7 +38,7 @@ int main(int argc,char** argv)
|
||||
|
||||
BasicDemo ccdDemo;
|
||||
ccdDemo.initPhysics();
|
||||
ccdDemo.setCameraDistance(50.f);
|
||||
ccdDemo.setCameraDistance(10.f);
|
||||
|
||||
#ifdef CHECK_MEMORY_LEAKS
|
||||
ccdDemo.exitPhysics();
|
||||
@@ -60,8 +60,11 @@ void BasicDemo::clientMoveAndDisplay()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
//simple dynamics world doesn't handle fixed-time-stepping
|
||||
float ms = m_clock.getTimeMilliseconds();
|
||||
m_clock.reset();
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
m_dynamicsWorld->stepSimulation(ms / 1000.f);
|
||||
|
||||
renderme();
|
||||
|
||||
@@ -95,13 +98,6 @@ void BasicDemo::displayCallback(void) {
|
||||
|
||||
|
||||
|
||||
///make this positive to show stack falling from a distance
|
||||
///this shows the penalty tresholds in action, springy/spungy look
|
||||
|
||||
void BasicDemo::clientResetScene()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BasicDemo::initPhysics()
|
||||
{
|
||||
@@ -164,7 +160,7 @@ void BasicDemo::initPhysics()
|
||||
btTransform trans;
|
||||
trans.setIdentity();
|
||||
//stack them
|
||||
int colsize = 10;
|
||||
int colsize = 2;
|
||||
int row = (i*HALF_EXTENTS*2)/(colsize*2*HALF_EXTENTS);
|
||||
int row2 = row;
|
||||
int col = (i)%(colsize)-colsize/2;
|
||||
|
||||
@@ -52,7 +52,6 @@ class BasicDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -30,9 +30,7 @@ class BspDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ subject to the following restrictions:
|
||||
|
||||
#include "btBulletDynamicsCommon.h"
|
||||
|
||||
#ifdef COMPARE_WITH_QUICKSTEP 1
|
||||
#ifdef COMPARE_WITH_QUICKSTEP
|
||||
#include "../Extras/quickstep/OdeConstraintSolver.h"
|
||||
#endif //COMPARE_WITH_QUICKSTEP
|
||||
|
||||
@@ -114,6 +114,7 @@ GLDebugDrawer debugDrawer;
|
||||
int main(int argc,char** argv)
|
||||
{
|
||||
|
||||
|
||||
CcdPhysicsDemo* ccdDemo = new CcdPhysicsDemo();
|
||||
|
||||
ccdDemo->initPhysics();
|
||||
@@ -141,8 +142,32 @@ void CcdPhysicsDemo::clientMoveAndDisplay()
|
||||
m_dynamicsWorld->getCollisionObjectArray()[0]->m_worldTransform.getOrigin() += kinTranslation;
|
||||
#endif //USE_KINEMATIC_GROUND
|
||||
|
||||
float dt = m_clock.getTimeMilliseconds() * 0.001f;
|
||||
m_clock.reset();
|
||||
printf("dt = %f: ",dt);
|
||||
|
||||
if (m_dynamicsWorld)
|
||||
m_dynamicsWorld->stepSimulation(deltaTime);
|
||||
{
|
||||
//during idle mode, just run 1 simulation step maximum
|
||||
int maxSimSubSteps = m_idle ? 1 : 1;
|
||||
if (m_idle)
|
||||
dt = 1.0/420.f;
|
||||
|
||||
int numSimSteps = m_dynamicsWorld->stepSimulation(dt,maxSimSubSteps);
|
||||
if (!numSimSteps)
|
||||
printf("Interpolated transforms\n");
|
||||
else
|
||||
{
|
||||
if (numSimSteps > maxSimSubSteps)
|
||||
{
|
||||
//detect dropping frames
|
||||
printf("Dropped (%i) simulation steps out of %i\n",numSimSteps - maxSimSubSteps,numSimSteps);
|
||||
} else
|
||||
{
|
||||
printf("Simulated (%i) steps\n",numSimSteps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_QUICKPROF
|
||||
btProfiler::beginBlock("render");
|
||||
@@ -183,59 +208,6 @@ void CcdPhysicsDemo::displayCallback(void) {
|
||||
|
||||
|
||||
|
||||
///make this positive to show stack falling from a distance
|
||||
///this shows the penalty tresholds in action, springy/spungy look
|
||||
|
||||
void CcdPhysicsDemo::clientResetScene()
|
||||
{
|
||||
|
||||
/*
|
||||
int i;
|
||||
int numObjects = m_physicsEnvironmentPtr->GetNumControllers();
|
||||
|
||||
for (i=0;i<numObjects;i++)
|
||||
{
|
||||
//skip the first object (static ground)
|
||||
if (i>0)
|
||||
{
|
||||
CcdPhysicsController* ctrl = m_physicsEnvironmentPtr->GetPhysicsController(i);
|
||||
|
||||
if ((getDebugMode() & btIDebugDraw::DBG_NoHelpText))
|
||||
{
|
||||
if (ctrl->getRigidBody()->getCollisionShape()->getShapeType() != SPHERE_SHAPE_PROXYTYPE)
|
||||
{
|
||||
ctrl->getRigidBody()->SetCollisionShape(shapePtr[2]);
|
||||
} else
|
||||
{
|
||||
ctrl->getRigidBody()->SetCollisionShape(shapePtr[1]);
|
||||
}
|
||||
|
||||
btBroadphaseProxy* bpproxy = ctrl->getRigidBody()->m_broadphaseHandle;
|
||||
m_physicsEnvironmentPtr->getBroadphase()->cleanProxyFromPairs(bpproxy);
|
||||
}
|
||||
|
||||
//stack them
|
||||
int colsize = 10;
|
||||
int row = (i*CUBE_HALF_EXTENTS*2)/(colsize*2*CUBE_HALF_EXTENTS);
|
||||
int row2 = row;
|
||||
int col = (i)%(colsize)-colsize/2;
|
||||
|
||||
|
||||
if (col>3)
|
||||
{
|
||||
col=11;
|
||||
row2 |=1;
|
||||
}
|
||||
ctrl->setPosition(col*2*CUBE_HALF_EXTENTS + (row2%2)*CUBE_HALF_EXTENTS,
|
||||
row*2*CUBE_HALF_EXTENTS+CUBE_HALF_EXTENTS+EXTRA_HEIGHT,0);
|
||||
ctrl->setOrientation(0,0,0,1);
|
||||
ctrl->SetLinearVelocity(0,0,0,false);
|
||||
ctrl->SetAngularVelocity(0,0,0,false);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
///User-defined friction model, the most simple friction model available: no friction
|
||||
@@ -368,7 +340,7 @@ void CcdPhysicsDemo::initPhysics()
|
||||
body->m_ccdSquareMotionTreshold = CUBE_HALF_EXTENTS;
|
||||
|
||||
//Experimental: better estimation of CCD Time of Impact:
|
||||
body->m_ccdSweptShereRadius = 0.2*CUBE_HALF_EXTENTS;
|
||||
body->m_ccdSweptSphereRadius = 0.2*CUBE_HALF_EXTENTS;
|
||||
|
||||
#ifdef USER_DEFINED_FRICTION_MODEL
|
||||
///Advanced use: override the friction solver
|
||||
|
||||
@@ -28,7 +28,6 @@ class CcdPhysicsDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -29,9 +29,6 @@ class ColladaDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void keyboardCallback(unsigned char key, int x, int y);
|
||||
|
||||
|
||||
@@ -28,9 +28,6 @@ class CollisionDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif //COLLISION_DEMO_H
|
||||
|
||||
@@ -29,7 +29,6 @@ class ConcaveDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -192,23 +192,6 @@ void ConcaveDemo::clientMoveAndDisplay()
|
||||
|
||||
}
|
||||
|
||||
void ConcaveDemo::clientResetScene()
|
||||
{
|
||||
/*int numObj = m_physicsEnvironmentPtr->GetNumControllers();
|
||||
|
||||
//skip ground
|
||||
for (int i=1;i<numObj;i++)
|
||||
{
|
||||
CcdPhysicsController* ctrl = m_physicsEnvironmentPtr->GetPhysicsController(i);
|
||||
ctrl->setPosition(2*i,1,1);
|
||||
ctrl->setOrientation(0,0,0,1);
|
||||
ctrl->SetLinearVelocity(0,0,0,0);
|
||||
ctrl->SetAngularVelocity(0,0,0,0);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,9 +28,7 @@ class ConstraintDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //CONSTRAINT_DEMO_H
|
||||
|
||||
@@ -28,9 +28,7 @@ class btContinuousConvexCollisionDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //CONTINUOUS_CONVEX_COLLISION_DEMO_H
|
||||
|
||||
@@ -28,10 +28,7 @@ class ConvexDecompositionDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene()
|
||||
{
|
||||
//not yet
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -28,9 +28,7 @@ class LinearConvexCastDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //LINEAR_CONVEX_CAST_DEMO_H
|
||||
|
||||
@@ -21,8 +21,12 @@ subject to the following restrictions:
|
||||
#include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"//picking
|
||||
#include "BulletCollision/CollisionShapes/btCollisionShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btBoxShape.h"
|
||||
#include "BulletCollision/CollisionShapes/btCompoundShape.h"
|
||||
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "LinearMath/btQuickprof.h"
|
||||
#include "LinearMath/btDefaultMotionState.h"
|
||||
|
||||
#include "BMF_Api.h"
|
||||
|
||||
extern bool gDisableDeactivation;
|
||||
@@ -646,7 +650,9 @@ btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform
|
||||
if (isDynamic)
|
||||
shape->calculateLocalInertia(mass,localInertia);
|
||||
|
||||
btRigidBody* body = new btRigidBody(mass,startTransform,shape,localInertia);
|
||||
btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
|
||||
btRigidBody* body = new btRigidBody(mass,myMotionState,shape,localInertia);
|
||||
body->m_userObjectPointer = myMotionState;
|
||||
|
||||
m_dynamicsWorld->addRigidBody(body);
|
||||
|
||||
@@ -656,7 +662,6 @@ btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform
|
||||
|
||||
|
||||
|
||||
|
||||
void DemoApplication::renderme()
|
||||
{
|
||||
updateCamera();
|
||||
@@ -670,7 +675,15 @@ void DemoApplication::renderme()
|
||||
for (int i=0;i<numObjects;i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
colObj->m_worldTransform.getOpenGLMatrix(m);
|
||||
|
||||
if (colObj->m_userObjectPointer)
|
||||
{
|
||||
btDefaultMotionState* myMotionState = (btDefaultMotionState*)colObj->m_userObjectPointer;
|
||||
myMotionState->m_graphicsWorldTrans.getOpenGLMatrix(m);
|
||||
} else
|
||||
{
|
||||
colObj->m_worldTransform.getOpenGLMatrix(m);
|
||||
}
|
||||
|
||||
btVector3 wireColor(1.f,1.0f,0.5f); //wants deactivation
|
||||
if (i & 1)
|
||||
@@ -798,3 +811,27 @@ void DemoApplication::renderme()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DemoApplication::clientResetScene()
|
||||
{
|
||||
int numObjects = m_dynamicsWorld->getNumCollisionObjects();
|
||||
|
||||
for (int i=0;i<numObjects;i++)
|
||||
{
|
||||
btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
|
||||
|
||||
if (colObj->m_userObjectPointer)
|
||||
{
|
||||
btDefaultMotionState* myMotionState = (btDefaultMotionState*)colObj->m_userObjectPointer;
|
||||
myMotionState->m_graphicsWorldTrans = myMotionState->m_startWorldTrans;
|
||||
colObj->m_worldTransform = myMotionState->m_graphicsWorldTrans;
|
||||
colObj->m_interpolationWorldTransform = myMotionState->m_startWorldTrans;
|
||||
btRigidBody* body = btRigidBody::upcast(colObj);
|
||||
if (body && !body->isStaticObject())
|
||||
{
|
||||
btRigidBody::upcast(colObj)->setLinearVelocity(btVector3(0,0,0));
|
||||
btRigidBody::upcast(colObj)->setAngularVelocity(btVector3(0,0,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ subject to the following restrictions:
|
||||
#include "LinearMath/btVector3.h"
|
||||
#include "LinearMath/btMatrix3x3.h"
|
||||
#include "LinearMath/btTransform.h"
|
||||
#include "LinearMath/btQuickProf.h"
|
||||
|
||||
class btCollisionShape;
|
||||
class btDynamicsWorld;
|
||||
@@ -50,6 +51,8 @@ class DemoApplication
|
||||
protected:
|
||||
|
||||
|
||||
hidden::Clock m_clock;
|
||||
|
||||
///this is the most important class
|
||||
btDynamicsWorld* m_dynamicsWorld;
|
||||
|
||||
@@ -134,7 +137,7 @@ public:
|
||||
|
||||
virtual void clientMoveAndDisplay() = 0;
|
||||
|
||||
virtual void clientResetScene() =0 ;
|
||||
virtual void clientResetScene();
|
||||
|
||||
///Demo functions
|
||||
void shootBox(const btVector3& destination);
|
||||
|
||||
@@ -28,9 +28,7 @@ class Raytracer : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //RAYTRACER_H
|
||||
|
||||
@@ -28,9 +28,7 @@ class SimplexDemo : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //SIMPLEX_DEMO_H
|
||||
|
||||
@@ -154,23 +154,7 @@ void UserCollisionAlgorithm::clientMoveAndDisplay()
|
||||
|
||||
}
|
||||
|
||||
void UserCollisionAlgorithm::clientResetScene()
|
||||
{
|
||||
/*
|
||||
int numObj = m_physicsEnvironmentPtr->GetNumControllers();
|
||||
|
||||
//skip ground
|
||||
for (int i=1;i<numObj;i++)
|
||||
{
|
||||
CcdPhysicsController* ctrl = m_physicsEnvironmentPtr->GetPhysicsController(i);
|
||||
ctrl->setPosition(1,2*i,1);
|
||||
ctrl->setOrientation(0,0,0,1);
|
||||
ctrl->SetLinearVelocity(0,0,0,0);
|
||||
ctrl->SetAngularVelocity(0,0,0,0);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ class UserCollisionAlgorithm : public DemoApplication
|
||||
|
||||
virtual void displayCallback();
|
||||
|
||||
virtual void clientResetScene();
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user