Skip to main content

traaains/editor/track/placing/
gizmos.rs

1use bevy::{
2    color::Color,
3    ecs::system::Single,
4    gizmos::gizmos::Gizmos,
5    math::{Isometry2d, Vec2},
6    transform::components::Transform,
7};
8
9use crate::{editor::track::placing::VirtualSegment, shape::Shapes};
10
11fn render_gizmos(coeffs: &[Vec2], virt_s_loc: &Vec2, gizmos: &mut Gizmos) {
12    for i in 0..coeffs.len() - 1 {
13        if i != coeffs.len() - 2 {
14            gizmos.circle_2d(
15                Isometry2d::from_translation(coeffs[i + 1] + *virt_s_loc),
16                4.0,
17                Color::WHITE,
18            );
19        }
20
21        gizmos.line_2d(
22            coeffs[i] + *virt_s_loc,
23            coeffs[i + 1] + *virt_s_loc,
24            Color::WHITE,
25        );
26    }
27}
28
29/// Draws the circle on and lines between control points of curves (quadratic and cubic).
30pub fn draw_virtual_segment_gizmos(
31    v_segment: Single<(&VirtualSegment, &Transform)>,
32    mut gizmos: Gizmos,
33) {
34    let virt_s_loc = v_segment.1.translation.truncate();
35
36    gizmos.circle_2d(
37        Isometry2d::from_translation(v_segment.1.translation.truncate()),
38        0.5,
39        Color::WHITE,
40    );
41
42    match &v_segment.0.shape {
43        Shapes::Quadratic(quadratic) => render_gizmos(&quadratic.coeffs, &virt_s_loc, &mut gizmos),
44        Shapes::Cubic(cubic) => render_gizmos(&cubic.coeffs, &virt_s_loc, &mut gizmos),
45        _ => {}
46    }
47}