disable help text by default in AllBulletDemos (text slows down many graphics cards)
improve CollisionDemo.cpp, show multi-contact generation using perturbation improve ColladaConverter: add hinge/point 2 point constraint conversion support, add btScaledTriangleMeshShape support Fix Dynamica MayaPlygin: remove 'active' flag, it has to be replaced by mass=0 for active, mass<>0 for passive Added missing projectfiles Fixed single-shot contact generation. it is disabled by default to improve performance Bugfixes for character controller, thanks to John McCutchan for reporting Constraint solver: better default settings btDefaultAllocator: aligned allocator uses non-aligned allocator (instead of directly malloc/free) disable memalign by default, use Bullet's aligned allocator
This commit is contained in:
@@ -20,7 +20,7 @@ subject to the following restrictions:
|
||||
///
|
||||
|
||||
|
||||
#define CHECK_GENSHER_TRIANGLE_CASE 1
|
||||
//#define CHECK_GENSHER_TRIANGLE_CASE 1
|
||||
|
||||
|
||||
///This low-level internal demo does intentionally NOT use the btBulletCollisionCommon.h header
|
||||
@@ -34,12 +34,15 @@ subject to the following restrictions:
|
||||
#include "BulletCollision/NarrowPhaseCollision/btPointCollector.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h"
|
||||
#include "BulletCollision/CollisionShapes/btTriangleShape.h"
|
||||
#include "BulletCollision/NarrowPhaseCollision/btGjkEpaPenetrationDepthSolver.h"
|
||||
#include "LinearMath/btTransformUtil.h"
|
||||
|
||||
#include "CollisionDemo.h"
|
||||
#include "GL_ShapeDrawer.h"
|
||||
#include "GlutStuff.h"
|
||||
#include "LinearMath/btIDebugDraw.h"
|
||||
#include "../OpenGL/GLDebugDrawer.h"
|
||||
GLDebugDrawer debugDrawer;
|
||||
|
||||
|
||||
float yaw=0.f,pitch=0.f,roll=0.f;
|
||||
@@ -78,7 +81,10 @@ int main(int argc,char** argv)
|
||||
|
||||
void CollisionDemo::initPhysics()
|
||||
{
|
||||
m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
|
||||
setTexturing(false);
|
||||
setShadows(false);
|
||||
|
||||
//m_debugMode |= btIDebugDraw::DBG_DrawWireframe;
|
||||
#ifdef CHECK_GENSHER_TRIANGLE_CASE
|
||||
m_azi = 140.f;
|
||||
#else
|
||||
@@ -86,75 +92,32 @@ void CollisionDemo::initPhysics()
|
||||
#endif
|
||||
m_ele = 25.f;
|
||||
|
||||
tr[0].setOrigin(btVector3(0.0013328250f,8.1363249f,7.0390840f));
|
||||
tr[1].setOrigin(btVector3(0.00000000f,9.1262732f,2.0343180f));
|
||||
m_azi = 0;
|
||||
m_ele = 0;
|
||||
|
||||
//tr[0].setOrigin(btVector3(0,0,0));
|
||||
//tr[1].setOrigin(btVector3(0,10,0));
|
||||
tr[0].setIdentity();
|
||||
tr[0].setOrigin(btVector3(10,0,0));
|
||||
tr[1].setIdentity();
|
||||
tr[1].setOrigin(btVector3(0,0,0));
|
||||
|
||||
btMatrix3x3 basisA;
|
||||
basisA.setValue(0.99999958f,0.00022980258f,0.00090992288f,
|
||||
-0.00029313788f,0.99753088f,0.070228584f,
|
||||
-0.00089153741f,-0.070228823f,0.99753052f);
|
||||
|
||||
btMatrix3x3 basisB;
|
||||
basisB.setValue(1.0000000f,4.4865553e-018f,-4.4410586e-017f,
|
||||
4.4865495e-018f,0.97979438f,0.20000751f,
|
||||
4.4410586e-017f,-0.20000751f,0.97979438f);
|
||||
|
||||
tr[0].setBasis(basisA);
|
||||
tr[1].setBasis(basisB);
|
||||
|
||||
#ifdef CHECK_GENSHER_TRIANGLE_CASE
|
||||
tr[0].setIdentity();
|
||||
tr[1].setIdentity();
|
||||
#endif //CHECK_GENSHER_TRIANGLE_CASE
|
||||
|
||||
btVector3 boxHalfExtentsA(1.0000004768371582f,1.0000004768371582f,1.0000001192092896f);
|
||||
btVector3 boxHalfExtentsB(3.2836332321166992f,3.2836332321166992f,3.2836320400238037f);
|
||||
btVector3 boxHalfExtentsA(1,1,1);//1.0000004768371582f,1.0000004768371582f,1.0000001192092896f);
|
||||
btVector3 boxHalfExtentsB(4,4,4);//3.2836332321166992f,3.2836332321166992f,3.2836320400238037f);
|
||||
|
||||
#ifndef CHECK_GENSHER_TRIANGLE_CASE
|
||||
btBoxShape* boxA = new btBoxShape(boxHalfExtentsA);
|
||||
btBoxShape* boxB = new btBoxShape(boxHalfExtentsB);
|
||||
#endif
|
||||
|
||||
float p1[3], p2[3], p3[3], q1[3],q2[3], q3[3];
|
||||
|
||||
p1[0] = -3.9242966175;
|
||||
p1[1] = -0.5582823175;
|
||||
p1[2] = 2.0101921558;
|
||||
|
||||
p2[0] = -3.6731941700;
|
||||
p2[1] = -0.5604774356;
|
||||
p2[2] = 2.00301921558;
|
||||
|
||||
p3[0] = -3.6698703766;
|
||||
p3[1] = -0.3097069263;
|
||||
p3[2] = 2.0073683262;
|
||||
|
||||
|
||||
|
||||
|
||||
q1[0] = -2.6317186356;
|
||||
q1[1] = -1.0000005960;
|
||||
q1[2] = 1.9999998808;
|
||||
|
||||
q2[0] = -2.6317174435;
|
||||
q2[1] = 0.9999994636;
|
||||
q2[2] = 1.9999998808;
|
||||
|
||||
q3[0] = -4.6317176819;
|
||||
q3[1] = 1.0f;
|
||||
q3[2] = 1.9999998808;
|
||||
|
||||
|
||||
|
||||
btTriangleShape* trishapeA = new btTriangleShape(btVector3(p1[0], p1[1], p1[2]), btVector3(p2[0], p2[1], p2[2]), btVector3(p3[0], p3[1], p3[2]));
|
||||
trishapeA->setMargin(0.001f);
|
||||
|
||||
btTriangleShape* trishapeB = new btTriangleShape(btVector3(q1[0], q1[1], q1[2]), btVector3(q2[0], q2[1], q2[2]), btVector3(q3[0], q3[1], q3[2]));
|
||||
trishapeB->setMargin(0.001f);
|
||||
|
||||
|
||||
|
||||
#ifdef CHECK_GENSHER_TRIANGLE_CASE
|
||||
shapePtr[0] = trishapeA;
|
||||
@@ -176,83 +139,148 @@ void CollisionDemo::clientMoveAndDisplay()
|
||||
static btVoronoiSimplexSolver sGjkSimplexSolver;
|
||||
btSimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver;
|
||||
|
||||
static btScalar gContactBreakingThreshold=.02f;
|
||||
|
||||
|
||||
int checkPerturbation = 1;
|
||||
int numPerturbationIterations = 20;
|
||||
void CollisionDemo::displayCallback(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
|
||||
|
||||
|
||||
btVoronoiSimplexSolver sGjkSimplexSolver;
|
||||
|
||||
btGjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,0);
|
||||
btVoronoiSimplexSolver sGjkSimplexSolver;
|
||||
btGjkEpaPenetrationDepthSolver epaSolver;
|
||||
btPointCollector gjkOutput;
|
||||
btGjkPairDetector::ClosestPointInput input;
|
||||
|
||||
|
||||
|
||||
input.m_transformA = tr[0];
|
||||
input.m_transformB = tr[1];
|
||||
|
||||
convexConvex.getClosestPoints(input, gjkOutput, 0);
|
||||
btVector3 worldBoundsMin(-1000,-1000,-1000);
|
||||
btVector3 worldBoundsMax(1000,1000,1000);
|
||||
{
|
||||
btGjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,&epaSolver);
|
||||
|
||||
btGjkPairDetector::ClosestPointInput input;
|
||||
input.m_transformA = tr[0];
|
||||
input.m_transformB = tr[1];
|
||||
|
||||
|
||||
convexConvex.getClosestPoints(input, gjkOutput, 0);
|
||||
}
|
||||
|
||||
if (gjkOutput.m_hasResult)
|
||||
{
|
||||
//VECCOPY(pa, gjkOutput.m_pointInWorld);
|
||||
//VECCOPY(pb, gjkOutput.m_pointInWorld);
|
||||
//VECADDFAC(pb, pb, gjkOutput.m_normalOnBInWorld, gjkOutput.m_distance);
|
||||
printf("bullet: %10.10f\n", gjkOutput.m_distance); // = 0.24 => that's absolutely wrong!
|
||||
btVector3 endPt = gjkOutput.m_pointInWorld +
|
||||
gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
|
||||
printf("bullet: %10.10f\n", gjkOutput.m_distance);
|
||||
btVector3 endPt = gjkOutput.m_pointInWorld +
|
||||
gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
|
||||
|
||||
debugDrawer.drawLine(gjkOutput.m_pointInWorld,endPt,btVector3(1,0,0));
|
||||
debugDrawer.drawSphere(gjkOutput.m_pointInWorld,0.05,btVector3(0,1,0));
|
||||
debugDrawer.drawSphere(endPt,0.05,btVector3(0,0,1));
|
||||
|
||||
bool perturbeA = false;//true;
|
||||
const btScalar angleLimit = 0.125f * SIMD_PI;
|
||||
btScalar perturbeAngle;
|
||||
btScalar radiusA = shapePtr[0]->getAngularMotionDisc();
|
||||
btScalar radiusB = shapePtr[1]->getAngularMotionDisc();
|
||||
|
||||
if (radiusA < radiusB)
|
||||
{
|
||||
perturbeAngle = gContactBreakingThreshold /radiusA;
|
||||
perturbeA = true;
|
||||
} else
|
||||
{
|
||||
perturbeAngle = gContactBreakingThreshold / radiusB;
|
||||
perturbeA = false;
|
||||
}
|
||||
if ( perturbeAngle > angleLimit )
|
||||
perturbeAngle = angleLimit;
|
||||
|
||||
btVector3 v0,v1;
|
||||
btPlaneSpace1(gjkOutput.m_normalOnBInWorld,v0,v1);
|
||||
|
||||
|
||||
int i;
|
||||
for ( i=0;i<numPerturbationIterations;i++)
|
||||
{
|
||||
|
||||
btGjkPairDetector::ClosestPointInput input;
|
||||
input.m_transformA = tr[0];
|
||||
input.m_transformB = tr[1];
|
||||
sGjkSimplexSolver.reset();
|
||||
|
||||
btQuaternion perturbeRot(v0,perturbeAngle);
|
||||
btScalar iterationAngle = i*(SIMD_2_PI/btScalar(numPerturbationIterations));
|
||||
btQuaternion rotq(gjkOutput.m_normalOnBInWorld,iterationAngle);
|
||||
if (perturbeA)
|
||||
{
|
||||
input.m_transformA.setBasis( btMatrix3x3(rotq*perturbeRot*rotq.inverse())*tr[0].getBasis());
|
||||
} else
|
||||
{
|
||||
input.m_transformB.setBasis( btMatrix3x3(rotq.inverse()*perturbeRot*rotq)*tr[1].getBasis());
|
||||
}
|
||||
debugDrawer.drawTransform(input.m_transformA,10.0);
|
||||
btGjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,&epaSolver);
|
||||
input.m_maximumDistanceSquared = 1e30;
|
||||
gjkOutput.m_distance = 1e30f;
|
||||
convexConvex.getClosestPoints(input, gjkOutput, 0);
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
btScalar m[16];
|
||||
|
||||
input.m_transformA.getOpenGLMatrix( m );
|
||||
m_shapeDrawer->drawOpenGL(m,shapePtr[0],btVector3(0,1,0),getDebugMode(),worldBoundsMin,worldBoundsMax);
|
||||
|
||||
}
|
||||
|
||||
if (1)//gjkOutput.m_hasResult)
|
||||
{
|
||||
printf("bullet: %10.10f\n", gjkOutput.m_distance);
|
||||
btVector3 startPt,endPt;
|
||||
if (perturbeA)
|
||||
{
|
||||
btVector3 endPtOrg = gjkOutput.m_pointInWorld + gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
|
||||
endPt = (tr[0]*input.m_transformA.inverse())(endPtOrg);
|
||||
btScalar depth = (endPt - gjkOutput.m_pointInWorld).dot(gjkOutput.m_normalOnBInWorld);
|
||||
startPt = endPt-gjkOutput.m_normalOnBInWorld*depth;
|
||||
} else
|
||||
{
|
||||
endPt = gjkOutput.m_pointInWorld + gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance;
|
||||
startPt = (tr[1]*input.m_transformB.inverse())(gjkOutput.m_pointInWorld);
|
||||
btScalar depth = (endPt - startPt).dot(gjkOutput.m_normalOnBInWorld);
|
||||
}
|
||||
|
||||
|
||||
debugDrawer.drawLine(startPt,endPt,btVector3(1,0,0));
|
||||
debugDrawer.drawSphere(startPt,0.05,btVector3(0,1,0));
|
||||
debugDrawer.drawSphere(endPt,0.05,btVector3(0,0,1));
|
||||
}
|
||||
}
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1, 0, 0);
|
||||
glVertex3d(gjkOutput.m_pointInWorld.x(), gjkOutput.m_pointInWorld.y(),gjkOutput.m_pointInWorld.z());
|
||||
glVertex3d(endPt.x(),endPt.y(),endPt.z());
|
||||
//glVertex3d(gjkOutputm_pointInWorld.x(), gjkOutputm_pointInWorld.y(),gjkOutputm_pointInWorld.z());
|
||||
//glVertex3d(gjkOutputm_pointInWorld.x(), gjkOutputm_pointInWorld.y(),gjkOutputm_pointInWorld.z());
|
||||
glEnd();
|
||||
}
|
||||
static int looper = 0;
|
||||
if (looper++>10)
|
||||
{
|
||||
looper =0;
|
||||
checkPerturbation++;
|
||||
if (checkPerturbation>numPerturbationIterations)
|
||||
checkPerturbation=0;
|
||||
}
|
||||
|
||||
//GL_ShapeDrawer::drawCoordSystem();
|
||||
GL_ShapeDrawer::drawCoordSystem();
|
||||
|
||||
btScalar m[16];
|
||||
int i;
|
||||
|
||||
// btGjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,0);
|
||||
|
||||
|
||||
convexConvex.getClosestPoints(input ,gjkOutput,0);
|
||||
|
||||
btVector3 worldBoundsMin(-1000,-1000,-1000);
|
||||
btVector3 worldBoundsMax(1000,1000,1000);
|
||||
|
||||
|
||||
for (i=0;i<numObjects;i++)
|
||||
{
|
||||
|
||||
tr[i].getOpenGLMatrix( m );
|
||||
|
||||
m_shapeDrawer->drawOpenGL(m,shapePtr[i],btVector3(1,1,1),getDebugMode(),worldBoundsMin,worldBoundsMax);
|
||||
|
||||
|
||||
}
|
||||
|
||||
simplex.setSimplexSolver(&sGjkSimplexSolver);
|
||||
btVector3 ybuf[4],pbuf[4],qbuf[4];
|
||||
int numpoints = sGjkSimplexSolver.getSimplex(pbuf,qbuf,ybuf);
|
||||
simplex.reset();
|
||||
|
||||
for (i=0;i<numpoints;i++)
|
||||
simplex.addVertex(ybuf[i]);
|
||||
|
||||
btTransform ident;
|
||||
ident.setIdentity();
|
||||
ident.getOpenGLMatrix(m);
|
||||
m_shapeDrawer->drawOpenGL(m,&simplex,btVector3(1,1,1),getDebugMode(),worldBoundsMin,worldBoundsMax);
|
||||
|
||||
|
||||
btQuaternion orn;
|
||||
orn.setEuler(yaw,pitch,roll);
|
||||
|
||||
Reference in New Issue
Block a user