Simulator::Simulator(QGraphicsScene *scene, QObject *parent): QObject(parent), timerId(0), scene(scene){ // Define the gravity vector. b2Vec2 gravity(0.0f,-10.0f); world = new b2World(gravity, true); b2BodyDef bodyDef; b2PolygonShape shapeDef; b2FixtureDef fixtureDef; bodyDef.position.Set(200.0f,-250); shapeDef.SetAsBox(100.0f, 10.0f); fixtureDef.shape = &shapeDef; groundBody = world->CreateBody(&bodyDef); groundBody->CreateFixture(&fixtureDef); // Create lots of little colored triangles, random pos, rotation, color. for (int i = 0; i < BODYCOUNT; ++i) { //poly << QPointF(0, -10) << QPointF(-5, 0) << QPointF(5, 0); Bot* polygon = bodyItems[i] = new Bot(world); polygon->setPos(200+-20 + qrand() % 40,200+ -75 - qrand() % 150); polygon->setRotation(qrand() % 360); polygon->setBrush(QColor(128 + qrand() % 128, 128 + qrand() % 128, 128 + qrand() % 128)); polygon->_init(); scene->addItem(polygon); } }