Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Demos / GimpactTestDemo / GimpactTestDemo.h
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 TEST_CONCAVE_DEMO_H
16 #define TEST_CONCAVE_DEMO_H
17
18
19 #ifdef _WINDOWS
20 #include "Win32DemoApplication.h"
21 #define PlatformDemoApplication Win32DemoApplication
22 #else
23 #include "GlutDemoApplication.h"
24 #define PlatformDemoApplication GlutDemoApplication
25 #endif
26
27 class btTriangleIndexVertexArray;
28 class btDefaultCollisionConfiguration;
29
30 //#define BULLET_TRIANGLE_COLLISION 1
31 #define BULLET_GIMPACT 1
32 //#define BULLET_GIMPACT_CONVEX_DECOMPOSITION 1
33
34 #define TEST_GIMPACT_TORUS
35
36 #ifdef BULLET_GIMPACT
37
38 #include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"
39         #ifdef BULLET_GIMPACT_CONVEX_DECOMPOSITION
40         #include "../Extras/GIMPACTUtils/btGImpactConvexDecompositionShape.h"
41         #endif
42
43
44 #else
45
46 #include "BulletCollision/Gimpact/btConcaveConcaveCollisionAlgorithm.h"
47 #include "BulletCollision/Gimpact/btGIMPACTMeshShape.h"
48
49 #endif
50
51
52
53 class btConstraintSolver;
54 struct btCollisionAlgorithmCreateFunc;
55
56 ///GimpactConcaveDemo shows usage of static concave triangle meshes
57 ///It also shows per-triangle material (friction/restitution) through CustomMaterialCombinerCallback
58 class GimpactConcaveDemo : public PlatformDemoApplication
59 {
60
61 public:
62         GimpactConcaveDemo()
63                 :       m_steps_done(0), 
64                         m_trimeshShape(NULL),
65                   m_trimeshShape2(NULL),
66                   m_indexVertexArrays(NULL),
67                   m_indexVertexArrays2(NULL),
68         
69
70         kinematicTorus(NULL),
71         
72         
73         m_gimpactCollisionCreateFunc(NULL),
74         m_collisionConfiguration(NULL),
75
76         m_dispatcher(NULL),
77
78         m_broadphase(NULL),      
79                  m_constraintSolver(NULL)
80         {
81         }
82
83         virtual ~GimpactConcaveDemo();
84
85
86         void    initGImpactCollision();
87         void    initPhysics();
88
89         virtual void clientMoveAndDisplay();
90
91         virtual void displayCallback();
92
93         virtual void clientResetScene();
94
95         virtual void renderme();
96         virtual void keyboardCallback(unsigned char key, int x, int y);
97
98         ///Demo functions
99         void    shootTrimesh(const btVector3& destination);
100
101 public: ///data
102         unsigned int                    m_steps_done;
103
104 #ifdef BULLET_GIMPACT
105         btCollisionShape                        *m_trimeshShape;
106         btCollisionShape                        *m_trimeshShape2;
107 #else
108
109         btGIMPACTMeshData * m_trimeshShape;
110         btGIMPACTMeshData * m_trimeshShape2;
111
112         btCollisionShape * createTorusShape();
113         btCollisionShape * createBunnyShape();
114
115 #endif
116
117                 //keep the collision shapes, for deletion/cleanup
118         btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
119
120         btTriangleIndexVertexArray  *m_indexVertexArrays;
121         btTriangleIndexVertexArray  *m_indexVertexArrays2;
122
123         btVector3                               kinTorusTran;
124         btQuaternion                    kinTorusRot;
125         btRigidBody                             *kinematicTorus;
126
127
128         btCollisionAlgorithmCreateFunc*  m_gimpactCollisionCreateFunc;
129
130         btDefaultCollisionConfiguration* m_collisionConfiguration;
131         btCollisionDispatcher*                   m_dispatcher;
132         btBroadphaseInterface*                   m_broadphase;
133         btConstraintSolver*                              m_constraintSolver;
134
135         static DemoApplication* Create()
136         {
137                 GimpactConcaveDemo* demo = new GimpactConcaveDemo();
138                 demo->myinit();
139                 demo->initPhysics();
140                 return demo;
141         }
142 };
143
144 #endif //CONCAVE_DEMO_H
145