mirror of
https://github.com/Noratrieb/spaceship.git
synced 2026-01-14 16:35:08 +01:00
spheres
This commit is contained in:
parent
a8855a216b
commit
cefbca4400
3 changed files with 48 additions and 16 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
|
@ -2602,14 +2602,6 @@ dependencies = [
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "orbital"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = "git+https://github.com/oli-obk/solar_sailors.git?rev=2fabdd044f0f362595494dcad5102c50ae9572f7#2fabdd044f0f362595494dcad5102c50ae9572f7"
|
|
||||||
dependencies = [
|
|
||||||
"tracing",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "overload"
|
name = "overload"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
|
|
@ -3071,7 +3063,6 @@ dependencies = [
|
||||||
"bevy",
|
"bevy",
|
||||||
"bevy_rapier3d",
|
"bevy_rapier3d",
|
||||||
"glam",
|
"glam",
|
||||||
"orbital",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,3 @@ bevy_rapier3d = { version = "0.22.0", features = [
|
||||||
"debug-render-3d",
|
"debug-render-3d",
|
||||||
] }
|
] }
|
||||||
glam = { version = "0.24.1", features = ["debug-glam-assert"] }
|
glam = { version = "0.24.1", features = ["debug-glam-assert"] }
|
||||||
orbital = { git = "https://github.com/oli-obk/solar_sailors.git", rev = "2fabdd044f0f362595494dcad5102c50ae9572f7" }
|
|
||||||
|
|
|
||||||
54
src/main.rs
54
src/main.rs
|
|
@ -69,6 +69,8 @@ struct OrbitCamera {
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct ThrusterSound;
|
struct ThrusterSound;
|
||||||
|
|
||||||
|
const AMOUNT_OF_FUNNY_ORBIT_SPHERES: u32 = 1000;
|
||||||
|
|
||||||
fn fire_thrusters(
|
fn fire_thrusters(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
keyboard_input: Res<Input<KeyCode>>,
|
keyboard_input: Res<Input<KeyCode>>,
|
||||||
|
|
@ -148,7 +150,7 @@ fn apply_gravity(
|
||||||
.translation
|
.translation
|
||||||
.distance(body_transform.translation) as f64;
|
.distance(body_transform.translation) as f64;
|
||||||
|
|
||||||
let fg = (orbit::G * (gravity.mass as f64)) / (distance * distance);
|
let fg = (orbit::G * gravity.mass) / (distance * distance);
|
||||||
let direction = (body_transform.translation - ship_transform.translation).normalize();
|
let direction = (body_transform.translation - ship_transform.translation).normalize();
|
||||||
|
|
||||||
let fg = ExternalForce {
|
let fg = ExternalForce {
|
||||||
|
|
@ -168,6 +170,15 @@ fn debug_spaceship_orbit(
|
||||||
body_query: Query<(&Transform, &GravityAttractor), Without<Spaceship>>,
|
body_query: Query<(&Transform, &GravityAttractor), Without<Spaceship>>,
|
||||||
mut text_query: Query<&mut Text, With<OrbitText>>,
|
mut text_query: Query<&mut Text, With<OrbitText>>,
|
||||||
mut gizmos: Gizmos,
|
mut gizmos: Gizmos,
|
||||||
|
mut query_sphere: Query<
|
||||||
|
&mut Transform,
|
||||||
|
(
|
||||||
|
With<FunnyOrbitalSphere>,
|
||||||
|
Without<OrbitText>,
|
||||||
|
Without<Spaceship>,
|
||||||
|
Without<GravityAttractor>,
|
||||||
|
),
|
||||||
|
>,
|
||||||
) {
|
) {
|
||||||
let mut text = text_query.single_mut();
|
let mut text = text_query.single_mut();
|
||||||
let (ship_transform, &v) = query.single();
|
let (ship_transform, &v) = query.single();
|
||||||
|
|
@ -204,7 +215,7 @@ fn debug_spaceship_orbit(
|
||||||
);
|
);
|
||||||
|
|
||||||
let orbit = orbit::Orbit::from_pos_dir(
|
let orbit = orbit::Orbit::from_pos_dir(
|
||||||
body_gravity.mass.into(),
|
body_gravity.mass,
|
||||||
DVec2::new(rotated_pos.x.into(), rotated_pos.z.into()),
|
DVec2::new(rotated_pos.x.into(), rotated_pos.z.into()),
|
||||||
DVec2::new(rotated_vel.x.into(), rotated_vel.z.into()),
|
DVec2::new(rotated_vel.x.into(), rotated_vel.z.into()),
|
||||||
);
|
);
|
||||||
|
|
@ -216,6 +227,17 @@ fn debug_spaceship_orbit(
|
||||||
gizmos.ray_gradient(ship_pos, translation, Color::BLUE, Color::GREEN);
|
gizmos.ray_gradient(ship_pos, translation, Color::BLUE, Color::GREEN);
|
||||||
|
|
||||||
gizmos.line(body_transform.translation, ship_pos, Color::WHITE);
|
gizmos.line(body_transform.translation, ship_pos, Color::WHITE);
|
||||||
|
|
||||||
|
let base_pos = body_pos;
|
||||||
|
let distance = (orbit.semi_major_axis as f32) * 2.0;
|
||||||
|
for (i, mut sphere) in query_sphere.iter_mut().enumerate() {
|
||||||
|
let angle = std::f32::consts::TAU / (AMOUNT_OF_FUNNY_ORBIT_SPHERES as f32) * (i as f32);
|
||||||
|
|
||||||
|
let pos = Vec3::new(angle.cos(), 0.0, angle.sin()) * distance;
|
||||||
|
let rotated = base_pos + -orbital_plane_rot * (pos - base_pos);
|
||||||
|
|
||||||
|
sphere.translation = base_pos + rotated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// adapted from https://bevy-cheatbook.github.io/cookbook/pan-orbit-camera.html
|
// adapted from https://bevy-cheatbook.github.io/cookbook/pan-orbit-camera.html
|
||||||
|
|
@ -252,6 +274,9 @@ fn orbit_camera(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct FunnyOrbitalSphere;
|
||||||
|
|
||||||
/// set up a simple 3D scene
|
/// set up a simple 3D scene
|
||||||
fn setup(
|
fn setup(
|
||||||
// mut windows: Query<&mut Window>,
|
// mut windows: Query<&mut Window>,
|
||||||
|
|
@ -260,10 +285,11 @@ fn setup(
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
asset_server: Res<AssetServer>,
|
asset_server: Res<AssetServer>,
|
||||||
) {
|
) {
|
||||||
let mut rapier = RapierConfiguration::default();
|
|
||||||
// We ain't a normal game, we do our own gravity.
|
// We ain't a normal game, we do our own gravity.
|
||||||
rapier.gravity = Vec3::new(0.0, 0.0, 0.0);
|
commands.insert_resource(RapierConfiguration {
|
||||||
commands.insert_resource(rapier);
|
gravity: Vec3::ZERO,
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
|
||||||
commands.spawn(PlanetBundle::new(
|
commands.spawn(PlanetBundle::new(
|
||||||
&mut meshes,
|
&mut meshes,
|
||||||
|
|
@ -279,6 +305,22 @@ fn setup(
|
||||||
Vec3::new(0.0, 100.0, 0.0),
|
Vec3::new(0.0, 100.0, 0.0),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
for _ in 0..AMOUNT_OF_FUNNY_ORBIT_SPHERES {
|
||||||
|
commands.spawn((
|
||||||
|
FunnyOrbitalSphere,
|
||||||
|
PbrBundle {
|
||||||
|
mesh: meshes.add(
|
||||||
|
shape::UVSphere {
|
||||||
|
radius: 100.0,
|
||||||
|
..default()
|
||||||
|
}
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// light
|
// light
|
||||||
commands.insert_resource(AmbientLight {
|
commands.insert_resource(AmbientLight {
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
|
|
@ -423,7 +465,7 @@ impl PlanetBundle {
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
),
|
),
|
||||||
material: material,
|
material,
|
||||||
transform: position,
|
transform: position,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue