use astrodyn::{FrameTransform, GravityModel, GravitySource, Planet, PlanetConfig};
use bevy::prelude::*;
use crate::components::*;
#[derive(Bundle)]
pub struct PlanetBundle<P: Planet> {
pub name: Name,
pub source: GravitySourceC,
pub position: SourceInertialPositionC,
pub trans: TranslationalStateC<P>,
pub rotation: PlanetFixedRotationC<P>,
pub omega: PlanetOmegaC,
pub ang_vel: PlanetAngularVelocityC<P>,
pub rotation_model: RotationModelC,
pub shape: PlanetC,
}
impl<P: Planet> PlanetBundle<P> {
pub fn from_config(name: &str, config: &PlanetConfig, source: GravitySource) -> Self {
Self {
name: Name::new(name.to_string()),
source: GravitySourceC(source),
position: SourceInertialPositionC::default(),
trans: TranslationalStateC::<P>::default(),
rotation: PlanetFixedRotationC::<P>(FrameTransform::from_matrix(glam::DMat3::IDENTITY)),
omega: PlanetOmegaC(config.omega),
ang_vel: PlanetAngularVelocityC::<P>::default(),
rotation_model: RotationModelC(config.rotation_model),
shape: PlanetC(config.shape),
}
}
pub fn point_mass(name: &str, config: &PlanetConfig) -> Self {
Self::from_config(
name,
config,
GravitySource {
mu: config.shape.mu,
model: GravityModel::PointMass,
},
)
}
pub fn point_mass_only(
name: impl Into<Name>,
source: GravitySource,
) -> (
Name,
GravitySourceC,
SourceInertialPositionC,
TranslationalStateC<P>,
) {
(
name.into(),
GravitySourceC(source),
SourceInertialPositionC::default(),
TranslationalStateC::<P>::default(),
)
}
}
#[derive(Bundle)]
pub struct SunBundle<P: Planet> {
pub name: Name,
pub marker: SunMarker,
pub trans: TranslationalStateC<P>,
}
impl<P: Planet> SunBundle<P> {
pub fn new(state: astrodyn::TranslationalState) -> Self {
Self {
name: Name::new("Sun"),
marker: SunMarker,
trans: TranslationalStateC::<P>::from_untyped(state),
}
}
}
#[derive(Bundle)]
pub struct MoonBundle<P: Planet> {
pub name: Name,
pub marker: MoonMarker,
pub trans: TranslationalStateC<P>,
}
impl<P: Planet> MoonBundle<P> {
pub fn new(state: astrodyn::TranslationalState) -> Self {
Self {
name: Name::new("Moon"),
marker: MoonMarker,
trans: TranslationalStateC::<P>::from_untyped(state),
}
}
}