From ebf470f312bd4f606544d5fe5581fc1ae09a7d96 Mon Sep 17 00:00:00 2001 From: Leon Liu Date: Wed, 13 Aug 2025 21:02:57 +0900 Subject: [PATCH] update --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + src/main.rs | 14 +++++++++++--- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 839406c..031d50a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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]] diff --git a/Cargo.toml b/Cargo.toml index edda80a..a3cf847 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/src/main.rs b/src/main.rs index 0ee0737..284940a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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();