Pārlūkot izejas kodu

Add DebugLine::add_mesh()

Daniele Bartolini 10 gadi atpakaļ
vecāks
revīzija
d0c4c9580e
2 mainītis faili ar 37 papildinājumiem un 18 dzēšanām
  1. 18 0
      src/world/debug_line.cpp
  2. 19 18
      src/world/debug_line.h

+ 18 - 0
src/world/debug_line.cpp

@@ -136,6 +136,24 @@ void DebugLine::add_obb(const Matrix4x4& tm, const Vector3& half_extents, const
 	add_line(o - x + y - z, o - x + y + z, color);
 }
 
+void DebugLine::add_mesh(const Matrix4x4& tm, const void* vertices, u32 stride, const u16* indices, u32 num, const Color4& color)
+{
+	for (u32 i = 0; i < num; ++i)
+	{
+		const u32 i0 = indices[i + 0];
+		const u32 i1 = indices[i + 1];
+		const u32 i2 = indices[i + 2];
+
+		const Vector3& v0 = *(const Vector3*)((const char*)vertices + i0*stride) * tm;
+		const Vector3& v1 = *(const Vector3*)((const char*)vertices + i1*stride) * tm;
+		const Vector3& v2 = *(const Vector3*)((const char*)vertices + i2*stride) * tm;
+
+		add_line(v0, v1, color);
+		add_line(v1, v2, color);
+		add_line(v2, v0, color);
+	}
+}
+
 void DebugLine::reset()
 {
 	_num = 0;

+ 19 - 18
src/world/debug_line.h

@@ -18,6 +18,22 @@ namespace crown
 /// @ingroup World
 struct DebugLine
 {
+	struct Line
+	{
+		Vector3 p0;
+		u32 c0;
+		Vector3 p1;
+		u32 c1;
+	};
+
+	u32 _marker;
+
+	StringId32 _shader;
+	bgfx::VertexDecl _vertex_decl;
+
+	u32 _num;
+	Line _lines[CROWN_MAX_DEBUG_LINES];
+
 	/// Whether to enable @a depth_test
 	DebugLine(bool depth_test);
 	~DebugLine();
@@ -41,6 +57,9 @@ struct DebugLine
 	/// the box. @a half_extents describes the size of the box along the axis.
 	void add_obb(const Matrix4x4& tm, const Vector3& half_extents, const Color4& color);
 
+	/// Adds the mesh described by (vertices, stride, indices, num).
+	void add_mesh(const Matrix4x4& tm, const void* vertices, u32 stride, const u16* indices, u32 num, const Color4& color);
+
 	/// Resets all the lines.
 	void reset();
 
@@ -50,24 +69,6 @@ struct DebugLine
 	/// Default number of segments.
 	static const u32 NUM_SEGMENTS = 36;
 	static const u32 MARKER = 0xd7c17715;
-
-private:
-
-	struct Line
-	{
-		Vector3 p0;
-		u32 c0;
-		Vector3 p1;
-		u32 c1;
-	};
-
-	u32 _marker;
-
-	StringId32 _shader;
-	bgfx::VertexDecl _vertex_decl;
-
-	u32 _num;
-	Line _lines[CROWN_MAX_DEBUG_LINES];
 };
 
 } // namespace crown