|
|
@@ -225,7 +225,6 @@ void DebugRenderer::AddBoundingBox(const BoundingBox& box, const Matrix3x4& tran
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
void DebugRenderer::AddFrustum(const Frustum& frustum, const Color& color, bool depthTest)
|
|
|
{
|
|
|
const Vector3* vertices = frustum.vertices_;
|
|
|
@@ -260,27 +259,18 @@ void DebugRenderer::AddPolyhedron(const Polyhedron& poly, const Color& color, bo
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static Vector3 PointOnSphere(const Sphere& sphere, unsigned theta, unsigned phi)
|
|
|
-{
|
|
|
- return Vector3(
|
|
|
- sphere.center_.x_ + sphere.radius_ * Sin((float)theta) * Sin((float)phi),
|
|
|
- sphere.center_.y_ + sphere.radius_ * Cos((float)phi),
|
|
|
- sphere.center_.z_ + sphere.radius_ * Cos((float)theta) * Sin((float)phi)
|
|
|
- );
|
|
|
-}
|
|
|
-
|
|
|
void DebugRenderer::AddSphere(const Sphere& sphere, const Color& color, bool depthTest)
|
|
|
{
|
|
|
unsigned uintColor = color.ToUInt();
|
|
|
|
|
|
- for (unsigned j = 0; j < 180; j += 45)
|
|
|
+ for (float j = 0; j < 180; j += 45)
|
|
|
{
|
|
|
- for (unsigned i = 0; i < 360; i += 45)
|
|
|
+ for (float i = 0; i < 360; i += 45)
|
|
|
{
|
|
|
- Vector3 p1 = PointOnSphere(sphere, i, j);
|
|
|
- Vector3 p2 = PointOnSphere(sphere, i + 45, j);
|
|
|
- Vector3 p3 = PointOnSphere(sphere, i, j + 45);
|
|
|
- Vector3 p4 = PointOnSphere(sphere, i + 45, j + 45);
|
|
|
+ Vector3 p1 = sphere.GetPoint(i, j);
|
|
|
+ Vector3 p2 = sphere.GetPoint(i + 45, j);
|
|
|
+ Vector3 p3 = sphere.GetPoint(i, j + 45);
|
|
|
+ Vector3 p4 = sphere.GetPoint(i + 45, j + 45);
|
|
|
|
|
|
AddLine(p1, p2, uintColor, depthTest);
|
|
|
AddLine(p3, p4, uintColor, depthTest);
|
|
|
@@ -290,16 +280,70 @@ void DebugRenderer::AddSphere(const Sphere& sphere, const Color& color, bool dep
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void DebugRenderer::AddSphereSector(const Sphere& sphere, const Quaternion& rotation, float angle,
|
|
|
+ bool drawLines, const Color& color, bool depthTest)
|
|
|
+{
|
|
|
+ if (angle <= 0.0f)
|
|
|
+ return;
|
|
|
+ else if (angle >= 360.0f)
|
|
|
+ {
|
|
|
+ AddSphere(sphere, color, depthTest);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ static const unsigned numCircleSegments = 8;
|
|
|
+ static const unsigned numLines = 4;
|
|
|
+ static const float arcStep = 45.0f;
|
|
|
+
|
|
|
+ const unsigned uintColor = color.ToUInt();
|
|
|
+ const float halfAngle = 0.5f * angle;
|
|
|
+ const unsigned numArcSegments = static_cast<unsigned>(Ceil(halfAngle / arcStep)) + 1;
|
|
|
+
|
|
|
+ // Draw circle
|
|
|
+ for (unsigned j = 0; j < numCircleSegments; ++j)
|
|
|
+ {
|
|
|
+ AddLine(
|
|
|
+ sphere.center_ + rotation * sphere.GetLocalPoint(j * 360.0f / numCircleSegments, halfAngle),
|
|
|
+ sphere.center_ + rotation * sphere.GetLocalPoint((j + 1) * 360.0f / numCircleSegments, halfAngle),
|
|
|
+ uintColor);
|
|
|
+ }
|
|
|
+
|
|
|
+ // Draw arcs
|
|
|
+ const unsigned step = numCircleSegments / numLines;
|
|
|
+ for (unsigned i = 0; i < numArcSegments - 1; ++i)
|
|
|
+ {
|
|
|
+ for (unsigned j = 0; j < numCircleSegments; j += step)
|
|
|
+ {
|
|
|
+ const float nextPhi = i + 1 == numArcSegments - 1 ? halfAngle : (i + 1) * arcStep;
|
|
|
+ AddLine(
|
|
|
+ sphere.center_ + rotation * sphere.GetLocalPoint(j * 360.0f / numCircleSegments, i * arcStep),
|
|
|
+ sphere.center_ + rotation * sphere.GetLocalPoint(j * 360.0f / numCircleSegments, nextPhi),
|
|
|
+ uintColor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // Draw lines
|
|
|
+ if (drawLines)
|
|
|
+ {
|
|
|
+ for (unsigned j = 0; j < numCircleSegments; j += step)
|
|
|
+ {
|
|
|
+ AddLine(sphere.center_,
|
|
|
+ sphere.center_ + rotation * sphere.GetLocalPoint(j * 360.0f / numCircleSegments, halfAngle),
|
|
|
+ uintColor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void DebugRenderer::AddCylinder(const Vector3& position, float radius, float height, const Color& color, bool depthTest)
|
|
|
{
|
|
|
Sphere sphere(position, radius);
|
|
|
Vector3 heightVec(0, height, 0);
|
|
|
Vector3 offsetXVec(radius, 0, 0);
|
|
|
Vector3 offsetZVec(0, 0, radius);
|
|
|
- for (unsigned i = 0; i < 360; i += 45)
|
|
|
+ for (float i = 0; i < 360; i += 45)
|
|
|
{
|
|
|
- Vector3 p1 = PointOnSphere(sphere, i, 90);
|
|
|
- Vector3 p2 = PointOnSphere(sphere, i + 45, 90);
|
|
|
+ Vector3 p1 = sphere.GetPoint(i, 90);
|
|
|
+ Vector3 p2 = sphere.GetPoint(i + 45, 90);
|
|
|
AddLine(p1, p2, color, depthTest);
|
|
|
AddLine(p1 + heightVec, p2 + heightVec, color, depthTest);
|
|
|
}
|