Imported Upstream version 2.81
[platform/upstream/libbullet.git] / Demos / SoftDemo / SoftDemo.h
1
2 /*
3 Bullet Continuous Collision Detection and Physics Library
4 Copyright (c) 2003-2006 Erwin Coumans  http://continuousphysics.com/Bullet/
5
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:
11
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.
15 */
16
17 ///btSoftBody implementation by Nathanael Presson
18
19 #ifndef SOFT_DEMO_H
20 #define SOFT_DEMO_H
21
22 #ifdef _WINDOWS
23 #include "Win32DemoApplication.h"
24 #define PlatformDemoApplication Win32DemoApplication
25 #else
26 #include "GlutDemoApplication.h"
27 #define PlatformDemoApplication GlutDemoApplication
28 #endif
29 #include "LinearMath/btAlignedObjectArray.h"
30 #include "BulletSoftBody/btSoftBody.h"
31
32
33 class btBroadphaseInterface;
34 class btCollisionShape;
35 class btOverlappingPairCache;
36 class btCollisionDispatcher;
37 class btConstraintSolver;
38 struct btCollisionAlgorithmCreateFunc;
39 class btDefaultCollisionConfiguration;
40
41 ///collisions between two btSoftBody's
42 class btSoftSoftCollisionAlgorithm;
43
44 ///collisions between a btSoftBody and a btRigidBody
45 class btSoftRididCollisionAlgorithm;
46 class btSoftRigidDynamicsWorld;
47
48
49 ///CcdPhysicsDemo shows basic stacking using Bullet physics, and allows toggle of Ccd (using key '1')
50 class SoftDemo : public PlatformDemoApplication
51 {
52 public:
53
54         btAlignedObjectArray<btSoftSoftCollisionAlgorithm*> m_SoftSoftCollisionAlgorithms;
55
56         btAlignedObjectArray<btSoftRididCollisionAlgorithm*> m_SoftRigidCollisionAlgorithms;
57
58         btSoftBodyWorldInfo     m_softBodyWorldInfo;
59
60         
61
62         bool                                                            m_autocam;
63         bool                                                            m_cutting;
64         bool                                                            m_raycast;
65         btScalar                                                        m_animtime;
66         btClock                                                         m_clock;
67         int                                                                     m_lastmousepos[2];
68         btVector3                                                       m_impact;
69         btSoftBody::sRayCast                            m_results;
70         btSoftBody::Node*                                       m_node;
71         btVector3                                                       m_goal;
72         bool                                                            m_drag;
73
74
75         //keep the collision shapes, for deletion/cleanup
76         btAlignedObjectArray<btCollisionShape*>         m_collisionShapes;
77
78         btBroadphaseInterface*  m_broadphase;
79
80         btCollisionDispatcher*  m_dispatcher;
81
82
83         btConstraintSolver*     m_solver;
84
85         btCollisionAlgorithmCreateFunc* m_boxBoxCF;
86
87         btDefaultCollisionConfiguration* m_collisionConfiguration;
88
89
90 public:
91
92         void    initPhysics();
93
94         void    exitPhysics();
95
96         SoftDemo() : m_drag(false)
97         {
98                 setTexturing(true);
99                 setShadows(true);
100         }
101         virtual ~SoftDemo()
102         {
103                 exitPhysics();
104         }
105
106         virtual void clientMoveAndDisplay();
107
108         virtual void displayCallback();
109
110         void createStack( btCollisionShape* boxShape, float halfCubeSize, int size, float zPos );
111
112         static DemoApplication* Create()
113         {
114                 SoftDemo* demo = new SoftDemo;
115                 demo->myinit();
116                 demo->initPhysics();
117                 return demo;
118         }
119
120         virtual void setDrawClusters(bool drawClusters);
121
122         virtual const btSoftRigidDynamicsWorld* getSoftDynamicsWorld() const
123         {
124                 ///just make it a btSoftRigidDynamicsWorld please
125                 ///or we will add type checking
126                 return (btSoftRigidDynamicsWorld*) m_dynamicsWorld;
127         }
128
129         virtual btSoftRigidDynamicsWorld*       getSoftDynamicsWorld()
130         {
131                 ///just make it a btSoftRigidDynamicsWorld please
132                 ///or we will add type checking
133                 return (btSoftRigidDynamicsWorld*) m_dynamicsWorld;
134         }
135
136         //
137         void    clientResetScene();
138         void    renderme();
139         void    keyboardCallback(unsigned char key, int x, int y);
140         void    mouseFunc(int button, int state, int x, int y);
141         void    mouseMotionFunc(int x,int y);
142
143 };
144
145 #define MACRO_SOFT_DEMO(a) class SoftDemo##a : public SoftDemo\
146 {\
147 public:\
148         static DemoApplication* Create()\
149         {\
150                 SoftDemo* demo = new SoftDemo##a;\
151                 extern int current_demo;\
152                 current_demo=a;\
153                 demo->myinit();\
154                 demo->initPhysics();\
155                 return demo;\
156         }\
157 };
158
159
160 MACRO_SOFT_DEMO(0) //Init_Cloth
161 MACRO_SOFT_DEMO(1) //Init_Pressure
162 MACRO_SOFT_DEMO(2)//Init_Volume
163 MACRO_SOFT_DEMO(3)//Init_Ropes
164 MACRO_SOFT_DEMO(4)//Init_Ropes_Attach
165 MACRO_SOFT_DEMO(5)//Init_ClothAttach
166 MACRO_SOFT_DEMO(6)//Init_Sticks
167 MACRO_SOFT_DEMO(7)//Init_Collide
168 MACRO_SOFT_DEMO(8)//Init_Collide2
169 MACRO_SOFT_DEMO(9)//Init_Collide3
170 MACRO_SOFT_DEMO(10)//Init_Impact
171 MACRO_SOFT_DEMO(11)//Init_Aero
172 MACRO_SOFT_DEMO(12)//Init_Friction
173 MACRO_SOFT_DEMO(13)//Init_Torus
174 MACRO_SOFT_DEMO(14)//Init_TorusMatch
175 MACRO_SOFT_DEMO(15)//Init_Bunny
176 MACRO_SOFT_DEMO(16)//Init_BunnyMatch
177 MACRO_SOFT_DEMO(17)//Init_Cutting1
178 MACRO_SOFT_DEMO(18)//Init_ClusterDeform
179 MACRO_SOFT_DEMO(19)//Init_ClusterCollide1
180 MACRO_SOFT_DEMO(20)//Init_ClusterCollide2
181 MACRO_SOFT_DEMO(21)//Init_ClusterSocket
182 MACRO_SOFT_DEMO(22)//Init_ClusterHinge
183 MACRO_SOFT_DEMO(23)//Init_ClusterCombine
184 MACRO_SOFT_DEMO(24)//Init_ClusterCar
185 MACRO_SOFT_DEMO(25)//Init_ClusterRobot
186 MACRO_SOFT_DEMO(26)//Init_ClusterStackSoft
187 MACRO_SOFT_DEMO(27)//Init_ClusterStackMixed
188 MACRO_SOFT_DEMO(28)//Init_TetraCube
189 MACRO_SOFT_DEMO(29)//Init_TetraBunny
190
191
192 #endif //CCD_PHYSICS_DEMO_H
193
194
195
196
197