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 SPHERE_STACK_H
20 #define SPHERE_STACK_H
21 
22 class SphereStack : public Test
23 {
24 public:
25 
26     enum
27     {
28         e_count = 10
29     };
30 
SphereStack()31     SphereStack()
32     {
33         {
34             b2BodyDef bd;
35             b2Body* ground = m_world->CreateBody(&bd);
36 
37             b2EdgeShape shape;
38             shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
39             ground->CreateFixture(&shape, 0.0f);
40         }
41 
42         {
43             b2CircleShape shape;
44             shape.m_radius = 1.0f;
45 
46             for (int32 i = 0; i < e_count; ++i)
47             {
48                 b2BodyDef bd;
49                 bd.type = b2_dynamicBody;
50                 bd.position.Set(0.0, 4.0f + 3.0f * i);
51 
52                 m_bodies[i] = m_world->CreateBody(&bd);
53 
54                 m_bodies[i]->CreateFixture(&shape, 1.0f);
55 
56                 m_bodies[i]->SetLinearVelocity(b2Vec2(0.0f, -50.0f));
57             }
58         }
59     }
60 
Step(Settings * settings)61     void Step(Settings* settings)
62     {
63         Test::Step(settings);
64 
65         //for (int32 i = 0; i < e_count; ++i)
66         //{
67         //  printf("%g ", m_bodies[i]->GetWorldCenter().y);
68         //}
69 
70         //for (int32 i = 0; i < e_count; ++i)
71         //{
72         //  printf("%g ", m_bodies[i]->GetLinearVelocity().y);
73         //}
74 
75         //printf("\n");
76     }
77 
Create()78     static Test* Create()
79     {
80         return new SphereStack;
81     }
82 
83     b2Body* m_bodies[e_count];
84 };
85 
86 #endif
87