MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / DrawCone

Function DrawCone

Source/Engine/Debug/DebugDraw.cpp:2043–2088  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2041 }
2042
2043 void DrawCone(Array<DebugTriangle>* list, const Vector3& position, const Quaternion& orientation, float radius, float angleXY, float angleXZ, const Color& color, float duration)
2044 {
2045 PROFILE_MEM(EngineDebug);
2046 const float tolerance = 0.001f;
2047 const float angle1 = Math::Clamp(angleXY, tolerance, PI - tolerance);
2048 const float angle2 = Math::Clamp(angleXZ, tolerance, PI - tolerance);
2049
2050 const float sinX1 = Math::Sin(0.5f * angle1);
2051 const float sinY2 = Math::Sin(0.5f * angle2);
2052 const float sinSqX1 = sinX1 * sinX1;
2053 const float sinSqY2 = sinY2 * sinY2;
2054
2055 DebugTriangle t;
2056 t.Color = Color32(color);
2057 t.TimeLeft = duration;
2058 const Float3 positionF = position - Context->Origin;
2059 const Matrix world = Matrix::RotationQuaternion(orientation) * Matrix::Translation(positionF);
2060 t.V0 = world.GetTranslation();
2061
2062 Float3 vertices[DEBUG_DRAW_CONE_RESOLUTION];
2063 for (uint32 i = 0; i < DEBUG_DRAW_CONE_RESOLUTION; i++)
2064 {
2065 const float alpha = (float)i / (float)DEBUG_DRAW_CONE_RESOLUTION;
2066 const float azimuth = alpha * TWO_PI;
2067
2068 const float phi = Math::Atan2(Math::Sin(azimuth) * sinY2, Math::Cos(azimuth) * sinX1);
2069 const float sinPhi = Math::Sin(phi);
2070 const float cosPhi = Math::Cos(phi);
2071 const float sinSqPhi = sinPhi * sinPhi;
2072 const float cosSqPhi = cosPhi * cosPhi;
2073
2074 const float rSq = sinSqX1 * sinSqY2 / (sinSqX1 * sinSqPhi + sinSqY2 * cosSqPhi);
2075 const float r = Math::Sqrt(rSq);
2076 const float s = Math::Sqrt(1 - rSq);
2077
2078 Float3 vertex = Float3(2 * s * (r * cosPhi), 2 * s * (r * sinPhi), 1 - 2 * rSq) * radius;
2079 Float3::Transform(vertex, world, vertices[i]);
2080 }
2081
2082 for (uint32 i = 0; i < DEBUG_DRAW_CONE_RESOLUTION; i++)
2083 {
2084 t.V1 = vertices[i];
2085 t.V2 = vertices[(i + 1) % DEBUG_DRAW_CONE_RESOLUTION];
2086 list->Add(t);
2087 }
2088 }
2089}
2090
2091void DebugDraw::DrawCylinder(const Vector3& position, const Quaternion& orientation, float radius, float height, const Color& color, float duration, bool depthTest)

Callers 2

DrawConeMethod · 0.85
DrawWireConeMethod · 0.85

Calls 10

ClampFunction · 0.85
RotationQuaternionFunction · 0.85
Float3Class · 0.85
TransformClass · 0.70
SinFunction · 0.50
Color32Class · 0.50
Atan2Function · 0.50
CosFunction · 0.50
SqrtFunction · 0.50
AddMethod · 0.45

Tested by

no test coverage detected