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 BENCHMARK_DEMO_H
16 #define BENCHMARK_DEMO_H
17 
18 
19 #include "LinearMath/btAlignedObjectArray.h"
20 #include "LinearMath/btTransform.h"
21 
22 class btDynamicsWorld;
23 
24 #define NUMRAYS 500
25 
26 class btRigidBody;
27 class btBroadphaseInterface;
28 class btCollisionShape;
29 class btOverlappingPairCache;
30 class btCollisionDispatcher;
31 class btConstraintSolver;
32 struct btCollisionAlgorithmCreateFunc;
33 class btDefaultCollisionConfiguration;
34 
35 
36 #ifndef USE_GRAPHICAL_BENCHMARK
37 ///empty placeholder
38 class DemoApplication
39 {
40 protected:
41 
42 	btDynamicsWorld* m_dynamicsWorld;
43 	btScalar	m_defaultContactProcessingThreshold;
44 
45 public:
DemoApplication()46 	DemoApplication()
47 	:m_defaultContactProcessingThreshold(BT_LARGE_FLOAT)
48 	{
49 	}
myinit()50 	virtual void myinit() {}
getDynamicsWorld()51 	virtual btDynamicsWorld* getDynamicsWorld()
52 	{
53 		return m_dynamicsWorld;
54 	}
55 
getDeltaTimeMicroseconds()56 	btScalar	getDeltaTimeMicroseconds()
57 	{
58 		return 1.f;
59 	}
60 
renderme()61 	void	renderme() {}
setCameraDistance(btScalar dist)62 	void	setCameraDistance(btScalar dist){}
clientResetScene()63 	void	clientResetScene(){}
64 	btRigidBody*	localCreateRigidBody(float mass, const btTransform& startTransform,btCollisionShape* shape);
65 
66 };
67 ///BenchmarkDemo is provides several performance tests
68 #define PlatformDemoApplication DemoApplication
69 #else //USE_GRAPHICAL_BENCHMARK
70 
71 #ifdef _WINDOWS
72 #include "Win32DemoApplication.h"
73 #define PlatformDemoApplication Win32DemoApplication
74 #else
75 #include "GlutDemoApplication.h"
76 #define PlatformDemoApplication GlutDemoApplication
77 #endif
78 
79 #endif //USE_GRAPHICAL_BENCHMARK
80 
81 
82 class BenchmarkDemo : public PlatformDemoApplication
83 {
84 
85 	//keep the collision shapes, for deletion/cleanup
86 	btAlignedObjectArray<btCollisionShape*>	m_collisionShapes;
87 
88 	btAlignedObjectArray<class RagDoll*>	m_ragdolls;
89 
90 	btBroadphaseInterface*	m_overlappingPairCache;
91 
92 	btCollisionDispatcher*	m_dispatcher;
93 
94 	btConstraintSolver*	m_solver;
95 
96 	btDefaultCollisionConfiguration* m_collisionConfiguration;
97 
98 	int	m_benchmark;
99 
100 	void	createTest1();
101 	void	createTest2();
102 	void	createTest3();
103 	void	createTest4();
104 	void	createTest5();
105 	void	createTest6();
106 	void	createTest7();
107 
108 	void createWall(const btVector3& offsetPosition,int stackSize,const btVector3& boxSize);
109 	void createPyramid(const btVector3& offsetPosition,int stackSize,const btVector3& boxSize);
110 	void createTowerCircle(const btVector3& offsetPosition,int stackSize,int rotSize,const btVector3& boxSize);
111 	void createLargeMeshBody();
112 
113 
114 	class SpuBatchRaycaster* m_batchRaycaster;
115 	class btThreadSupportInterface* m_batchRaycasterThreadSupport;
116 
117 	void castRays();
118 	void initRays();
119 
120 	public:
121 
BenchmarkDemo(int benchmark)122 	BenchmarkDemo(int benchmark)
123 	:m_benchmark(benchmark)
124 	{
125 	}
~BenchmarkDemo()126 	virtual ~BenchmarkDemo()
127 	{
128 		exitPhysics();
129 	}
130 	void	initPhysics();
131 
132 	void	exitPhysics();
133 
134 	virtual void clientMoveAndDisplay();
135 
136 	virtual void displayCallback();
137 
138 
139 
140 
141 };
142 
143 class BenchmarkDemo1 : public BenchmarkDemo
144 {
145 public:
BenchmarkDemo1()146 	BenchmarkDemo1()
147 		:BenchmarkDemo(1)
148 	{
149 	}
150 
Create()151 	static DemoApplication* Create()
152 	{
153 		BenchmarkDemo1* demo = new BenchmarkDemo1;
154 		demo->myinit();
155 		demo->initPhysics();
156 		return demo;
157 	}
158 };
159 
160 class BenchmarkDemo2 : public BenchmarkDemo
161 {
162 public:
BenchmarkDemo2()163 	BenchmarkDemo2()
164 		:BenchmarkDemo(2)
165 	{
166 	}
167 
Create()168 	static DemoApplication* Create()
169 	{
170 		BenchmarkDemo2* demo = new BenchmarkDemo2;
171 		demo->myinit();
172 		demo->initPhysics();
173 		return demo;
174 	}
175 };
176 
177 class BenchmarkDemo3 : public BenchmarkDemo
178 {
179 public:
BenchmarkDemo3()180 	BenchmarkDemo3()
181 		:BenchmarkDemo(3)
182 	{
183 	}
184 
Create()185 	static DemoApplication* Create()
186 	{
187 		BenchmarkDemo3* demo = new BenchmarkDemo3;
188 		demo->myinit();
189 		demo->initPhysics();
190 		return demo;
191 	}
192 };
193 
194 class BenchmarkDemo4 : public BenchmarkDemo
195 {
196 public:
BenchmarkDemo4()197 	BenchmarkDemo4()
198 		:BenchmarkDemo(4)
199 	{
200 	}
201 
Create()202 	static DemoApplication* Create()
203 	{
204 		BenchmarkDemo4* demo = new BenchmarkDemo4;
205 		demo->myinit();
206 		demo->initPhysics();
207 		return demo;
208 	}
209 };
210 
211 
212 class BenchmarkDemo5 : public BenchmarkDemo
213 {
214 public:
BenchmarkDemo5()215 	BenchmarkDemo5()
216 		:BenchmarkDemo(5)
217 	{
218 	}
219 
Create()220 	static DemoApplication* Create()
221 	{
222 		BenchmarkDemo5* demo = new BenchmarkDemo5;
223 		demo->myinit();
224 		demo->initPhysics();
225 		return demo;
226 	}
227 };
228 
229 
230 class BenchmarkDemo6 : public BenchmarkDemo
231 {
232 public:
BenchmarkDemo6()233 	BenchmarkDemo6()
234 		:BenchmarkDemo(6)
235 	{
236 	}
237 
Create()238 	static DemoApplication* Create()
239 	{
240 		BenchmarkDemo6* demo = new BenchmarkDemo6;
241 		demo->myinit();
242 		demo->initPhysics();
243 		return demo;
244 	}
245 };
246 
247 class BenchmarkDemo7 : public BenchmarkDemo
248 {
249 public:
BenchmarkDemo7()250 	BenchmarkDemo7()
251 		:BenchmarkDemo(7)
252 	{
253 	}
254 
Create()255 	static DemoApplication* Create()
256 	{
257 		BenchmarkDemo7* demo = new BenchmarkDemo7;
258 		demo->myinit();
259 		demo->initPhysics();
260 		return demo;
261 	}
262 };
263 
264 #endif //BENCHMARK_DEMO_H
265 
266