zuma-like/src/states/linear/components_track.rs

57 lines
No EOL
1.5 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use bevy::prelude::*;
#[derive(Resource)]
pub struct Track {
pub start_point: Vec2,
pub start_direction: Vec2, // будет нормализовано при построении
pub segments: Vec<PathSegment>,
}
#[derive(Debug)]
pub enum SegementType{
Line,
Turn,
}
// линия всегда строится от точки старта по направлению
// направление изменяется сегментами поворота
// left при истине - поворот против часовой стрелки, ложь - по часовой
#[derive(Clone, Copy)]
pub enum PathSegment {
Line { length: f32 },
Turn { radius: f32, left: bool },
// TODO заменить перечисление на структуру с полем типа SegementType, чтоб был единый источник типа
}
#[derive(Resource)]
pub struct PrecalculatedTrack{
pub segments: Vec<PTSegment>,
pub min_spawn_gap: f32, //нормализован
pub total_length: f32,
pub speed_norm: f32,
}
#[derive(Debug)]
pub struct PTSegment {
pub t_start: f32,
pub t_end: f32,
pub segment_type: SegementType,
pub start_pos: Vec2,
pub direction: Vec2,
pub center: Vec2,
pub radius: f32,
pub start_angle: f32,
pub sweep_sign: f32,
pub length: f32,
}
#[derive(Debug, Clone, Copy)]
pub struct ArcCalculation {
pub normal: Vec2,
pub center: Vec2,
pub start_angle: f32,
pub sweep_sign: f32,
pub end_pos: Vec2,
}