bevy_avian_baseball_flight/
lib.rs1mod ball_flight_state;
2mod common;
3mod components;
4mod events;
5mod resources;
6mod systems;
7
8pub mod prelude {
9 pub use super::{
10 components::*, constants::*, events::*, utils::*, BaseballFlightPlugin, GyroPole, Tilt,
11 };
12}
13
14use crate::systems::*;
15
16pub(crate) use crate::resources::*;
17pub(crate) use avian3d::prelude::*;
18pub(crate) use ball_flight_state::*;
19pub(crate) use bevy::{math::*, prelude::*};
20pub(crate) use common::*;
21pub(crate) use constants::*;
22pub(crate) use events::*;
23pub(crate) use utils::*;
24
25pub struct BaseballFlightPlugin {
26 pub ssw_on: bool,
27 pub magnus_on: bool,
28 pub drag_on: bool,
29}
30
31impl Plugin for BaseballFlightPlugin {
32 fn build(&self, app: &mut App) {
33 app.add_event::<ActivateAerodynamicsEvent>();
34 app.add_event::<PostActivateAerodynamicsEvent>();
35 app.add_event::<DisableAerodynamicsEvent>();
36
37 app.register_type::<BaseballFlightState>();
38
39 app.insert_resource(BaseballPluginConfig {
40 ssw_on: self.ssw_on,
41 magnus_on: self.magnus_on,
42 drag_on: self.drag_on,
43 ..default()
44 });
45
46 app.add_systems(FixedUpdate, _apply_physics_option_3);
49
50 app.add_systems(FixedUpdate, activate_aerodynamics);
51 app.add_systems(FixedUpdate, disable_aerodynamics);
52 }
53}
54
55#[derive(Debug, Clone, Copy, Reflect)]
56pub enum GyroPole {
57 Right,
58 Left,
59}
60
61impl Default for GyroPole {
62 fn default() -> Self {
63 Self::Right
64 }
65}
66
67#[derive(Debug, Reflect, Copy, Clone)]
68pub struct Tilt(f32);
69impl Tilt {
70 pub fn from_hour_mintes(h: i8, m: i8) -> Self {
71 assert!(h <= 12 && h > 0);
72 let rad_hrs = (h - 3) as f32 * PI_32 / 6.;
73 let rad_mins = m as f32 * PI_32 / 360.;
74 Self(rad_hrs + rad_mins)
75 }
76
77 pub fn get(&self) -> f32 {
78 self.0
79 }
80}