1 /*
2 * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty.  In no event will the authors be held liable for any damages
6 * 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
9 * freely, subject to the following restrictions:
10 * 1. The origin of this software must not be misrepresented; you must not
11 * claim that you wrote the original software. If you use this software
12 * in a product, an acknowledgment in the product documentation would be
13 * appreciated but is not required.
14 * 2. Altered source versions must be plainly marked as such, and must not be
15 * misrepresented as being the original software.
16 * 3. This notice may not be removed or altered from any source distribution.
17 */
18 
19 #ifndef CONTINUOUS_TEST_H
20 #define CONTINUOUS_TEST_H
21 
22 class ContinuousTest : public Test
23 {
24 public:
25 
ContinuousTest()26 	ContinuousTest()
27 	{
28 		{
29 			b2BodyDef bd;
30 			bd.position.Set(0.0f, 0.0f);
31 			b2Body* body = m_world->CreateBody(&bd);
32 
33 			b2EdgeShape edge;
34 
35 			edge.Set(b2Vec2(-10.0f, 0.0f), b2Vec2(10.0f, 0.0f));
36 			body->CreateFixture(&edge, 0.0f);
37 
38 			b2PolygonShape shape;
39 			shape.SetAsBox(0.2f, 1.0f, b2Vec2(0.5f, 1.0f), 0.0f);
40 			body->CreateFixture(&shape, 0.0f);
41 		}
42 
43 #if 1
44 		{
45 			b2BodyDef bd;
46 			bd.type = b2_dynamicBody;
47 			bd.position.Set(0.0f, 20.0f);
48 			//bd.angle = 0.1f;
49 
50 			b2PolygonShape shape;
51 			shape.SetAsBox(2.0f, 0.1f);
52 
53 			m_body = m_world->CreateBody(&bd);
54 			m_body->CreateFixture(&shape, 1.0f);
55 
56 			m_angularVelocity = RandomFloat(-50.0f, 50.0f);
57 			//m_angularVelocity = 46.661274f;
58 			m_body->SetLinearVelocity(b2Vec2(0.0f, -100.0f));
59 			m_body->SetAngularVelocity(m_angularVelocity);
60 		}
61 #else
62 		{
63 			b2BodyDef bd;
64 			bd.type = b2_dynamicBody;
65 			bd.position.Set(0.0f, 2.0f);
66 			b2Body* body = m_world->CreateBody(&bd);
67 
68 			b2CircleShape shape;
69 			shape.m_p.SetZero();
70 			shape.m_radius = 0.5f;
71 			body->CreateFixture(&shape, 1.0f);
72 
73 			bd.bullet = true;
74 			bd.position.Set(0.0f, 10.0f);
75 			body = m_world->CreateBody(&bd);
76 			body->CreateFixture(&shape, 1.0f);
77 			body->SetLinearVelocity(b2Vec2(0.0f, -100.0f));
78 		}
79 #endif
80 
81 		extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;
82 		extern int32 b2_toiCalls, b2_toiIters;
83 		extern int32 b2_toiRootIters, b2_toiMaxRootIters;
84 		extern float32 b2_toiTime, b2_toiMaxTime;
85 
86 		b2_gjkCalls = 0; b2_gjkIters = 0; b2_gjkMaxIters = 0;
87 		b2_toiCalls = 0; b2_toiIters = 0;
88 		b2_toiRootIters = 0; b2_toiMaxRootIters = 0;
89 		b2_toiTime = 0.0f; b2_toiMaxTime = 0.0f;
90 	}
91 
Launch()92 	void Launch()
93 	{
94 		extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;
95 		extern int32 b2_toiCalls, b2_toiIters;
96 		extern int32 b2_toiRootIters, b2_toiMaxRootIters;
97 		extern float32 b2_toiTime, b2_toiMaxTime;
98 
99 		b2_gjkCalls = 0; b2_gjkIters = 0; b2_gjkMaxIters = 0;
100 		b2_toiCalls = 0; b2_toiIters = 0;
101 		b2_toiRootIters = 0; b2_toiMaxRootIters = 0;
102 		b2_toiTime = 0.0f; b2_toiMaxTime = 0.0f;
103 
104 		m_body->SetTransform(b2Vec2(0.0f, 20.0f), 0.0f);
105 		m_angularVelocity = RandomFloat(-50.0f, 50.0f);
106 		m_body->SetLinearVelocity(b2Vec2(0.0f, -100.0f));
107 		m_body->SetAngularVelocity(m_angularVelocity);
108 	}
109 
Step(Settings * settings)110 	void Step(Settings* settings)
111 	{
112 		Test::Step(settings);
113 
114 		extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;
115 
116 		if (b2_gjkCalls > 0)
117 		{
118 			g_debugDraw.DrawString(5, m_textLine, "gjk calls = %d, ave gjk iters = %3.1f, max gjk iters = %d",
119 				b2_gjkCalls, b2_gjkIters / float32(b2_gjkCalls), b2_gjkMaxIters);
120 			m_textLine += DRAW_STRING_NEW_LINE;
121 		}
122 
123 		extern int32 b2_toiCalls, b2_toiIters;
124 		extern int32 b2_toiRootIters, b2_toiMaxRootIters;
125 		extern float32 b2_toiTime, b2_toiMaxTime;
126 
127 		if (b2_toiCalls > 0)
128 		{
129 			g_debugDraw.DrawString(5, m_textLine, "toi calls = %d, ave [max] toi iters = %3.1f [%d]",
130 								b2_toiCalls, b2_toiIters / float32(b2_toiCalls), b2_toiMaxRootIters);
131 			m_textLine += DRAW_STRING_NEW_LINE;
132 
133 			g_debugDraw.DrawString(5, m_textLine, "ave [max] toi root iters = %3.1f [%d]",
134 				b2_toiRootIters / float32(b2_toiCalls), b2_toiMaxRootIters);
135 			m_textLine += DRAW_STRING_NEW_LINE;
136 
137 			g_debugDraw.DrawString(5, m_textLine, "ave [max] toi time = %.1f [%.1f] (microseconds)",
138 				1000.0f * b2_toiTime / float32(b2_toiCalls), 1000.0f * b2_toiMaxTime);
139 			m_textLine += DRAW_STRING_NEW_LINE;
140 		}
141 
142 		if (m_stepCount % 60 == 0)
143 		{
144 			//Launch();
145 		}
146 	}
147 
Create()148 	static Test* Create()
149 	{
150 		return new ContinuousTest;
151 	}
152 
153 	b2Body* m_body;
154 	float32 m_angularVelocity;
155 };
156 
157 #endif
158