draw arc by lines instead of arc_2d

This commit is contained in:
nquidox 2026-04-17 16:25:26 +03:00
parent a1180ea769
commit 0c7ceb5d8d

View file

@ -22,13 +22,28 @@ pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
PathSegment::Turn { radius, left } => { PathSegment::Turn { radius, left } => {
// вычисляем нормаль, центр, угол поворота арки и знак // вычисляем нормаль, центр, угол поворота арки и знак
let arc = helper_arc_calculator(current_pos, current_dir, *left, *radius); let arc = helper_arc_calculator(current_pos, current_dir, *left, *radius);
// арки никак не хотели вставать на свои места
// gizmos.arc_2d(
// Isometry2d::new(arc.center, Rot2::degrees(current_angle)),
// FRAC_PI_2 * arc.sweep_sign,
// *radius,
// GREEN,
// );
// поэтому отрисовка поворота через линии
let steps = 16;
let mut prev_point = current_pos;
gizmos.arc_2d( for i in 1..=steps {
Isometry2d::new(arc.center, Rot2::radians(arc.start_angle)), let t = i as f32 / steps as f32;
FRAC_PI_2, let angle = arc.start_angle + arc.sweep_sign * FRAC_PI_2 * t;
*radius, let point = arc.center + Vec2::from_angle(angle) * *radius;
GREEN,
); gizmos.line_2d(prev_point, point, GREEN);
prev_point = point;
}
current_pos = arc.end_pos; current_pos = arc.end_pos;
current_dir = arc.normal; current_dir = arc.normal;
} }
@ -36,4 +51,4 @@ pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
} }
// рисуем финиш // рисуем финиш
gizmos.circle_2d(current_pos, 5.0, Color::WHITE); gizmos.circle_2d(current_pos, 5.0, Color::WHITE);
} }