Body * World::findById(int id) const { for(const b2Body * b2ody = getB2World()->GetBodyList(); b2ody; b2ody = b2ody->GetNext()) { Body * body = static_cast<Body *>(b2ody->GetUserData()); if(body->getId() == id) return body; } ythrow(std::runtime_error, "ID " << id << " не найден."); }
bool World::createMouseJoint(const Vec2f & mousePos) { Body * body = findFirstByPos(mousePos); if(body == nullptr || body->getId() == 1 || !body->isDynamic()) return false; body->getB2Body()->SetAwake(true); b2MouseJointDef jd; jd.bodyA = findById(1)->getB2Body(); // Не используется jd.bodyB = body->getB2Body(); jd.target = mousePos.toB2Pos(); jd.collideConnected = true; jd.maxForce = body->getB2Body()->GetMass() * 1000; _mouseJoint = static_cast<b2MouseJoint *>(getB2World()->CreateJoint(&jd)); return true; }