constants moved
This commit is contained in:
parent
0f7882d3fb
commit
7b334b33c0
3 changed files with 96 additions and 56 deletions
15
src/states/linear/constants.rs
Normal file
15
src/states/linear/constants.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
use crate::FACTOR;
|
||||||
|
use bevy::color::Color;
|
||||||
|
|
||||||
|
pub const CENTER_X: f32 = 0.0;
|
||||||
|
pub const CENTER_Y: f32 = 0.0;
|
||||||
|
|
||||||
|
// pub const FACTOR_RADIUS: f32 = FACTOR as f32 / 2.0;
|
||||||
|
|
||||||
|
pub const STEP: f32 = FACTOR as f32 / SCALE;
|
||||||
|
pub const SCALE: f32 = 2.0;
|
||||||
|
|
||||||
|
//COLORS
|
||||||
|
pub const PINK: Color = Color::srgb_u8(250, 0, 155);
|
||||||
|
pub const BLUE: Color = Color::srgb_u8(0, 0, 255);
|
||||||
|
pub const GREEN: Color = Color::srgb_u8(0, 255, 0);
|
||||||
|
|
@ -3,10 +3,6 @@ use bevy::prelude::*;
|
||||||
use states::linear::*;
|
use states::linear::*;
|
||||||
use std::f32::consts::FRAC_PI_2;
|
use std::f32::consts::FRAC_PI_2;
|
||||||
|
|
||||||
const PINK: Color = Color::srgb_u8(250, 0, 155);
|
|
||||||
const BLUE: Color = Color::srgb_u8(0, 0, 255);
|
|
||||||
const GREEN: Color = Color::srgb_u8(0, 255, 0);
|
|
||||||
|
|
||||||
pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
|
pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
|
||||||
let mut current_pos = track.start_point;
|
let mut current_pos = track.start_point;
|
||||||
let mut current_dir = track.start_direction.normalize();
|
let mut current_dir = track.start_direction.normalize();
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,8 @@
|
||||||
use std::f32::consts::FRAC_PI_2;
|
use crate::FACTOR;
|
||||||
use crate::states::linear::*;
|
use crate::states::linear::*;
|
||||||
use crate::{FACTOR};
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::reflect::List;
|
use bevy::reflect::List;
|
||||||
|
use std::f32::consts::FRAC_PI_2;
|
||||||
pub const CENTER_X: f32 = 0.0;
|
|
||||||
pub const CENTER_Y: f32 = 0.0;
|
|
||||||
|
|
||||||
// pub const FACTOR_RADIUS: f32 = FACTOR as f32 / 2.0;
|
|
||||||
|
|
||||||
pub const STEP: f32 = FACTOR as f32 / SCALE;
|
|
||||||
pub const SCALE: f32 = 2.0;
|
|
||||||
|
|
||||||
|
|
||||||
pub fn setup_linear_track() -> Track {
|
pub fn setup_linear_track() -> Track {
|
||||||
println!("Построение трека начато");
|
println!("Построение трека начато");
|
||||||
|
|
@ -23,22 +14,55 @@ pub fn setup_linear_track() -> Track {
|
||||||
start_direction: Vec2::X,
|
start_direction: Vec2::X,
|
||||||
segments: vec![
|
segments: vec![
|
||||||
PathSegment::Line { length: STEP * 6.0 },
|
PathSegment::Line { length: STEP * 6.0 },
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
PathSegment::Turn {
|
||||||
|
radius: STEP,
|
||||||
|
left: true,
|
||||||
|
},
|
||||||
PathSegment::Line { length: STEP },
|
PathSegment::Line { length: STEP },
|
||||||
PathSegment::Turn { radius: STEP, left: false },
|
PathSegment::Turn {
|
||||||
PathSegment::Line { length: STEP * 18.0 },
|
radius: STEP,
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
left: false,
|
||||||
|
},
|
||||||
|
PathSegment::Line {
|
||||||
|
length: STEP * 18.0,
|
||||||
|
},
|
||||||
|
PathSegment::Turn {
|
||||||
|
radius: STEP,
|
||||||
|
left: true,
|
||||||
|
},
|
||||||
PathSegment::Line { length: STEP * 4.0 },
|
PathSegment::Line { length: STEP * 4.0 },
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
PathSegment::Turn {
|
||||||
PathSegment::Turn { radius: STEP, left: false },
|
radius: STEP,
|
||||||
|
left: true,
|
||||||
|
},
|
||||||
|
PathSegment::Turn {
|
||||||
|
radius: STEP,
|
||||||
|
left: false,
|
||||||
|
},
|
||||||
PathSegment::Line { length: STEP * 4.0 },
|
PathSegment::Line { length: STEP * 4.0 },
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
PathSegment::Turn {
|
||||||
PathSegment::Line { length: STEP * 20.0 },
|
radius: STEP,
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
left: true,
|
||||||
|
},
|
||||||
|
PathSegment::Line {
|
||||||
|
length: STEP * 20.0,
|
||||||
|
},
|
||||||
|
PathSegment::Turn {
|
||||||
|
radius: STEP,
|
||||||
|
left: true,
|
||||||
|
},
|
||||||
PathSegment::Line { length: STEP * 5.0 },
|
PathSegment::Line { length: STEP * 5.0 },
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
PathSegment::Turn {
|
||||||
PathSegment::Line { length: STEP * 10.0 },
|
radius: STEP,
|
||||||
PathSegment::Turn { radius: STEP, left: false },
|
left: true,
|
||||||
|
},
|
||||||
|
PathSegment::Line {
|
||||||
|
length: STEP * 10.0,
|
||||||
|
},
|
||||||
|
PathSegment::Turn {
|
||||||
|
radius: STEP,
|
||||||
|
left: false,
|
||||||
|
},
|
||||||
PathSegment::Line { length: STEP * 2.0 },
|
PathSegment::Line { length: STEP * 2.0 },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +119,8 @@ pub fn precalculate_track(track: &Track) -> PrecalculatedTrack {
|
||||||
current_pos = arc.end_pos;
|
current_pos = arc.end_pos;
|
||||||
current_dir = arc.normal;
|
current_dir = arc.normal;
|
||||||
// накапливаем длину
|
// накапливаем длину
|
||||||
cumulative_length.push(cumulative_length[cumulative_length.len() -1] + (FRAC_PI_2 * radius));
|
cumulative_length
|
||||||
|
.push(cumulative_length[cumulative_length.len() - 1] + (FRAC_PI_2 * radius));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -128,7 +153,11 @@ pub fn helper_arc_calculator(pos: Vec2, dir: Vec2, turn_to: bool, radius: f32) -
|
||||||
|
|
||||||
let center = pos + normal * radius;
|
let center = pos + normal * radius;
|
||||||
let start_vec = pos - center;
|
let start_vec = pos - center;
|
||||||
let initial_vec = if turn_to { -start_vec.perp() } else { -start_vec };
|
let initial_vec = if turn_to {
|
||||||
|
-start_vec.perp()
|
||||||
|
} else {
|
||||||
|
-start_vec
|
||||||
|
};
|
||||||
let angle = initial_vec.to_angle();
|
let angle = initial_vec.to_angle();
|
||||||
|
|
||||||
ArcCalculation {
|
ArcCalculation {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue