2 Bullet Continuous Collision Detection and Physics Library
4 Copyright (c) 2007 Starbreeze Studios
6 This software is provided 'as-is', without any express or implied warranty.
7 In no event will the authors be held liable for any damages arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it freely,
10 subject to the following restrictions:
12 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.
13 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
14 3. This notice may not be removed or altered from any source distribution.
16 Originally Written by: Marten Svanfeldt
17 ReWritten by: Francisco León
22 #include "btBulletDynamicsCommon.h"
23 #include "GlutStuff.h"
24 #include "GL_ShapeDrawer.h"
26 #include "LinearMath/btIDebugDraw.h"
28 #include "GLDebugDrawer.h"
29 #include "GenericJointDemo.h"
33 GLDebugDrawer debugDrawer;
40 void GenericJointDemo::initPhysics()
45 // Setup the basic world
47 btDefaultCollisionConfiguration * collision_config = new btDefaultCollisionConfiguration();
49 btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collision_config);
51 btVector3 worldAabbMin(-10000,-10000,-10000);
52 btVector3 worldAabbMax(10000,10000,10000);
53 btBroadphaseInterface* overlappingPairCache = new btAxisSweep3 (worldAabbMin, worldAabbMax);
55 btConstraintSolver* constraintSolver = new btSequentialImpulseConstraintSolver;
58 m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,overlappingPairCache,constraintSolver,collision_config);
60 m_dynamicsWorld->setGravity(btVector3(0,-30,0));
62 m_dynamicsWorld->setDebugDrawer(&debugDrawer);
64 // Setup a big ground box
66 btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(200.),btScalar(10.),btScalar(200.)));
67 btTransform groundTransform;
68 groundTransform.setIdentity();
69 groundTransform.setOrigin(btVector3(0,-15,0));
70 localCreateRigidBody(btScalar(0.),groundTransform,groundShape);
79 void GenericJointDemo::spawnRagdoll(bool random)
81 RagDoll* ragDoll = new RagDoll (m_dynamicsWorld, btVector3 (0,0,10),5.f);
82 m_ragdolls.push_back(ragDoll);
85 void GenericJointDemo::clientMoveAndDisplay()
87 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
89 //simple dynamics world doesn't handle fixed-time-stepping
90 float ms = getDeltaTimeMicroseconds();
92 float minFPS = 1000000.f/60.f;
98 m_dynamicsWorld->stepSimulation(ms / 1000000.f);
99 //optional but useful: debug drawing
100 m_dynamicsWorld->debugDrawWorld();
110 void GenericJointDemo::displayCallback()
112 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
115 m_dynamicsWorld->debugDrawWorld();
123 void GenericJointDemo::keyboardCallback(unsigned char key, int x, int y)
131 DemoApplication::keyboardCallback(key, x, y);