Prechádzať zdrojové kódy

Merge pull request #56912 from AnilBK/circle-fix

Circle&CapsuleShape2D: Fix outlines missing line.
Rémi Verschelde 3 rokov pred
rodič
commit
02f3e3346a

+ 2 - 4
scene/resources/capsule_shape_2d.cpp

@@ -84,13 +84,11 @@ real_t CapsuleShape2D::get_height() const {
 
 
 void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) {
 void CapsuleShape2D::draw(const RID &p_to_rid, const Color &p_color) {
 	Vector<Vector2> points = _get_points();
 	Vector<Vector2> points = _get_points();
-	Vector<Color> col;
-	col.push_back(p_color);
+	Vector<Color> col = { p_color };
 	RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col);
 	RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col);
 	if (is_collision_outline_enabled()) {
 	if (is_collision_outline_enabled()) {
+		points.push_back(points[0]);
 		RenderingServer::get_singleton()->canvas_item_add_polyline(p_to_rid, points, col);
 		RenderingServer::get_singleton()->canvas_item_add_polyline(p_to_rid, points, col);
-		// Draw the last segment as it's not drawn by `canvas_item_add_polyline()`.
-		RenderingServer::get_singleton()->canvas_item_add_line(p_to_rid, points[points.size() - 1], points[0], p_color);
 	}
 	}
 }
 }
 
 

+ 6 - 5
scene/resources/circle_shape_2d.cpp

@@ -71,18 +71,19 @@ real_t CircleShape2D::get_enclosing_radius() const {
 
 
 void CircleShape2D::draw(const RID &p_to_rid, const Color &p_color) {
 void CircleShape2D::draw(const RID &p_to_rid, const Color &p_color) {
 	Vector<Vector2> points;
 	Vector<Vector2> points;
+	points.resize(24);
+
 	const real_t turn_step = Math_TAU / 24.0;
 	const real_t turn_step = Math_TAU / 24.0;
 	for (int i = 0; i < 24; i++) {
 	for (int i = 0; i < 24; i++) {
-		points.push_back(Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * get_radius());
+		points.write[i] = Vector2(Math::cos(i * turn_step), Math::sin(i * turn_step)) * get_radius();
 	}
 	}
 
 
-	Vector<Color> col;
-	col.push_back(p_color);
+	Vector<Color> col = { p_color };
 	RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col);
 	RenderingServer::get_singleton()->canvas_item_add_polygon(p_to_rid, points, col);
+
 	if (is_collision_outline_enabled()) {
 	if (is_collision_outline_enabled()) {
+		points.push_back(points[0]);
 		RenderingServer::get_singleton()->canvas_item_add_polyline(p_to_rid, points, col);
 		RenderingServer::get_singleton()->canvas_item_add_polyline(p_to_rid, points, col);
-		// Draw the last segment as it's not drawn by `canvas_item_add_polyline()`.
-		RenderingServer::get_singleton()->canvas_item_add_line(p_to_rid, points[points.size() - 1], points[0], p_color);
 	}
 	}
 }
 }