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_FRICTION_H 20 #define VARYING_FRICTION_H 21 22 class VaryingFriction : public Test 23 { 24 public: 25 VaryingFriction()26 VaryingFriction() 27 { 28 { 29 b2BodyDef bd; 30 b2Body* ground = m_world->CreateBody(&bd); 31 32 b2EdgeShape shape; 33 shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); 34 ground->CreateFixture(&shape, 0.0f); 35 } 36 37 { 38 b2PolygonShape shape; 39 shape.SetAsBox(13.0f, 0.25f); 40 41 b2BodyDef bd; 42 bd.position.Set(-4.0f, 22.0f); 43 bd.angle = -0.25f; 44 45 b2Body* ground = m_world->CreateBody(&bd); 46 ground->CreateFixture(&shape, 0.0f); 47 } 48 49 { 50 b2PolygonShape shape; 51 shape.SetAsBox(0.25f, 1.0f); 52 53 b2BodyDef bd; 54 bd.position.Set(10.5f, 19.0f); 55 56 b2Body* ground = m_world->CreateBody(&bd); 57 ground->CreateFixture(&shape, 0.0f); 58 } 59 60 { 61 b2PolygonShape shape; 62 shape.SetAsBox(13.0f, 0.25f); 63 64 b2BodyDef bd; 65 bd.position.Set(4.0f, 14.0f); 66 bd.angle = 0.25f; 67 68 b2Body* ground = m_world->CreateBody(&bd); 69 ground->CreateFixture(&shape, 0.0f); 70 } 71 72 { 73 b2PolygonShape shape; 74 shape.SetAsBox(0.25f, 1.0f); 75 76 b2BodyDef bd; 77 bd.position.Set(-10.5f, 11.0f); 78 79 b2Body* ground = m_world->CreateBody(&bd); 80 ground->CreateFixture(&shape, 0.0f); 81 } 82 83 { 84 b2PolygonShape shape; 85 shape.SetAsBox(13.0f, 0.25f); 86 87 b2BodyDef bd; 88 bd.position.Set(-4.0f, 6.0f); 89 bd.angle = -0.25f; 90 91 b2Body* ground = m_world->CreateBody(&bd); 92 ground->CreateFixture(&shape, 0.0f); 93 } 94 95 { 96 b2PolygonShape shape; 97 shape.SetAsBox(0.5f, 0.5f); 98 99 b2FixtureDef fd; 100 fd.shape = &shape; 101 fd.density = 25.0f; 102 103 float friction[5] = {0.75f, 0.5f, 0.35f, 0.1f, 0.0f}; 104 105 for (int i = 0; i < 5; ++i) 106 { 107 b2BodyDef bd; 108 bd.type = b2_dynamicBody; 109 bd.position.Set(-15.0f + 4.0f * i, 28.0f); 110 b2Body* body = m_world->CreateBody(&bd); 111 112 fd.friction = friction[i]; 113 body->CreateFixture(&fd); 114 } 115 } 116 } 117 Create()118 static Test* Create() 119 { 120 return new VaryingFriction; 121 } 122 }; 123 124 #endif 125