57 lines
No EOL
1.5 KiB
Rust
57 lines
No EOL
1.5 KiB
Rust
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,
|
||
} |