Daniele Bartolini vor 10 Jahren
Ursprung
Commit
bcc23e95ce
2 geänderte Dateien mit 23 neuen und 8 gelöschten Zeilen
  1. 17 5
      src/lua/lua_api.cpp
  2. 6 3
      src/renderers/debug_line.h

+ 17 - 5
src/lua/lua_api.cpp

@@ -2388,15 +2388,21 @@ static int debug_line_add_line(lua_State* L)
 static int debug_line_add_axes(lua_State* L)
 {
 	LuaStack stack(L);
-	const float length = stack.num_args() == 3 ? stack.get_float(3) : 1.0f;
-	stack.get_debug_line(1)->add_axes(stack.get_matrix4x4(2), length);
+	const float len = stack.num_args() == 3
+		? stack.get_float(3)
+		: 1.0f
+		;
+	stack.get_debug_line(1)->add_axes(stack.get_matrix4x4(2), len);
 	return 0;
 }
 
 static int debug_line_add_circle(lua_State* L)
 {
 	LuaStack stack(L);
-	const uint32_t segments = stack.num_args() >= 6 ? stack.get_int(6) : 36;
+	const uint32_t segments = stack.num_args() >= 6
+		? stack.get_int(6)
+		: DebugLine::NUM_SEGMENTS
+		;
 	stack.get_debug_line(1)->add_circle(stack.get_vector3(2)
 		, stack.get_float(3)
 		, stack.get_vector3(4)
@@ -2409,7 +2415,10 @@ static int debug_line_add_circle(lua_State* L)
 static int debug_line_add_cone(lua_State* L)
 {
 	LuaStack stack(L);
-	const uint32_t segments = stack.num_args() >= 6 ? stack.get_int(6) : 36;
+	const uint32_t segments = stack.num_args() >= 6
+		? stack.get_int(6)
+		: DebugLine::NUM_SEGMENTS
+		;
 	stack.get_debug_line(1)->add_cone(stack.get_vector3(2)
 		, stack.get_vector3(3)
 		, stack.get_float(4)
@@ -2422,7 +2431,10 @@ static int debug_line_add_cone(lua_State* L)
 static int debug_line_add_sphere(lua_State* L)
 {
 	LuaStack stack(L);
-	const uint32_t segments = stack.num_args() >= 5 ? stack.get_int(5) : 36;
+	const uint32_t segments = stack.num_args() >= 5
+		? stack.get_int(5)
+		: DebugLine::NUM_SEGMENTS
+		;
 	stack.get_debug_line(1)->add_sphere(stack.get_vector3(2)
 		, stack.get_float(3)
 		, stack.get_color4(4)

+ 6 - 3
src/renderers/debug_line.h

@@ -30,13 +30,13 @@ struct DebugLine
 	void add_axes(const Matrix4x4& m, float length = 1.0f);
 
 	/// Adds a circle at @a center with the given @a radius and @a normal vector.
-	void add_circle(const Vector3& center, float radius, const Vector3& normal, const Color4& color, uint32_t segments = 36);
+	void add_circle(const Vector3& center, float radius, const Vector3& normal, const Color4& color, uint32_t segments = NUM_SEGMENTS);
 
 	/// Adds a cone with the base centered at @a from and the tip at @a to.
-	void add_cone(const Vector3& from, const Vector3& to, float radius, const Color4& color, uint32_t segments = 36);
+	void add_cone(const Vector3& from, const Vector3& to, float radius, const Color4& color, uint32_t segments = NUM_SEGMENTS);
 
 	/// Adds a sphere at @a center with the given @a radius and @a color.
-	void add_sphere(const Vector3& center, const float radius, const Color4& color, uint32_t segments = 36);
+	void add_sphere(const Vector3& center, const float radius, const Color4& color, uint32_t segments = NUM_SEGMENTS);
 
 	/// Adds an orientd bounding box. @a tm describes the position and orientation of
 	/// the box. @a half_extents describes the size of the box along the axis.
@@ -48,6 +48,9 @@ struct DebugLine
 	/// Submits the lines to renderer for drawing.
 	void submit();
 
+	/// Default number of segments.
+	static const uint32_t NUM_SEGMENTS = 36;
+
 public:
 
 	enum { MARKER = 0xd7c17715 };