| 117 | } |
| 118 | |
| 119 | void Box2DTest::initPhysics() |
| 120 | { |
| 121 | b2Vec2 gravity; |
| 122 | gravity.Set(0.0f, -10.0f); |
| 123 | world = new b2World(gravity); |
| 124 | |
| 125 | // Do we want to let bodies sleep? |
| 126 | world->SetAllowSleeping(true); |
| 127 | |
| 128 | world->SetContinuousPhysics(true); |
| 129 | |
| 130 | // Define the ground body. |
| 131 | b2BodyDef groundBodyDef; |
| 132 | groundBodyDef.position.Set(0, 0); // bottom-left corner |
| 133 | |
| 134 | // Call the body factory which allocates memory for the ground body |
| 135 | // from a pool and creates the ground box shape (also from a pool). |
| 136 | // The body is also added to the world. |
| 137 | b2Body* groundBody = world->CreateBody(&groundBodyDef); |
| 138 | |
| 139 | // Define the ground box shape. |
| 140 | b2EdgeShape groundBox; |
| 141 | |
| 142 | // bottom |
| 143 | groundBox.SetTwoSided(b2Vec2(VisibleRect::leftBottom().x / PTM_RATIO, VisibleRect::leftBottom().y / PTM_RATIO), |
| 144 | b2Vec2(VisibleRect::rightBottom().x / PTM_RATIO, VisibleRect::rightBottom().y / PTM_RATIO)); |
| 145 | groundBody->CreateFixture(&groundBox, 0); |
| 146 | |
| 147 | // top |
| 148 | groundBox.SetTwoSided(b2Vec2(VisibleRect::leftTop().x / PTM_RATIO, VisibleRect::leftTop().y / PTM_RATIO), |
| 149 | b2Vec2(VisibleRect::rightTop().x / PTM_RATIO, VisibleRect::rightTop().y / PTM_RATIO)); |
| 150 | groundBody->CreateFixture(&groundBox, 0); |
| 151 | |
| 152 | // left |
| 153 | groundBox.SetTwoSided(b2Vec2(VisibleRect::leftTop().x / PTM_RATIO, VisibleRect::leftTop().y / PTM_RATIO), |
| 154 | b2Vec2(VisibleRect::leftBottom().x / PTM_RATIO, VisibleRect::leftBottom().y / PTM_RATIO)); |
| 155 | groundBody->CreateFixture(&groundBox, 0); |
| 156 | |
| 157 | // right |
| 158 | groundBox.SetTwoSided(b2Vec2(VisibleRect::rightBottom().x / PTM_RATIO, VisibleRect::rightBottom().y / PTM_RATIO), |
| 159 | b2Vec2(VisibleRect::rightTop().x / PTM_RATIO, VisibleRect::rightTop().y / PTM_RATIO)); |
| 160 | groundBody->CreateFixture(&groundBox, 0); |
| 161 | |
| 162 | // Small triangle |
| 163 | b2Vec2 vertices[3]; |
| 164 | vertices[0].Set(-1.0f, 0.0f); |
| 165 | vertices[1].Set(1.0f, 0.0f); |
| 166 | vertices[2].Set(0.0f, 2.0f); |
| 167 | |
| 168 | b2PolygonShape polygon; |
| 169 | polygon.Set(vertices, 3); |
| 170 | |
| 171 | b2FixtureDef triangleShapeDef; |
| 172 | triangleShapeDef.shape = &polygon; |
| 173 | triangleShapeDef.density = 1.0f; |
| 174 | |
| 175 | b2BodyDef triangleBodyDef; |
| 176 | triangleBodyDef.type = b2_dynamicBody; |
no test coverage detected