MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / AddDebugSphere

Method AddDebugSphere

TombEngine/Renderer/RendererDraw.cpp:1522–1599  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1520 }
1521
1522 void Renderer::AddDebugSphere(const Vector3& center, float radius, const Color& color, RendererDebugPage page, bool isWireframe)
1523 {
1524 constexpr auto AXIS_COUNT = 3;
1525 constexpr auto SUBDIVISION_COUNT = 16;
1526 constexpr auto STEP_ANGLE = PI / (SUBDIVISION_COUNT / 4);
1527
1528 if (_isLocked)
1529 return;
1530
1531 if (!DebugMode || (_debugPage != page && page != RendererDebugPage::None))
1532 return;
1533
1534 // Construct sphere.
1535 if (isWireframe)
1536 {
1537 auto prevVertices = std::array<Vector3, AXIS_COUNT>{};
1538 for (int i = 0; i < (SUBDIVISION_COUNT / 4); i++)
1539 {
1540 float x = sin(STEP_ANGLE * i) * radius;
1541 float z = cos(STEP_ANGLE * i) * radius;
1542
1543 float angle = 0.0f;
1544
1545 for (int j = 0; j < SUBDIVISION_COUNT; j++)
1546 {
1547 auto vertices = std::array<Vector3, AXIS_COUNT>
1548 {
1549 center + Vector3(sin(angle) * abs(x), z, cos(angle) * abs(x)),
1550 center + Vector3(cos(angle) * abs(x), sin(angle) * abs(x), z),
1551 center + Vector3(z, sin(angle) * abs(x), cos(angle) * abs(x))
1552 };
1553
1554 if (j > 0)
1555 {
1556 for (int k = 0; k < vertices.size(); k++)
1557 AddDebugLine(prevVertices[k], vertices[k], color);
1558 }
1559
1560 prevVertices = vertices;
1561 angle += PI_MUL_2 / (SUBDIVISION_COUNT - 1);
1562 }
1563 }
1564 }
1565 else
1566 {
1567 auto vertices = std::vector<Vector3>{};
1568 for (int i = 0; i <= SUBDIVISION_COUNT; i++)
1569 {
1570 float pitch = ((float)i / SUBDIVISION_COUNT) * PI;
1571 float y = cos(pitch) * radius;
1572 float radiusAtY = sin(pitch) * radius;
1573
1574 for (int j = 0; j < SUBDIVISION_COUNT; j++)
1575 {
1576 float theta = ((float)j / SUBDIVISION_COUNT) * PI_MUL_2;
1577 float x = cos(theta) * radiusAtY;
1578 float z = sin(theta) * radiusAtY;
1579

Callers 1

DrawDebugSphereFunction · 0.80

Calls 3

Vector3Function · 0.50
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected