diff --git a/src/flycam.rs b/src/flycam.rs index 8f09b01..8cc43a6 100644 --- a/src/flycam.rs +++ b/src/flycam.rs @@ -61,26 +61,9 @@ fn setup( args: Res, space: Res, ) { - let height_direction = args.starting_position.normalize().as_vec3(); - let (grid, subgrid): (GalacticGrid, _) = space.translation_to_grid(args.starting_position); - - let mut transform = Transform::from_translation(subgrid + height_direction * args.elevation) - // This "hack" rotates the camera-view down and accroding to Lat/Lon - .looking_at(subgrid, Vec3::Z) // ::Z for Nord - ; - - // Todo?: Rotate realy by Lat/Lon - // Bevy Camera default-rotation is: view to -z and up = +y - // OSMeta Earth is Nord = +Z and Greenwich at 0 degrees to -Y? so the default view should be +Y. - // So the initial rotaton needs to be 90 degrees -X ??? - // let mut rotation = Quat::from_axis_angle(Vec3::Y, (-90_f32).to_radians()) - // * Quat::from_axis_angle(Vec3::Z, (-90_f32).to_radians()) - - let rotation = Quat::from_axis_angle(Vec3::Z, args.direction.to_radians()) - * Quat::from_axis_angle(Vec3::X, args.up_view.to_radians()); - transform = transform * Transform::from_rotation(rotation); - - movement_settings.up = height_direction; + // set up accroding to lat/lon relative to Earth center + movement_settings.up = args.starting_position.normalize().as_vec3(); + let (grid, _): (GalacticGrid, _) = space.translation_to_grid(args.starting_position); let material = materials.add(StandardMaterial { base_color_texture: Some(images.add(uv_debug_texture())), @@ -103,10 +86,7 @@ fn setup( .id(); let mut camera = commands.spawn(( - Camera3dBundle { - transform, - ..default() - }, + Camera3dBundle { ..default() }, InheritedVisibility::default(), FlyCam, grid, diff --git a/src/geoview.rs b/src/geoview.rs index 2966c6a..da59deb 100644 --- a/src/geoview.rs +++ b/src/geoview.rs @@ -156,6 +156,13 @@ impl GeoView { } } +fn keys_ui_setup(mut player: Player, mut views: ResMut, space: Res) { + let start_view = GeoView::restore(("Key0").to_string(), &mut views.map); + if let Some(start_view) = start_view { + start_view.set_camera_view(&space, &mut player); + } +} + // System: If keys pressed, store and restore camera views fn keys_ui( keys: Res>, @@ -214,6 +221,7 @@ impl bevy::prelude::Plugin for Plugin { self.start_view.store("Key0".to_string(), &mut map); //lf.start_view.set_camera_view(&space, &mut player); app.insert_resource(Views { map }); + app.add_systems(PostStartup, keys_ui_setup); } } diff --git a/src/lib.rs b/src/lib.rs index 938e22d..fa60235 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,9 +48,6 @@ type GalacticTransformItem<'a> = GridTransformItem<'a, GridPrecision>; #[derive(Resource)] struct Args { starting_position: PlanetaryPosition, - elevation: f32, - direction: f32, - up_view: f32, xr: bool, } @@ -77,14 +74,14 @@ pub fn main() { } let mut geo_coord = GeoCoord { - lat: 0., //48.1408, // Germany, Munic, Main railway station - lon: 0., //11.5577, + lat: 48.1408, // Germany, Munic, Main railway station + lon: 11.5577, }; - let mut elevation: f32 = 5000000.; //300.0; // Camare hight about ground + let mut elevation: f32 = 300.0; // Camare hight about ground 5000000.; // // GeoView to city center, Marienplatz - let mut direction: f32 = 0.; //(-105.0_f32); // Compass view-direction to Oeast-Southeast. 0 = Nord, -90 = East Todo: Why minus? - let mut up_view: f32 = 0.; //(75.0_f32); // Up-view slightly down. -90 = down, 0 = horizontal 90 = Up + let mut direction: f32 = -105.0; // Compass view-direction to Oeast-Southeast. 0 = Nord, -90 = East Todo: Why minus? + let mut up_view: f32 = 75.0; // Up-view slightly down. -90 = down, 0 = horizontal 90 = Up let mut xr = false; @@ -106,9 +103,6 @@ pub fn main() { let mut app = App::new(); app.insert_resource(Args { starting_position: geo_coord.to_cartesian(), - elevation, - direction, - up_view, xr, });