This commit is contained in:
Leon Liu 2025-08-13 21:02:57 +09:00
parent ca2b06efb8
commit ebf470f312
3 changed files with 22 additions and 3 deletions

10
Cargo.lock generated
View File

@ -880,6 +880,15 @@ dependencies = [
"glam",
]
[[package]]
name = "bevy_panorbit_camera"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca6e15e297754d0bcb7665620c390c4f05665d4ac4ac91b4b5d3c66b9fe1f0e6"
dependencies = [
"bevy",
]
[[package]]
name = "bevy_pbr"
version = "0.16.1"
@ -3818,6 +3827,7 @@ name = "solar-sim"
version = "0.1.0"
dependencies = [
"bevy",
"bevy_panorbit_camera",
]
[[package]]

View File

@ -5,6 +5,7 @@ edition = "2024"
[dependencies]
bevy = "0.16"
bevy_panorbit_camera = "0.26"
# Enable a small amount of optimization in the dev profile.
[profile.dev]

View File

@ -1,4 +1,5 @@
use bevy::{math::DVec3, prelude::*};
use bevy_panorbit_camera::{PanOrbitCamera, PanOrbitCameraPlugin};
// Unit wrapper types - all distances in AU
#[derive(Clone, Copy, Debug, PartialEq)]
@ -90,11 +91,17 @@ fn sync_position_to_transform(mut query: Query<(&Position, &mut Transform), Chan
}
fn setup_rendering(mut commands: Commands) {
// Spawn camera positioned to view the solar system
// Place it above and to the side for a good perspective view
// Spawn camera with pan/orbit/zoom controls
// Place it at a good distance to view the solar system
commands.spawn((
Camera3d::default(),
Transform::from_xyz(2.0, 1.5, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
Transform::from_translation(Vec3::new(2.0, 1.5, 2.0)),
PanOrbitCamera {
focus: Vec3::ZERO,
radius: Some(3.0),
is_upside_down: false,
..default()
},
));
// Spawn directional light from the sun's position
@ -163,6 +170,7 @@ fn setup_solar_system(mut commands: Commands) {
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(PanOrbitCameraPlugin)
.add_plugins(SolarRenderingPlugin)
.add_systems(Startup, setup_solar_system)
.run();