Exemplo n.º 1
0
void QChain::cutCircle(Circle circle) {
  if (m_vertices.size() == 0) return;
  circle.setCenter(circle.pos());

  QPainterPath cr;
  cr.addEllipse(circle.x - circle.r, circle.y - circle.r, 2 * circle.r,
                2 * circle.r);

  QPolygonF polygon;
  for (QPointF p : m_vertices) polygon.append(p);
  QPainterPath chain;
  chain.addPolygon(polygon);

  if (!chain.intersects(cr)) return;

  chain = chain.subtracted(cr);

  for (const QPolygonF &poly : chain.toSubpathPolygons()) {
    std::vector<Vector2d> pts(poly.begin(), poly.end() - 1);

    if (std::fabs(Geometry::area(pts.begin(), pts.end())) > 5.f) {
      auto chain = std::make_unique<QChain>(world());
      chain->setVertices(std::vector<QPointF>(pts.begin(), pts.end()));
      chain->initializeLater(world());

      world()->itemSet()->addBody(std::move(chain));
    }
  }

  m_vertices.clear();
  destroyLater();
}
Exemplo n.º 2
0
Bullet::Bullet(Circle circle, Item *p) : QBody(p) {
  setPosition(QPointF(circle.pos()));
  setLinearDamping(0);
  setBullet(true);
  setBodyType(Dynamic);

  auto fixture = std::make_unique<Box2DCircle>(this);
  fixture->setShadowCaster(false);
  fixture->setRadius(circle.radius());
  fixture->setGroupIndex(-1);

  addFixture(std::move(fixture));
}