Browse Source

Fix DebugRenderer::AddSphereSector AS binding. Use AddSphereSector for rendering SoundSource3D.

Eugene Kozlov 8 years ago
parent
commit
cf0d6b6f78
2 changed files with 6 additions and 69 deletions
  1. 1 1
      Source/Urho3D/AngelScript/GraphicsAPI.cpp
  2. 5 68
      Source/Urho3D/Audio/SoundSource3D.cpp

+ 1 - 1
Source/Urho3D/AngelScript/GraphicsAPI.cpp

@@ -2056,7 +2056,7 @@ static void RegisterDebugRenderer(asIScriptEngine* engine)
     engine->RegisterObjectMethod("DebugRenderer", "void AddFrustum(const Frustum&in, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddFrustum), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddPolyhedron(const Polyhedron&in, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddPolyhedron), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddSphere(const Sphere&in, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddSphere), asCALL_THISCALL);
-    engine->RegisterObjectMethod("DebugRenderer", "void AddSphereSector(const Sphere&in, const Quaternion&in, float, bool, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddSphere), asCALL_THISCALL);
+    engine->RegisterObjectMethod("DebugRenderer", "void AddSphereSector(const Sphere&in, const Quaternion&in, float, bool, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddSphereSector), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddSkeleton(Skeleton@+, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddSkeleton), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddCircle(const Vector3&in, const Vector3&in, float, const Color&in, int steps = 64, bool depthTest = true)", asMETHOD(DebugRenderer, AddCircle), asCALL_THISCALL);
     engine->RegisterObjectMethod("DebugRenderer", "void AddCross(const Vector3&in, float size, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddCross), asCALL_THISCALL);

+ 5 - 68
Source/Urho3D/Audio/SoundSource3D.cpp

@@ -43,63 +43,6 @@ static const Color OUTER_COLOR(1.0f, 0.0f, 1.0f);
 
 extern const char* AUDIO_CATEGORY;
 
-static Vector3 PointOnSphere(float radius, float theta, float phi)
-{
-    // Zero angles point toward positive Z axis
-    phi += 90.0f;
-
-    return Vector3(
-        radius * Sin(theta) * Sin(phi),
-        radius * Cos(phi),
-        radius * Cos(theta) * Sin(phi)
-    );
-}
-
-static void DrawDebugArc(const Vector3& worldPosition, const Quaternion& worldRotation, float angle, float distance, bool drawLines,
-    const Color& color, DebugRenderer* debug, bool depthTest)
-{
-    if (angle <= 0.f)
-        return;
-    else if (angle >= 360.0f)
-    {
-        debug->AddSphere(Sphere(worldPosition, distance), color, depthTest);
-        return;
-    }
-
-    unsigned uintColor = color.ToUInt();
-    float halfAngle = 0.5f * angle;
-
-    if (drawLines)
-    {
-        debug->AddLine(worldPosition, worldPosition + worldRotation * PointOnSphere(distance, halfAngle, halfAngle),
-            uintColor);
-        debug->AddLine(worldPosition, worldPosition + worldRotation * PointOnSphere(distance, -halfAngle, halfAngle),
-            uintColor);
-        debug->AddLine(worldPosition, worldPosition + worldRotation * PointOnSphere(distance, halfAngle, -halfAngle),
-            uintColor);
-        debug->AddLine(worldPosition, worldPosition + worldRotation * PointOnSphere(distance, -halfAngle, -halfAngle),
-            uintColor);
-    }
-
-    const float step = 0.5f;
-
-    for (float x = -1.0f; x < 1.0f; x += step)
-    {
-        debug->AddLine(worldPosition + worldRotation * PointOnSphere(distance, x * halfAngle, halfAngle),
-            worldPosition + worldRotation * PointOnSphere(distance, (x + step) * halfAngle, halfAngle),
-            uintColor);
-        debug->AddLine(worldPosition + worldRotation * PointOnSphere(distance, x * halfAngle, -halfAngle),
-            worldPosition + worldRotation * PointOnSphere(distance, (x + step) * halfAngle, -halfAngle),
-            uintColor);
-        debug->AddLine(worldPosition + worldRotation * PointOnSphere(distance, halfAngle, x * halfAngle),
-            worldPosition + worldRotation * PointOnSphere(distance, halfAngle, (x + step) * halfAngle),
-            uintColor);
-        debug->AddLine(worldPosition + worldRotation * PointOnSphere(distance, -halfAngle, x * halfAngle),
-            worldPosition + worldRotation * PointOnSphere(distance, -halfAngle, (x + step) * halfAngle),
-            uintColor);
-    }
-}
-
 SoundSource3D::SoundSource3D(Context* context) :
     SoundSource(context),
     nearDistance_(DEFAULT_NEARDISTANCE),
@@ -139,17 +82,11 @@ void SoundSource3D::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
     // Draw cones for directional sounds, or spheres for non-directional
     if (innerAngle_ < DEFAULT_ANGLE && outerAngle_ > 0.0f)
     {
-        /// \todo Replace arcs with sphere sector
-        //const Quaternion rotation = worldRotation * Quaternion(Vector3::UP, Vector3::FORWARD);
-        //debug->AddSphereSector(Sphere(worldPosition, nearDistance_), rotation, innerAngle_, false, INNER_COLOR, depthTest);
-        //debug->AddSphereSector(Sphere(worldPosition, nearDistance_), rotation, outerAngle_, false, OUTER_COLOR, depthTest);
-        //debug->AddSphereSector(Sphere(worldPosition, farDistance_), rotation, innerAngle_, true, INNER_COLOR, depthTest);
-        //debug->AddSphereSector(Sphere(worldPosition, farDistance_), rotation, outerAngle_, true, OUTER_COLOR, depthTest);
-
-        DrawDebugArc(worldPosition, worldRotation, innerAngle_, nearDistance_, false, INNER_COLOR, debug, depthTest);
-        DrawDebugArc(worldPosition, worldRotation, outerAngle_, nearDistance_, false, OUTER_COLOR, debug, depthTest);
-        DrawDebugArc(worldPosition, worldRotation, innerAngle_, farDistance_, true, INNER_COLOR, debug, depthTest);
-        DrawDebugArc(worldPosition, worldRotation, outerAngle_, farDistance_, true, OUTER_COLOR, debug, depthTest);
+        const Quaternion rotation = worldRotation * Quaternion(Vector3::UP, Vector3::FORWARD);
+        debug->AddSphereSector(Sphere(worldPosition, nearDistance_), rotation, innerAngle_, false, INNER_COLOR, depthTest);
+        debug->AddSphereSector(Sphere(worldPosition, nearDistance_), rotation, outerAngle_, false, OUTER_COLOR, depthTest);
+        debug->AddSphereSector(Sphere(worldPosition, farDistance_), rotation, innerAngle_, true, INNER_COLOR, depthTest);
+        debug->AddSphereSector(Sphere(worldPosition, farDistance_), rotation, outerAngle_, true, OUTER_COLOR, depthTest);
     }
     else
     {