Explorar o código

Fix DebugLine color

Daniele Bartolini %!s(int64=11) %!d(string=hai) anos
pai
achega
191adaee80

+ 3 - 3
engine/lua/lua_debug_line.cpp

@@ -36,21 +36,21 @@ namespace crown
 static int debug_line_add_line(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.get_debug_line(1)->add_line(Color4::RED, stack.get_vector3(2), stack.get_vector3(3));
+	stack.get_debug_line(1)->add_line(stack.get_vector3(2), stack.get_vector3(3), stack.get_color4(4));
 	return 0;
 }
 
 static int debug_line_add_sphere(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.get_debug_line(1)->add_sphere(Color4::RED, stack.get_vector3(2), stack.get_float(3));
+	stack.get_debug_line(1)->add_sphere(stack.get_vector3(2), stack.get_float(3), stack.get_color4(4));
 	return 0;
 }
 
 static int debug_line_add_obb(lua_State* L)
 {
 	LuaStack stack(L);
-	stack.get_debug_line(1)->add_obb(Color4::RED, stack.get_matrix4x4(2), stack.get_vector3(3));
+	stack.get_debug_line(1)->add_obb(stack.get_matrix4x4(2), stack.get_vector3(3), stack.get_color4(4));
 	return 0;
 }
 

+ 3 - 2
engine/physics/physics_world.cpp

@@ -223,8 +223,9 @@ namespace physics_globals
 			for(PxU32 i = 0; i < rb.getNbLines(); i++)
 			{
 				const PxDebugLine& pxline = rb.getLines()[i];
-				line.add_line(Color4(pxline.color0), Vector3(pxline.pos0.x, pxline.pos0.y, pxline.pos0.z),
-								Vector3(pxline.pos1.x, pxline.pos1.y, pxline.pos1.z));
+				line.add_line(Vector3(pxline.pos0.x, pxline.pos0.y, pxline.pos0.z),
+								Vector3(pxline.pos1.x, pxline.pos1.y, pxline.pos1.z),
+								Color4(pxline.color0));
 			}
 
 			line.commit();

+ 37 - 37
engine/renderers/debug_line.cpp

@@ -146,30 +146,30 @@ namespace debug_line
 } // namespace debug_line
 
 DebugLine::DebugLine(bool depth_test)
-	: m_depth_test(depth_test)
-	, m_num_lines(0)
+	: _depth_test(depth_test)
+	, _num(0)
 {
 }
 
-void DebugLine::add_line(const Color4& color, const Vector3& start, const Vector3& end)
+void DebugLine::add_line(const Vector3& start, const Vector3& end, const Color4& color)
 {
-	if (m_num_lines >= CE_MAX_DEBUG_LINES)
+	if (_num >= CE_MAX_DEBUG_LINES)
 		 return;
 
-	m_lines[m_num_lines].p0[0] = start.x;
-	m_lines[m_num_lines].p0[1] = start.y;
-	m_lines[m_num_lines].p0[2] = start.z;
-	m_lines[m_num_lines].c0    = color4::to_abgr(color);
+	_lines[_num].p0[0] = start.x;
+	_lines[_num].p0[1] = start.y;
+	_lines[_num].p0[2] = start.z;
+	_lines[_num].c0    = color4::to_abgr(color);
 
-	m_lines[m_num_lines].p1[0] = end.x;
-	m_lines[m_num_lines].p1[1] = end.y;
-	m_lines[m_num_lines].p1[2] = end.z;
-	m_lines[m_num_lines].c1    = color4::to_abgr(color);
+	_lines[_num].p1[0] = end.x;
+	_lines[_num].p1[1] = end.y;
+	_lines[_num].p1[2] = end.z;
+	_lines[_num].c1    = color4::to_abgr(color);
 
-	m_num_lines++;
+	_num++;
 }
 
-void DebugLine::add_sphere(const Color4& color, const Vector3& center, const float radius)
+void DebugLine::add_sphere(const Vector3& center, const float radius, const Color4& color)
 {
 	const uint32_t deg_step = 15;
 
@@ -181,21 +181,21 @@ void DebugLine::add_sphere(const Color4& color, const Vector3& center, const flo
 		// XZ plane
 		const Vector3 start0(math::cos(rad0) * radius, 0, -math::sin(rad0) * radius);
 		const Vector3 end0  (math::cos(rad1) * radius, 0, -math::sin(rad1) * radius);
-		add_line(color, center + start0, center + end0);
+		add_line(center + start0, center + end0, color);
 
 		// XY plane
 		const Vector3 start1(math::cos(rad0) * radius, math::sin(rad0) * radius, 0);
 		const Vector3 end1  (math::cos(rad1) * radius, math::sin(rad1) * radius, 0);
-		add_line(color, center + start1, center + end1);
+		add_line(center + start1, center + end1, color);
 
 		// YZ plane
 		const Vector3 start2(0, math::sin(rad0) * radius, -math::cos(rad0) * radius);
 		const Vector3 end2  (0, math::sin(rad1) * radius, -math::cos(rad1) * radius);
-		add_line(color, center + start2, center + end2);
+		add_line(center + start2, center + end2, color);
 	}
 }
 
-void DebugLine::add_obb(const Color4& color, const Matrix4x4& tm, const Vector3& extents)
+void DebugLine::add_obb(const Matrix4x4& tm, const Vector3& extents, const Color4& color)
 {
 	const Vector3 o = Vector3(tm.t.x, tm.t.y, tm.t.z);
 	const Vector3 x = Vector3(tm.x.x, tm.x.y, tm.x.z) * (extents.x * 0.5);
@@ -203,46 +203,46 @@ void DebugLine::add_obb(const Color4& color, const Matrix4x4& tm, const Vector3&
 	const Vector3 z = Vector3(tm.z.x, tm.z.y, tm.z.z) * (extents.z * 0.5);
 
 	// Back face
-	add_line(color, o - x - y - z, o + x - y - z);
-	add_line(color, o + x - y - z, o + x + y - z);
-	add_line(color, o + x + y - z, o - x + y - z);
-	add_line(color, o - x + y - z, o - x - y - z);
-
-	add_line(color, o - x - y + z, o + x - y + z);
-	add_line(color, o + x - y + z, o + x + y + z);
-	add_line(color, o + x + y + z, o - x + y + z);
-	add_line(color, o - x + y + z, o - x - y + z);
-
-	add_line(color, o - x - y - z, o - x - y + z);
-	add_line(color, o + x - y - z, o + x - y + z);
-	add_line(color, o + x + y - z, o + x + y + z);
-	add_line(color, o - x + y - z, o - x + y + z);
+	add_line(o - x - y - z, o + x - y - z, color);
+	add_line(o + x - y - z, o + x + y - z, color);
+	add_line(o + x + y - z, o - x + y - z, color);
+	add_line(o - x + y - z, o - x - y - z, color);
+
+	add_line(o - x - y + z, o + x - y + z, color);
+	add_line(o + x - y + z, o + x + y + z, color);
+	add_line(o + x + y + z, o - x + y + z, color);
+	add_line(o - x + y + z, o - x - y + z, color);
+
+	add_line(o - x - y - z, o - x - y + z, color);
+	add_line(o + x - y - z, o + x - y + z, color);
+	add_line(o + x + y - z, o + x + y + z, color);
+	add_line(o - x + y - z, o - x + y + z, color);
 }
 
 void DebugLine::clear()
 {
-	m_num_lines = 0;
+	_num = 0;
 }
 
 void DebugLine::commit()
 {
-	if (!m_num_lines)
+	if (!_num)
 		return;
 
 	bgfx::TransientVertexBuffer tvb;
 	bgfx::allocTransientVertexBuffer(&tvb, CE_MAX_DEBUG_LINES * 2, debug_line::s_decl);
 
-	memcpy(tvb.data, m_lines, sizeof(Line) * m_num_lines);
+	memcpy(tvb.data, _lines, sizeof(Line) * _num);
 
 	bgfx::setState(BGFX_STATE_PT_LINES
 		| BGFX_STATE_RGB_WRITE
 		| BGFX_STATE_DEPTH_WRITE
-		| (m_depth_test ? BGFX_STATE_DEPTH_TEST_LESS
+		| (_depth_test ? BGFX_STATE_DEPTH_TEST_LESS
 			: BGFX_STATE_DEPTH_TEST_ALWAYS)
 		| BGFX_STATE_CULL_CW);
 
 	bgfx::setProgram(debug_line::s_prog);
-	bgfx::setVertexBuffer(&tvb, 0, m_num_lines * 2);
+	bgfx::setVertexBuffer(&tvb, 0, _num * 2);
 	bgfx::submit(0);
 }
 

+ 6 - 6
engine/renderers/debug_line.h

@@ -47,14 +47,14 @@ struct DebugLine
 	DebugLine(bool depth_test);
 
 	/// Adds a line from @a start to @a end with the given @a color.
-	void add_line(const Color4& color, const Vector3& start, const Vector3& end);
+	void add_line(const Vector3& start, const Vector3& end, const Color4& color);
 
 	/// Adds a sphere at @a center with the given @a radius and @a color.
-	void add_sphere(const Color4& color, const Vector3& center, const float radius);
+	void add_sphere(const Vector3& center, const float radius, const Color4& color);
 
 	/// Adds an orientd bounding box. @a tm describes the position and orientation of
 	/// the box. @a extents describes the size of the box along the axis.
-	void add_obb(const Color4& color, const Matrix4x4& tm, const Vector3& extents);
+	void add_obb(const Matrix4x4& tm, const Vector3& extents, const Color4& color);
 
 	/// Clears all the lines.
 	void clear();
@@ -72,9 +72,9 @@ private:
 		uint32_t c1;
 	};
 
-	bool m_depth_test;
-	uint32_t m_num_lines;
-	Line m_lines[CE_MAX_DEBUG_LINES];
+	bool _depth_test;
+	uint32_t _num;
+	Line _lines[CE_MAX_DEBUG_LINES];
 };
 
 } // namespace crown