[168] | 1 | /* |
---|
| 2 | Bullet Continuous Collision Detection and Physics Library |
---|
| 3 | Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/ |
---|
| 4 | |
---|
| 5 | This software is provided 'as-is', without any express or implied warranty. |
---|
| 6 | In no event will the authors be held liable for any damages arising from the use of this software. |
---|
| 7 | Permission is granted to anyone to use this software for any purpose, |
---|
| 8 | including commercial applications, and to alter it and redistribute it freely, |
---|
| 9 | subject to the following restrictions: |
---|
| 10 | |
---|
| 11 | 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. |
---|
| 12 | 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. |
---|
| 13 | 3. This notice may not be removed or altered from any source distribution. |
---|
| 14 | */ |
---|
| 15 | #ifndef BASIC_DEMO_H |
---|
| 16 | #define BASIC_DEMO_H |
---|
| 17 | |
---|
| 18 | #include "GlutDemoApplication.h" |
---|
| 19 | #include <LinearMath/btAlignedObjectArray.h> |
---|
| 20 | #include "Agent.h" |
---|
| 21 | #include "Sensor.h" |
---|
| 22 | #include <utility> |
---|
| 23 | |
---|
| 24 | using namespace std; |
---|
| 25 | |
---|
| 26 | class btBroadphaseInterface; |
---|
| 27 | class btCollisionShape; |
---|
| 28 | class btOverlappingPairCache; |
---|
| 29 | class btCollisionDispatcher; |
---|
| 30 | class btConstraintSolver; |
---|
| 31 | struct btCollisionAlgorithmCreateFunc; |
---|
| 32 | class btDefaultCollisionConfiguration; |
---|
| 33 | |
---|
| 34 | ///BasicDemo is good starting point for learning the code base and porting. |
---|
| 35 | class BasicDemo : public GlutDemoApplication |
---|
| 36 | { |
---|
| 37 | |
---|
| 38 | //keep the collision shapes, for deletion/cleanup |
---|
| 39 | btAlignedObjectArray<btCollisionShape*> m_collisionShapes; |
---|
| 40 | |
---|
| 41 | btBroadphaseInterface* m_broadphase; |
---|
| 42 | |
---|
| 43 | btCollisionDispatcher* m_dispatcher; |
---|
| 44 | |
---|
| 45 | btConstraintSolver* m_solver; |
---|
| 46 | |
---|
| 47 | btDefaultCollisionConfiguration* m_collisionConfiguration; |
---|
| 48 | |
---|
| 49 | public: |
---|
| 50 | btAlignedObjectArray<btTypedConstraint*> m_joints; |
---|
| 51 | btAlignedObjectArray<Agent*> m_agents; |
---|
| 52 | btAlignedObjectArray<pair<int, Sensor*> > m_sensors; |
---|
| 53 | btAlignedObjectArray<btAlignedObjectArray<int> > m_matrix; |
---|
| 54 | |
---|
| 55 | BasicDemo() |
---|
| 56 | { |
---|
| 57 | } |
---|
| 58 | virtual ~BasicDemo() |
---|
| 59 | { |
---|
| 60 | exitPhysics(); |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | void initPhysics(); |
---|
| 64 | |
---|
| 65 | btScalar computeVelocity(btScalar currentAngle, btScalar targetAngle); |
---|
| 66 | btRigidBody* localCreateRigidBody (btScalar mass, const btTransform& startTransform, btCollisionShape* shape); |
---|
| 67 | btRigidBody* createObject(btCollisionShape* colShape, btVector3 position, btScalar mass); |
---|
| 68 | btRigidBody* createObject(btCollisionShape* colShape, btTransform transform, btScalar mass); |
---|
| 69 | |
---|
| 70 | void createHinge(bool enable); |
---|
| 71 | void createMagicCarpet(int n, int m); |
---|
| 72 | void createSwarm3D(int n, int m, int p); |
---|
| 73 | void createSimulation2D(int n, int m); |
---|
| 74 | void createSimulation3D(int n, int m, int p); |
---|
| 75 | |
---|
| 76 | void updateSensors(); |
---|
| 77 | void updateActuators(); |
---|
| 78 | void updateAgents(); |
---|
| 79 | |
---|
| 80 | void exitPhysics(); |
---|
| 81 | |
---|
| 82 | void debug(); |
---|
| 83 | |
---|
| 84 | virtual void keyboardCallback(unsigned char key, int x, int y); |
---|
| 85 | |
---|
| 86 | virtual void clientMoveAndDisplay(); |
---|
| 87 | |
---|
| 88 | virtual void displayCallback(); |
---|
| 89 | |
---|
| 90 | static DemoApplication* Create() |
---|
| 91 | { |
---|
| 92 | BasicDemo* demo = new BasicDemo; |
---|
| 93 | demo->myinit(); |
---|
| 94 | demo->initPhysics(); |
---|
| 95 | return demo; |
---|
| 96 | } |
---|
| 97 | }; |
---|
| 98 | |
---|
| 99 | #endif //BASIC_DEMO_H |
---|
| 100 | |
---|