diff --git a/Demos/DoublePrecisionDemo/DoublePrecisionDemo.cpp b/Demos/DoublePrecisionDemo/DoublePrecisionDemo.cpp new file mode 100644 index 000000000..289bd3041 --- /dev/null +++ b/Demos/DoublePrecisionDemo/DoublePrecisionDemo.cpp @@ -0,0 +1,274 @@ +/* +Bullet Continuous Collision Detection and Physics Library +Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ + +This software is provided 'as-is', without any express or implied warranty. +In no event will the authors be held liable for any damages arising from the use of this software. +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it freely, +subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. +*/ + + +/// +/// DoublePrecisionDemo shows high level usage of the Collision Detection. +/// + +#include "GL_Simplex1to4.h" + +//include common Bullet Collision Detection headerfiles +#include "btBulletCollisionCommon.h" + +#include "LinearMath/btIDebugDraw.h" +#include "BMF_Api.h" +#include "GL_ShapeDrawer.h" +#include "doublePrecisionDemo.h" +#include "GlutStuff.h" +#include "GLDebugDrawer.h" + +btScalar yaw=btScalar(0.); +btScalar pitch=btScalar(0.); +btScalar roll=btScalar(0.); +const int maxNumObjects = 4; +const int numObjects = 2; + +GL_Simplex1to4 simplex; + + +btCollisionObject objects[maxNumObjects]; +btCollisionWorld* collisionWorld = 0; + +// so pixel ratio is 1:1 +int screenWidth = 640; +int screenHeight = 640; +GLDebugDrawer debugDrawer; + +const btScalar LARGE_DISTANCE_FROM_ORIGIN = btScalar(999999.0); +const btScalar VERY_SMALL_INCREMENT = btScalar(0.000009); + +int main(int argc,char** argv) +{ + DoublePrecisionDemo* doublePrecisionDemo = new DoublePrecisionDemo(); + + doublePrecisionDemo->initPhysics(); + doublePrecisionDemo->setCameraDistance(btScalar(2.0)); + + doublePrecisionDemo->clientResetScene(); + + return glutmain(argc, argv,screenWidth,screenHeight,"Double Precision Demo",doublePrecisionDemo); +} + +void DoublePrecisionDemo::initPhysics() +{ + m_debugMode |= btIDebugDraw::DBG_DrawWireframe; + + btMatrix3x3 basisA; + basisA.setIdentity(); + + btMatrix3x3 basisB; + basisB.setIdentity(); + + objects[0].getWorldTransform().setBasis(basisA); + objects[1].getWorldTransform().setBasis(basisB); + + + btBoxShape* boxA = new btBoxShape(btVector3(0.5,0.5,0.5)); + btBoxShape* boxB = new btBoxShape(btVector3(0.5,0.5,0.5)); + + objects[0].setCollisionShape(boxA);//&hullA; + objects[1].setCollisionShape(boxB);//&hullB; + + btCollisionDispatcher* dispatcher = new btCollisionDispatcher; + btVector3 worldAabbMin(80000,80000,80000); + btVector3 worldAabbMax(120000,120000,120000); + + btAxisSweep3* broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax); + + collisionWorld = new btCollisionWorld(dispatcher,broadphase); + + collisionWorld->addCollisionObject(&objects[0]); + collisionWorld->addCollisionObject(&objects[1]); + +} + + +//to be implemented by the demo + +void DoublePrecisionDemo::clientMoveAndDisplay() +{ + + displayCallback(); +} + + +static btVoronoiSimplexSolver sGjkSimplexSolver; +btSimplexSolverInterface& gGjkSimplexSolver = sGjkSimplexSolver; + +void DoublePrecisionDemo::displayCallback(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glDisable(GL_LIGHTING); + + collisionWorld->getDispatchInfo().m_debugDraw = &debugDrawer; + + if (collisionWorld) + collisionWorld->performDiscreteCollisionDetection(); + + int i; + + ///one way to draw all the contact points is iterating over contact manifolds / points: + int numManifolds = collisionWorld->getDispatcher()->getNumManifolds(); + for (i=0;igetDispatcher()->getManifoldByIndexInternal(i); + btCollisionObject* obA = static_cast(contactManifold->getBody0()); + btCollisionObject* obB = static_cast(contactManifold->getBody1()); + contactManifold->refreshContactPoints(obA->getWorldTransform(),obB->getWorldTransform()); + + int numContacts = contactManifold->getNumContacts(); + for (int j=0;jgetContactPoint(j); + + glBegin(GL_LINES); + glColor3f(1, 1, 1); + + btVector3 ptA = pt.getPositionWorldOnA() - m_cameraPosition; + btVector3 ptB = pt.getPositionWorldOnB() - m_cameraPosition; + + glVertex3d(ptA.x(),ptA.y(),ptA.z()); + glVertex3d(ptB.x(),ptB.y(),ptB.z()); + glEnd(); + } + + //you can un-comment out this line, and then all points are removed + //contactManifold->clearManifold(); + } + + btScalar m[16]; + btTransform temp; + + + btVector3 color; + //int i; + for (i=0;i