Enable graphical benchmark by default in cmake

Toggle between point to point and generic 6dof constraint for mouse picking in the demos

Use a 'equal vertex thresdhold' in the btVoronoiSimplexSolver of  0.0001f by default.
This can be disabled (or configured) using defaultCollisionConfiguration->getSimplexSolver()->setEqualVertexThreshold(0.f);
See http://code.google.com/p/bullet/issues/detail?id=305
This commit is contained in:
erwin.coumans
2010-02-24 01:28:23 +00:00
parent 1425feec26
commit e156967762
6 changed files with 136 additions and 62 deletions

View File

@@ -14,7 +14,7 @@ ENDIF (NOT CMAKE_BUILD_TYPE)
OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF)
OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" OFF)
OPTION(USE_GRAPHICAL_BENCHMARK "Use Graphical Benchmark" ON)
OPTION(USE_MULTITHREADED_BENCHMARK "Use Multithreaded Benchmark" OFF)
IF (USE_MULTITHREADED_BENCHMARK)

View File

@@ -41,6 +41,7 @@ subject to the following restrictions:
#endif
#undef USE_PARALLEL_SOLVER_BENCHMARK
#ifdef USE_PARALLEL_SOLVER_BENCHMARK
#include "BulletMultiThreaded/btParallelConstraintSolver.h"
#endif

View File

@@ -17,7 +17,7 @@ subject to the following restrictions:
#include "DemoApplication.h"
#include "LinearMath/btIDebugDraw.h"
#include "BulletDynamics/Dynamics/btDynamicsWorld.h"
//#define USE_6DOF 1
#include "BulletDynamics/ConstraintSolver/btPoint2PointConstraint.h"//picking
#include "BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h"//picking
@@ -33,7 +33,7 @@ subject to the following restrictions:
#include "LinearMath/btSerializer.h"
#include "GLDebugFont.h"
static bool use6Dof = false;
extern bool gDisableDeactivation;
int numObjects = 0;
const int maxNumObjects = 16384;
@@ -554,6 +554,7 @@ void DemoApplication::shootBox(const btVector3& destination)
btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_shootBoxShape);
body->setLinearFactor(btVector3(1,1,1));
//body->setRestitution(1);
btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
linVel.normalize();
@@ -784,7 +785,9 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
#ifdef USE_6DOF
if (use6Dof)
{
btTransform tr;
tr.setIdentity();
tr.setOrigin(localPivot);
@@ -797,22 +800,45 @@ void DemoApplication::mouseFunc(int button, int state, int x, int y)
m_dynamicsWorld->addConstraint(dof6);
m_pickConstraint = dof6;
#else
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,0);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,1);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,2);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,3);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,4);
dof6->setParam(BT_CONSTRAINT_STOP_CFM,0.8,5);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,0);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,1);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,2);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,3);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,4);
dof6->setParam(BT_CONSTRAINT_STOP_ERP,0.1,5);
} else
{
btPoint2PointConstraint* p2p = new btPoint2PointConstraint(*body,localPivot);
m_dynamicsWorld->addConstraint(p2p);
m_pickConstraint = p2p;
p2p->m_setting.m_impulseClamp = mousePickClamping;
//very weak constraint for picking
p2p->m_setting.m_tau = 0.1f;
#endif
p2p->m_setting.m_tau = 0.001f;
/*
p2p->setParam(BT_CONSTRAINT_CFM,0.8,0);
p2p->setParam(BT_CONSTRAINT_CFM,0.8,1);
p2p->setParam(BT_CONSTRAINT_CFM,0.8,2);
p2p->setParam(BT_CONSTRAINT_ERP,0.1,0);
p2p->setParam(BT_CONSTRAINT_ERP,0.1,1);
p2p->setParam(BT_CONSTRAINT_ERP,0.1,2);
*/
}
use6Dof = !use6Dof;
//save mouse position for dragging
gOldPickingPos = rayTo;
gHitPos = pickPos;
gOldPickingDist = (pickPos-rayFrom).length();
}
}
}
@@ -851,23 +877,17 @@ void DemoApplication::mouseMotionFunc(int x,int y)
if (m_pickConstraint)
{
//move the constraint pivot
#ifdef USE_6DOF
btGeneric6DofConstraint* pickCon = static_cast<btGeneric6DofConstraint*>(m_pickConstraint);
#else
btPoint2PointConstraint* pickCon = static_cast<btPoint2PointConstraint*>(m_pickConstraint);
#endif
if (m_pickConstraint->getConstraintType() == D6_CONSTRAINT_TYPE)
{
btGeneric6DofConstraint* pickCon = static_cast<btGeneric6DofConstraint*>(m_pickConstraint);
if (pickCon)
{
//keep it at the same picking distance
btVector3 newRayTo = getRayTo(x,y);
btVector3 rayFrom;
#ifdef USE_6DOF
btVector3 oldPivotInB = pickCon->getFrameOffsetA().getOrigin();
#else
btVector3 oldPivotInB = pickCon->getPivotInB();
#endif
btVector3 newPivotB;
if (m_ortho)
@@ -884,14 +904,37 @@ void DemoApplication::mouseMotionFunc(int x,int y)
newPivotB = rayFrom + dir;
}
#ifdef USE_6DOF
pickCon->getFrameOffsetA().setOrigin(newPivotB);
#else
pickCon->setPivotB(newPivotB);
#endif
}
} else
{
btPoint2PointConstraint* pickCon = static_cast<btPoint2PointConstraint*>(m_pickConstraint);
if (pickCon)
{
//keep it at the same picking distance
btVector3 newRayTo = getRayTo(x,y);
btVector3 rayFrom;
btVector3 oldPivotInB = pickCon->getPivotInB();
btVector3 newPivotB;
if (m_ortho)
{
newPivotB = oldPivotInB;
newPivotB.setX(newRayTo.getX());
newPivotB.setY(newRayTo.getY());
} else
{
rayFrom = m_cameraPosition;
btVector3 dir = newRayTo-rayFrom;
dir.normalize();
dir *= gOldPickingDist;
newPivotB = rayFrom + dir;
}
pickCon->setPivotB(newPivotB);
}
}
}
float dx, dy;

View File

@@ -112,6 +112,11 @@ public:
return m_stackAlloc;
}
virtual btVoronoiSimplexSolver* getSimplexSolver()
{
return m_simplexSolver;
}
virtual btCollisionAlgorithmCreateFunc* getCollisionAlgorithmCreateFunc(int proxyType0,int proxyType1);

View File

@@ -289,7 +289,11 @@ bool btVoronoiSimplexSolver::inSimplex(const btVector3& w)
//w is in the current (reduced) simplex
for (i=0;i<numverts;i++)
{
#ifdef BT_USE_EQUAL_VERTEX_THRESHOLD
if ( m_simplexVectorW[i].distance2(w) <= m_equalVertexThreshold)
#else
if (m_simplexVectorW[i] == w)
#endif
found = true;
}

View File

@@ -24,6 +24,11 @@ subject to the following restrictions:
#define VORONOI_SIMPLEX_MAX_VERTS 5
///disable next define, or use defaultCollisionConfiguration->getSimplexSolver()->setEqualVertexThreshold(0.f) to disable/configure
#define BT_USE_EQUAL_VERTEX_THRESHOLD
#define VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD 0.0001f
struct btUsageBitfield{
btUsageBitfield()
{
@@ -106,8 +111,11 @@ public:
btVector3 m_cachedP2;
btVector3 m_cachedV;
btVector3 m_lastW;
btScalar m_equalVertexThreshold;
bool m_cachedValidClosest;
btSubSimplexClosestResult m_cachedBC;
bool m_needsUpdate;
@@ -122,10 +130,23 @@ public:
public:
btVoronoiSimplexSolver()
: m_equalVertexThreshold(VORONOI_DEFAULT_EQUAL_VERTEX_THRESHOLD)
{
}
void reset();
void addVertex(const btVector3& w, const btVector3& p, const btVector3& q);
void setEqualVertexThreshold(btScalar threshold)
{
m_equalVertexThreshold = threshold;
}
btScalar getEqualVertexThreshold() const
{
return m_equalVertexThreshold;
}
bool closest(btVector3& v);