| 1457 | } |
| 1458 | |
| 1459 | void Renderer::AddDebugCylinder(const Vector3& center, const Quaternion& orient, float radius, float length, const Color& color, RendererDebugPage page, bool isWireframe) |
| 1460 | { |
| 1461 | constexpr auto SUBDIVISION_COUNT = 32; |
| 1462 | |
| 1463 | if (_isLocked) |
| 1464 | return; |
| 1465 | |
| 1466 | if (!DebugMode || (_debugPage != page && page != RendererDebugPage::None)) |
| 1467 | return; |
| 1468 | |
| 1469 | auto rotMatrix = Matrix::CreateFromQuaternion(orient); |
| 1470 | |
| 1471 | auto baseVertices = std::vector<Vector3>{}; |
| 1472 | baseVertices.reserve(SUBDIVISION_COUNT); |
| 1473 | float angle = 0.0f; |
| 1474 | |
| 1475 | // Calculate base circle vertices. |
| 1476 | for (int i = 0; i <= SUBDIVISION_COUNT; i++) |
| 1477 | { |
| 1478 | float sinAngle = sin(angle); |
| 1479 | float cosAngle = cos(angle); |
| 1480 | |
| 1481 | auto vertex = center + Vector3::Transform(Vector3(radius * sinAngle, radius * cosAngle, 0.0f), rotMatrix); |
| 1482 | baseVertices.push_back(vertex); |
| 1483 | |
| 1484 | angle += PI_MUL_2 / SUBDIVISION_COUNT; |
| 1485 | } |
| 1486 | |
| 1487 | auto dir = Geometry::ConvertQuatToDirection(orient); |
| 1488 | |
| 1489 | // Calculate top circle vertices. |
| 1490 | auto topVertices = baseVertices; |
| 1491 | for (auto& vertex : topVertices) |
| 1492 | vertex = Geometry::TranslatePoint(vertex, dir, length); |
| 1493 | |
| 1494 | // Construct cylinder. |
| 1495 | auto topCenter = Geometry::TranslatePoint(center, dir, length); |
| 1496 | for (int i = 0; i < baseVertices.size(); i++) |
| 1497 | { |
| 1498 | const auto& baseVertex0 = baseVertices[i]; |
| 1499 | const auto& baseVertex1 = baseVertices[(i == (baseVertices.size() - 1)) ? 0 : (i + 1)]; |
| 1500 | |
| 1501 | const auto& topVertex0 = topVertices[i]; |
| 1502 | const auto& topVertex1 = topVertices[(i == (topVertices.size() - 1)) ? 0 : (i + 1)]; |
| 1503 | |
| 1504 | if (isWireframe) |
| 1505 | { |
| 1506 | AddDebugLine(baseVertex0, baseVertex1, color); |
| 1507 | AddDebugLine(topVertex0, topVertex1, color); |
| 1508 | |
| 1509 | if ((i % (SUBDIVISION_COUNT / 8)) == 0) |
| 1510 | AddDebugLine(baseVertex0, topVertex0, color); |
| 1511 | } |
| 1512 | else |
| 1513 | { |
| 1514 | AddDebugTriangle(baseVertex0, baseVertex1, center, color); |
| 1515 | AddDebugTriangle(topVertex0, topVertex1, topCenter, color); |
| 1516 | AddDebugTriangle(baseVertex0, baseVertex1, topVertex1, color); |
no test coverage detected