瀏覽代碼

CirCle -> Circle. Convert color to uint prior to drawing the lines, instead of converting on each line.

Lasse Öörni 10 年之前
父節點
當前提交
b9155ca8b3

+ 13 - 8
Source/Urho3D/Graphics/DebugRenderer.cpp

@@ -340,27 +340,30 @@ void DebugRenderer::AddTriangleMesh(const void* vertexData, unsigned vertexSize,
     }
 }
 
-void DebugRenderer::AddCirCle(const Vector3& center, const Vector3& normal, float radius, const Color& color, int steps, bool depthTest)
+void DebugRenderer::AddCircle(const Vector3& center, const Vector3& normal, float radius, const Color& color, int steps, bool depthTest)
 {
     Quaternion orientation;
     orientation.FromRotationTo(Vector3::UP, normal.Normalized());
     Vector3 p = orientation * Vector3(radius, 0, 0) + center;
+    unsigned uintColor = color.ToUInt();
 
     for(int i = 1; i <= steps; ++i)
     {
         const float angle = (float)i / (float)steps * 360.0f;
         Vector3 v(radius * Cos(angle), 0, radius * Sin(angle));
         Vector3 c = orientation * v + center;
-        AddLine(p, c, color, depthTest);
+        AddLine(p, c, uintColor, depthTest);
         p = c;
     }
 
     p = center + normal * (radius / 4.0f);
-    AddLine(center, p, color, depthTest);
+    AddLine(center, p, uintColor, depthTest);
 }
 
 void DebugRenderer::AddCross(const Vector3& center, float size, const Color& color, bool depthTest)
 {
+    unsigned uintColor = color.ToUInt();
+
     float halfSize = size / 2.0f;
     for (int i = 0; i < 3; ++i)
     {
@@ -368,20 +371,22 @@ void DebugRenderer::AddCross(const Vector3& center, float size, const Color& col
         float end[3] = { center.x_, center.y_, center.z_ };
         start[i] -= halfSize;
         end[i] += halfSize;
-        AddLine(start, end, color, depthTest);
+        AddLine(start, end, uintColor, depthTest);
     }
 }
 
 void DebugRenderer::AddQuad(const Vector3& center, float width, float height, const Color& color, bool depthTest)
 {
+    unsigned uintColor = color.ToUInt();
+
     Vector3 v0(center.x_ - width / 2, center.y_, center.z_ - height / 2);
     Vector3 v1(center.x_ + width / 2, center.y_, center.z_ - height / 2);
     Vector3 v2(center.x_ + width / 2, center.y_, center.z_ + height / 2);
     Vector3 v3(center.x_ - width / 2, center.y_, center.z_ + height / 2);
-    AddLine(v0, v1, color, depthTest);
-    AddLine(v1, v2, color, depthTest);
-    AddLine(v2, v3, color, depthTest);
-    AddLine(v3, v0, color, depthTest);
+    AddLine(v0, v1, uintColor, depthTest);
+    AddLine(v1, v2, uintColor, depthTest);
+    AddLine(v2, v3, uintColor, depthTest);
+    AddLine(v3, v0, uintColor, depthTest);
 }
 
 void DebugRenderer::Render()

+ 4 - 4
Source/Urho3D/Graphics/DebugRenderer.h

@@ -134,11 +134,11 @@ public:
     void AddTriangleMesh
         (const void* vertexData, unsigned vertexSize, const void* indexData, unsigned indexSize, unsigned indexStart,
             unsigned indexCount, const Matrix3x4& transform, const Color& color, bool depthTest = true);
-    /// Add a circle
-    void AddCirCle(const Vector3& center, const Vector3& normal, float radius, const Color& color, int steps = 64, bool depthTest = true);
-    /// Add a cross
+    /// Add a circle.
+    void AddCircle(const Vector3& center, const Vector3& normal, float radius, const Color& color, int steps = 64, bool depthTest = true);
+    /// Add a cross.
     void AddCross(const Vector3& center, float size, const Color& color, bool depthTest = true);
-    /// Add a quad
+    /// Add a quad on the XZ plane.
     void AddQuad(const Vector3& center, float width, float height, const Color& color, bool depthTest = true);
 
     /// Update vertex buffer and render all debug lines. The viewport and rendertarget should be set before.

+ 1 - 1
Source/Urho3D/LuaScript/pkgs/Graphics/DebugRenderer.pkg

@@ -15,7 +15,7 @@ class DebugRenderer : public Component
     void AddSphere(const Sphere& sphere, const Color& color, bool depthTest = true);
     void AddSkeleton(const Skeleton& skeleton, const Color& color, bool depthTest = true);
     void AddTriangleMesh(const void* vertexData, unsigned vertexSize, const void* indexData, unsigned indexSize, unsigned indexStart, unsigned indexCount, const Matrix3x4& transform, const Color& color, bool depthTest = true);
-    void AddCirCle(const Vector3& center, const Vector3& normal, float radius, const Color& color, int steps = 64, bool depthTest = true);
+    void AddCircle(const Vector3& center, const Vector3& normal, float radius, const Color& color, int steps = 64, bool depthTest = true);
     void AddCross(const Vector3& center, float size, const Color& color, bool depthTest = true);
     void AddQuad(const Vector3& center, float width, float height, const Color& color, bool depthTest = true);
     void Render();

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

@@ -1764,7 +1764,7 @@ static void RegisterDebugRenderer(asIScriptEngine* engine)
     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 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 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);
     engine->RegisterObjectMethod("DebugRenderer", "void AddQuad(const Vector3&in, float, float, const Color&in, bool depthTest = true)", asMETHOD(DebugRenderer, AddQuad), asCALL_THISCALL);
     engine->RegisterObjectMethod("Scene", "DebugRenderer@+ get_debugRenderer() const", asFUNCTION(SceneGetDebugRenderer), asCALL_CDECL_OBJLAST);