inline void GetRandomAABB(b2AABB* aabb) { b2Vec2 w; w.Set(k_width, k_width); aabb->lowerBound.x = b2Random(-k_extent, k_extent); aabb->lowerBound.y = b2Random(0.0f, 2.0f * k_extent); aabb->upperBound = aabb->lowerBound + w; }
inline void MoveAABB(b2AABB* aabb) { b2Vec2 d; d.x = b2Random(-0.5f, 0.5f); d.y = b2Random(-0.5f, 0.5f); //d.x = 2.0f; //d.y = 0.0f; aabb->lowerBound += d; aabb->upperBound += d; b2Vec2 c0 = 0.5f * (aabb->lowerBound + aabb->upperBound); b2Vec2 min; min.Set(-k_extent, 0.0f); b2Vec2 max; max.Set(k_extent, 2.0f * k_extent); b2Vec2 c = b2Clamp(c0, min, max); aabb->lowerBound += c - c0; aabb->upperBound += c - c0; }
void Test::LaunchBomb() { if (m_bomb) { m_world->DestroyBody(m_bomb); m_bomb = NULL; } b2BodyDef bd; bd.allowSleep = true; bd.position.Set(b2Random(-15.0f, 15.0f), 30.0f); bd.isBullet = true; m_bomb = m_world->CreateBody(&bd); m_bomb->SetLinearVelocity(-5.0f * bd.position); b2CircleDef sd; sd.radius = 0.3f; sd.density = 20.0f; sd.restitution = 0.1f; m_bomb->CreateShape(&sd); m_bomb->SetMassFromShapes(); }