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 VARYING_RESTITUTION_H
20 #define VARYING_RESTITUTION_H
21 
22 // Note: even with a restitution of 1.0, there is some energy change
23 // due to position correction.
24 class VaryingRestitution : public Test
25 {
26 public:
27 
VaryingRestitution()28     VaryingRestitution()
29     {
30         {
31             b2BodyDef bd;
32             b2Body* ground = m_world->CreateBody(&bd);
33 
34             b2EdgeShape shape;
35             shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f));
36             ground->CreateFixture(&shape, 0.0f);
37         }
38 
39         {
40             b2CircleShape shape;
41             shape.m_radius = 1.0f;
42 
43             b2FixtureDef fd;
44             fd.shape = &shape;
45             fd.density = 1.0f;
46 
47             float32 restitution[7] = {0.0f, 0.1f, 0.3f, 0.5f, 0.75f, 0.9f, 1.0f};
48 
49             for (int32 i = 0; i < 7; ++i)
50             {
51                 b2BodyDef bd;
52                 bd.type = b2_dynamicBody;
53                 bd.position.Set(-10.0f + 3.0f * i, 20.0f);
54 
55                 b2Body* body = m_world->CreateBody(&bd);
56 
57                 fd.restitution = restitution[i];
58                 body->CreateFixture(&fd);
59             }
60         }
61     }
62 
Create()63     static Test* Create()
64     {
65         return new VaryingRestitution;
66     }
67 };
68 
69 #endif
70