diff --git a/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp b/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp index d70176ebc..ead976931 100644 --- a/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp +++ b/Demos/GjkConvexCastDemo/LinearConvexCastDemo.cpp @@ -4,8 +4,8 @@ * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies. - * Erwin Coumans makes no representations about the suitability - * of this software for any purpose. + * Erwin Coumans makes no representations about the suitability + * of this software for any purpose. * It is provided "as is" without express or implied warranty. */ @@ -15,7 +15,7 @@ LinearConvexCastDemo implements an efficient continuous collision detection algorithm. Both linear and angular velocities are supported. Gjk or Simplex based methods. Motion using Exponential Map. - Comparison with Screwing Motion. + Comparison with Screwing Motion. Also comparision with Algebraic CCD and Interval Arithmetic methods (Stephane Redon) */ @@ -23,201 +23,136 @@ ///Low level demo, doesn't include btBulletCollisionCommon.h #include "LinearMath/btQuaternion.h" #include "LinearMath/btTransform.h" -#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" + #include "BulletCollision/CollisionShapes/btBoxShape.h" +#include "BulletCollision/CollisionShapes/btConvexHullShape.h" #include "BulletCollision/CollisionShapes/btMinkowskiSumShape.h" +#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" #include "BulletCollision/NarrowPhaseCollision/btGjkPairDetector.h" #include "BulletCollision/NarrowPhaseCollision/btGjkConvexCast.h" #include "BulletCollision/NarrowPhaseCollision/btContinuousConvexCollision.h" #include "BulletCollision/NarrowPhaseCollision/btSubSimplexConvexCast.h" -#ifdef USE_ALGEBRAIC_CCD -#include "NarrowPhaseCollision/BU_CollisionPair.h" -#endif //USE_ALGEBRAIC_CCD + #include "BulletCollision/CollisionShapes/btSphereShape.h" #include "BulletCollision/CollisionShapes/btTetrahedronShape.h" +#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" +#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h" + + + #include "GL_ShapeDrawer.h" #include "LinearConvexCastDemo.h" #include "GlutStuff.h" +static btVoronoiSimplexSolver sVoronoiSimplexSolver; +btSimplexSolverInterface& gGjkSimplexSolver = sVoronoiSimplexSolver; static float yaw=0.f,pitch=0.f,roll=0.f; static const int maxNumObjects = 4; static const int numObjects = 2; - static btPolyhedralConvexShape* shapePtr[maxNumObjects]; static btTransform tr[numObjects]; -void DrawRasterizerLine(float const* , float const*, int) -{ -} void LinearConvexCastDemo::initPhysics() { - setCameraDistance(50.f); - tr[0].setOrigin(btVector3(0,0,0)); - tr[1].setOrigin(btVector3(0,10,0)); + setCameraDistance(10.f); - btMatrix3x3 basisA; - basisA.setValue(0.99999958f,0.00022980258f,0.00090992288f, - -0.00029313788f,0.99753088f,0.070228584f, - -0.00089153741f,-0.070228823f,0.99753052f); + tr[0].setIdentity(); + tr[0].setOrigin( btVector3( 0.0f, 5.5f, 0.0f ) ); - 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[1].setIdentity(); + tr[1].setOrigin( btVector3( 0.0f, 0.0f, 0.0f ) ); - tr[0].setBasis(basisA); - tr[1].setBasis(basisB); + // Pyramide + float r = 1.0f; + float h = 2.0f; + + btConvexHullShape* shapeA = new btConvexHullShape; + shapeA->addPoint( btVector3( 0.0f, 0.75f * h, 0.0f ) ); + shapeA->addPoint( btVector3( -r, -0.25f * h, r ) ); + shapeA->addPoint( btVector3( r, -0.25f * h, r ) ); + shapeA->addPoint( btVector3( r, -0.25f * h, -r ) ); + shapeA->addPoint( btVector3( -r, -0.25f * h, -r ) ); + // Triangle + btConvexHullShape* shapeB = new btConvexHullShape; + shapeB->addPoint( btVector3( 0.0f, 1.0f, 0.0f ) ); + shapeB->addPoint( btVector3( 1.0f, -1.0f, 0.0f ) ); + shapeB->addPoint( btVector3( -1.0f, -1.0f, 0.0f ) ); - btVector3 boxHalfExtentsA(0.2,4,4); - btVector3 boxHalfExtentsB(6,6,6); + shapePtr[0] = shapeA; + shapePtr[1] = shapeB; - btBoxShape* boxA = new btBoxShape(boxHalfExtentsA); -/* btBU_Simplex1to4 boxB; - boxB.addVertex(btPoint3(-5,0,-5)); - boxB.addVertex(btPoint3(5,0,-5)); - boxB.addVertex(btPoint3(0,0,5)); - boxB.addVertex(btPoint3(0,5,0)); -*/ - - btBoxShape* boxB = new btBoxShape(boxHalfExtentsB); - shapePtr[0] = boxA; - shapePtr[1] = boxB; - - shapePtr[0]->setMargin(0.01f); - shapePtr[1]->setMargin(0.01f); - - btTransform tr; - tr.setIdentity(); + shapePtr[0]->setMargin( 0.01f ); + shapePtr[1]->setMargin( 0.01f ); } //to be implemented by the demo - void LinearConvexCastDemo::clientMoveAndDisplay() { - displayCallback(); } -#include "BulletCollision/NarrowPhaseCollision/btVoronoiSimplexSolver.h" -#include "BulletCollision/NarrowPhaseCollision/btConvexPenetrationDepthSolver.h" +LinearConvexCastDemo::~LinearConvexCastDemo() +{ + delete shapePtr[0]; + delete shapePtr[1]; +} -static btVoronoiSimplexSolver sVoronoiSimplexSolver; - -btSimplexSolverInterface& gGjkSimplexSolver = sVoronoiSimplexSolver; - -bool drawLine= false; - -void LinearConvexCastDemo::displayCallback(void) +void LinearConvexCastDemo::displayCallback(void) { updateCamera(); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_LIGHTING); - //GL_ShapeDrawer::drawCoordSystem(); + GL_ShapeDrawer::drawCoordSystem(); - btScalar m[16]; - int i; - - for (i=0;isetLocalScaling(nonUniformScaling); - nonuniformScaledSphere->setMargin(0.04); - btConvexHullShape* convexHullShape = new btConvexHullShape(&positions[0].getX(),3); - - //attempt to approximate a bowling pin //choose shape - shapePtr[0] = &myCone;//&compound;//&myCone;//&myBox;//nonuniformScaledSphere;//&myCone; - // shapePtr[0] = &myCone;//&myBox;//nonuniformScaledSphere;//&myCone; + shapePtr[0] = &myCone; - shapePtr[1] =&simplex; - shapePtr[2] =convexHullShape; - shapePtr[3] =&myMink;//myBox;//multiSphereShape - - btVector3 sphereOffset(0,PIN_HEIGHT/4.0f,0); - - // create pin collision shape - btCollisionShape* cyl = new btCylinderShape(btVector3(PIN_DIAMETER/4.0f, PIN_HEIGHT/4.0f, PIN_DIAMETER/4.0f)); - cyl->setMargin(IN_TO_M(0.000025f)); - btVector3 spherepositions[3] = {btVector3(0,-PIN_HEIGHT/2.f +(PIN_DIAMETER/2.0f)+IN_TO_M(1.25f),0), -btVector3(0,-PIN_HEIGHT/2.f +(PIN_DIAMETER/2.0f)+IN_TO_M(1.25f),0)+sphereOffset, -btVector3(0,-PIN_HEIGHT/2.f +(PIN_DIAMETER/2.0f)+IN_TO_M(1.25f),0)-sphereOffset}; - btScalar radii[3] = {(PIN_DIAMETER/2.0f),(PIN_DIAMETER/4.0f),(PIN_DIAMETER/4.0f)}; - btCollisionShape* sph = new btMultiSphereShape(inertiaHalfExtents,spherepositions,radii,3); - - btTransform ident; - ident.setIdentity(); - ident.setOrigin(btVector3(0.f,-PIN_HEIGHT/4.f,0.f)); - compound.addChildShape(ident,cyl); - ident.setIdentity(); - //ident.setOrigin(btVector3(0.0f, -PIN_HEIGHT/2.0f + PIN_DIAMETER/2.0f + IN_TO_M(3.5f), 0.0f)); - compound.addChildShape(ident,sph); - - btVector3 spherepositions2[2] = {btVector3(0,+PIN_HEIGHT/2.f -(PIN_DIAMETER/4.0f),0), - btVector3(0,0,0)}; - btScalar radii2[2] = {(PIN_DIAMETER/4.0f),(PIN_DIAMETER/6.0f)}; - - btCollisionShape* sph2 = new btMultiSphereShape(inertiaHalfExtents,spherepositions2,radii2,2); - compound.addChildShape(ident,sph2); - - compound.setMargin(0.001); - simplex.setMargin(0.3f); } +Raytracer::~Raytracer() +{ + + delete raytracePicture; + raytracePicture=0; +} + //to be implemented by the demo void Raytracer::clientMoveAndDisplay() @@ -242,7 +148,6 @@ void Raytracer::displayCallback() //transforms[i].setRotation(orn); } } - myMink.setTransformA(btTransform(transforms[0].getRotation())); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_LIGHTING); @@ -512,23 +417,6 @@ void Raytracer::displayCallback() - /* - /// normal opengl rendering - float m[16]; - int i; - - for (i=0;i