Add DebugDraw.DrawArc and DebugDraw.DrawWireArc
This commit is contained in:
@@ -47,6 +47,8 @@
|
||||
//
|
||||
#define DEBUG_DRAW_CONE_RESOLUTION 32
|
||||
//
|
||||
#define DEBUG_DRAW_ARC_RESOLUTION 32
|
||||
//
|
||||
#define DEBUG_DRAW_TRIANGLE_SPHERE_RESOLUTION 12
|
||||
|
||||
struct DebugSphereCache
|
||||
@@ -1578,6 +1580,65 @@ void DebugDraw::DrawWireCone(const Vector3& position, const Quaternion& orientat
|
||||
::DrawCone(list, position, orientation, radius, angleXY, angleXZ, color, duration);
|
||||
}
|
||||
|
||||
void DebugDraw::DrawArc(const Vector3& position, const Quaternion& orientation, float radius, float angle, const Color& color, float duration, bool depthTest)
|
||||
{
|
||||
if (angle <= 0)
|
||||
return;
|
||||
if (angle > TWO_PI)
|
||||
angle = TWO_PI;
|
||||
Array<DebugTriangle>* list;
|
||||
if (depthTest)
|
||||
list = duration > 0 ? &Context->DebugDrawDepthTest.DefaultTriangles : &Context->DebugDrawDepthTest.OneFrameTriangles;
|
||||
else
|
||||
list = duration > 0 ? &Context->DebugDrawDefault.DefaultTriangles : &Context->DebugDrawDefault.OneFrameTriangles;
|
||||
const int32 resolution = Math::CeilToInt((float)DEBUG_DRAW_CONE_RESOLUTION / TWO_PI * angle);
|
||||
const float angleStep = angle / (float)resolution;
|
||||
const Matrix world = Matrix::RotationQuaternion(orientation) * Matrix::Translation(position);
|
||||
float currentAngle = 0.0f;
|
||||
DebugTriangle t;
|
||||
t.Color = Color32(color);
|
||||
t.TimeLeft = duration;
|
||||
t.V0 = world.GetTranslation();
|
||||
Vector3 pos(Math::Cos(0) * radius, Math::Sin(0) * radius, 0);
|
||||
Vector3::Transform(pos, world, t.V2);
|
||||
for (int32 i = 0; i < resolution; i++)
|
||||
{
|
||||
t.V1 = t.V2;
|
||||
currentAngle += angleStep;
|
||||
pos = Vector3(Math::Cos(currentAngle) * radius, Math::Sin(currentAngle) * radius, 0);
|
||||
Vector3::Transform(pos, world, t.V2);
|
||||
list->Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugDraw::DrawWireArc(const Vector3& position, const Quaternion& orientation, float radius, float angle, const Color& color, float duration, bool depthTest)
|
||||
{
|
||||
if (angle <= 0)
|
||||
return;
|
||||
if (angle > TWO_PI)
|
||||
angle = TWO_PI;
|
||||
const int32 resolution = Math::CeilToInt((float)DEBUG_DRAW_CONE_RESOLUTION / TWO_PI * angle);
|
||||
const float angleStep = angle / (float)resolution;
|
||||
const Matrix world = Matrix::RotationQuaternion(orientation) * Matrix::Translation(position);
|
||||
float currentAngle = 0.0f;
|
||||
Vector3 prevPos(world.GetTranslation());
|
||||
if (angle >= TWO_PI)
|
||||
{
|
||||
prevPos = Vector3(Math::Cos(TWO_PI - angleStep) * radius, Math::Sin(TWO_PI - angleStep) * radius, 0);
|
||||
Vector3::Transform(prevPos, world, prevPos);
|
||||
}
|
||||
for (int32 i = 0; i <= resolution; i++)
|
||||
{
|
||||
Vector3 pos(Math::Cos(currentAngle) * radius, Math::Sin(currentAngle) * radius, 0);
|
||||
Vector3::Transform(pos, world, pos);
|
||||
DrawLine(prevPos, pos, color, duration, depthTest);
|
||||
currentAngle += angleStep;
|
||||
prevPos = pos;
|
||||
}
|
||||
if (angle < TWO_PI)
|
||||
DrawLine(prevPos, world.GetTranslation(), color, duration, depthTest);
|
||||
}
|
||||
|
||||
void DebugDraw::DrawWireArrow(const Vector3& position, const Quaternion& orientation, float scale, const Color& color, float duration, bool depthTest)
|
||||
{
|
||||
Vector3 direction, up, right;
|
||||
|
||||
@@ -382,6 +382,30 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
|
||||
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
|
||||
API_FUNCTION() static void DrawWireCone(const Vector3& position, const Quaternion& orientation, float radius, float angleXY, float angleXZ, const Color& color, float duration = 0.0f, bool depthTest = true);
|
||||
|
||||
/// <summary>
|
||||
/// Draws the arc.
|
||||
/// </summary>
|
||||
/// <param name="position">The center position.</param>
|
||||
/// <param name="orientation">The orientation.</param>
|
||||
/// <param name="radius">The radius.</param>
|
||||
/// <param name="angle">The angle (in radians) of the arc (arc is facing positive Z axis - forward). Use PI*2 for full disc (360 degrees).</param>
|
||||
/// <param name="color">The color.</param>
|
||||
/// <param name="duration">The duration (in seconds). Use 0 to draw it only once.</param>
|
||||
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
|
||||
API_FUNCTION() static void DrawArc(const Vector3& position, const Quaternion& orientation, float radius, float angle, const Color& color, float duration = 0.0f, bool depthTest = true);
|
||||
|
||||
/// <summary>
|
||||
/// Draws the wireframe arc.
|
||||
/// </summary>
|
||||
/// <param name="position">The center position.</param>
|
||||
/// <param name="orientation">The orientation.</param>
|
||||
/// <param name="radius">The radius.</param>
|
||||
/// <param name="angle">The angle (in radians) of the arc (arc is facing positive Z axis - forward). Use PI*2 for full disc (360 degrees).</param>
|
||||
/// <param name="color">The color.</param>
|
||||
/// <param name="duration">The duration (in seconds). Use 0 to draw it only once.</param>
|
||||
/// <param name="depthTest">If set to <c>true</c> depth test will be performed, otherwise depth will be ignored.</param>
|
||||
API_FUNCTION() static void DrawWireArc(const Vector3& position, const Quaternion& orientation, float radius, float angle, const Color& color, float duration = 0.0f, bool depthTest = true);
|
||||
|
||||
/// <summary>
|
||||
/// Draws the wireframe arrow.
|
||||
/// </summary>
|
||||
@@ -454,6 +478,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
|
||||
#define DEBUG_DRAW_BOX(box, color, duration, depthTest) DebugDraw::DrawBox(box, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_CYLINDER(position, orientation, radius, height, color, duration, depthTest) DebugDraw::DrawCylinder(position, orientation, radius, height, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_CONE(position, orientation, radius, angleXY, angleXZ, color, duration, depthTest) DebugDraw::DrawCone(position, orientation, radius, angleXY, angleXZ, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_ARC(position, orientation, radius, angle, color, duration, depthTest) DebugDraw::DrawArc(position, orientation, radius, angle, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_TRIANGLE(v0, v1, v2, color, duration, depthTest) DebugDraw::DrawWireTriangle(v0, v1, v2, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_TRIANGLES(vertices, color, duration, depthTest) DebugDraw::DrawWireTriangles(vertices, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_TRIANGLES_EX(vertices, indices, color, duration, depthTest) DebugDraw::DrawWireTriangles(vertices, indices, color, duration, depthTest)
|
||||
@@ -463,6 +488,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
|
||||
#define DEBUG_DRAW_WIRE_TUBE(position, orientation, radius, length, color, duration, depthTest) DebugDraw::DrawWireTube(position, orientation, radius, length, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_CYLINDER(position, orientation, radius, height, color, duration, depthTest) DebugDraw::DrawWireCylinder(position, orientation, radius, height, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_CONE(position, orientation, radius, angleXY, angleXZ, color, duration, depthTest) DebugDraw::DrawWireCone(position, orientation, radius, angleXY, angleXZ, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_ARC(position, orientation, radius, angle, color, duration, depthTest) DebugDraw::DrawWireArc(position, orientation, radius, angle, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_ARROW(position, orientation, scale, color, duration, depthTest) DebugDraw::DrawWireArrow(position, orientation, scale, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_TEXT(text, position, color, size, duration) DebugDraw::DrawText(text, position, color, size, duration)
|
||||
|
||||
@@ -480,6 +506,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
|
||||
#define DEBUG_DRAW_BOX(box, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_CYLINDER(position, orientation, radius, height, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_CONE(position, orientation, radius, angleXY, angleXZ, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_ARC(position, orientation, radius, angle, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_TRIANGLE(v0, v1, v2, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_TRIANGLES(vertices, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_TRIANGLES_EX(vertices, indices, color, duration, depthTest)
|
||||
@@ -489,6 +516,7 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(DebugDraw);
|
||||
#define DEBUG_DRAW_WIRE_TUBE(position, orientation, radius, length, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_CYLINDER(position, orientation, radius, height, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_CONE(position, orientation, radius, angleXY, angleXZ, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_ARC(position, orientation, radius, angle, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_WIRE_ARROW(position, orientation, scale, color, duration, depthTest)
|
||||
#define DEBUG_DRAW_TEXT(text, position, color, size, duration)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user