void Renderer::drawBar(const cpShape* shape) { const auto p1 = cpSegmentShapeGetA(shape); const auto p2 = cpSegmentShapeGetB(shape); const auto radius = static_cast<float>(cpSegmentShapeGetRadius(shape)); auto rect = RoundedBar(radius); rect.setOutlineColor(sf::Color::Green); rect.setOutlineThickness(1.0f); rect.setFillColor(sf::Color::Transparent); const auto sfp1 = Utils::toSfv(p1, mTargetSize); const auto sfp2 = Utils::toSfv(p2, mTargetSize); const auto len = static_cast<float>(cpvdist(p1, p2)); if (p1.x == p2.x) { rect.setLength(len); auto y = std::min(sfp1.y, sfp2.y); rect.setRotation(90); rect.setPosition(sfp1.x, y + len / 2 - radius); rect.adjustOrigin(); } else if (p1.y == p2.y) { rect.setLength(len); auto x = std::min(sfp1.x, sfp2.x); rect.setPosition(x + len / 2 - radius, sfp1.y); rect.adjustOrigin(); } { for (auto& target : mTargets) { auto view = target->getView(); auto center = view.getCenter(); auto pieceW = view.getSize().x * 1.0f; auto pieceH = view.getSize().y * 1.0f; auto x = center.x - pieceW / 2.0f; auto y = center.y - pieceH / 2.0f; auto vRect = sf::FloatRect(x, y, pieceW, pieceH); if (vRect.intersects(rect.getGlobalBounds())) { target->draw(rect); } } } }
float ShapeSegment::getRadius() const { return cpSegmentShapeGetRadius(mShape); }