Compare commits

..

No commits in common. "3430f377837763b71148ed4085402e6a239ec86e" and "9a1b13b6f9f96474805660dcd9dbf1eafefe7ca2" have entirely different histories.

2 changed files with 22 additions and 36 deletions

View file

@ -1,8 +1,5 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy::input::mouse::MouseScrollUnit; use std::f32::consts::E;
use bevy::input::mouse::MouseWheel;
use std::f32::consts::{E, PI};
use crate::Player; use crate::Player;
use crate::GameState; use crate::GameState;
@ -10,10 +7,10 @@ use crate::ConstellationModel;
use crate::Sky; use crate::Sky;
use crate::MainGame; use crate::MainGame;
use crate::spawn_cons_lines; use crate::spawn_cons_lines;
use crate::CONS_VIEW_RADIUS; use crate::CONS_VIEW_RADIUS;
use crate::MOUSE_SPEED;
#[derive(Component)] #[derive(Component)]
pub struct InfoLabel; pub struct InfoLabel;
@ -108,30 +105,6 @@ pub fn player_mouse_move (
player.dragging_pos = Some(new_cursor); player.dragging_pos = Some(new_cursor);
} }
pub fn zoom(
mut evr_scroll: EventReader<MouseWheel>,
mut projection_query: Query<&mut Projection, With<Player>>,
) {
let Ok(mut projection) = projection_query.get_single_mut() else {
return;
};
let Projection::Perspective(ref mut perspective) = *projection else {
return;
};
for ev in evr_scroll.read() {
match ev.unit {
MouseScrollUnit::Line => {
perspective.fov = (0.6*PI).min((0.02*PI).max(perspective.fov * 0.9_f32.powf(ev.y)));
}
MouseScrollUnit::Pixel => {
println!("Scroll (pixel units): vertical: {}, horizontal: {}", ev.y, ev.x);
}
}
}
}
fn rotate_to_align(ray_1: Ray3d, ray_2: Ray3d) -> Quat { fn rotate_to_align(ray_1: Ray3d, ray_2: Ray3d) -> Quat {
let pos_1 = ray_1.get_point(1.0); let pos_1 = ray_1.get_point(1.0);
let pos_2 = ray_2.get_point(1.0); let pos_2 = ray_2.get_point(1.0);
@ -146,7 +119,7 @@ fn rotate_to_align(ray_1: Ray3d, ray_2: Ray3d) -> Quat {
} }
let dot_product = dir_1.dot(dir_2).clamp(-1.0, 1.0); let dot_product = dir_1.dot(dir_2).clamp(-1.0, 1.0);
let angle_of_rotation = dot_product.acos() * MOUSE_SPEED; let angle_of_rotation = dot_product.acos() * 6.0;
if angle_of_rotation.is_nan() || angle_of_rotation.is_infinite() { if angle_of_rotation.is_nan() || angle_of_rotation.is_infinite() {
return Quat::IDENTITY; return Quat::IDENTITY;

View file

@ -21,7 +21,6 @@ const MAX_STAR_SIZE: f32 = 0.63;
const STAR_SCALE: f32 = 0.02; const STAR_SCALE: f32 = 0.02;
const SKY_RADIUS: f32 = 4.0; const SKY_RADIUS: f32 = 4.0;
const CONS_VIEW_RADIUS: f32 = 0.8; const CONS_VIEW_RADIUS: f32 = 0.8;
const MOUSE_SPEED: f32 = 12.0;
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
struct StarData { struct StarData {
@ -141,8 +140,8 @@ fn main() {
.add_systems(Update, game_state::player_interact.run_if(in_state(GameState::Game))) .add_systems(Update, game_state::player_interact.run_if(in_state(GameState::Game)))
.add_systems(Update, explo_state::player_mouse_move.run_if(in_state(GameState::Game).or_else(in_state(GameState::Explo)))) .add_systems(Update, explo_state::player_mouse_move.run_if(in_state(GameState::Game).or_else(in_state(GameState::Explo))))
.add_systems(Update, explo_state::rotate_camera.run_if(in_state(GameState::Game).or_else(in_state(GameState::Explo)))) .add_systems(Update, explo_state::rotate_camera.run_if(in_state(GameState::Game).or_else(in_state(GameState::Explo))))
.add_systems(Update, explo_state::zoom.run_if(in_state(GameState::Game).or_else(in_state(GameState::Explo))))
.add_systems(Update, game_state::ui_buttons.run_if(in_state(GameState::Game))) .add_systems(Update, game_state::ui_buttons.run_if(in_state(GameState::Game)))
.add_systems(Update, explo_state::constellation_opacity.run_if(in_state(GameState::Game).or_else(in_state(GameState::Explo))))
.add_systems(Update, game_state::ui_labels.run_if(in_state(GameState::Game))) .add_systems(Update, game_state::ui_labels.run_if(in_state(GameState::Game)))
.add_systems(OnExit(GameState::Game), despawn_screen::<MainGame>) .add_systems(OnExit(GameState::Game), despawn_screen::<MainGame>)
.add_systems(OnEnter(GameState::End), end_state::setup) .add_systems(OnEnter(GameState::End), end_state::setup)
@ -150,7 +149,6 @@ fn main() {
.add_systems(OnExit(GameState::End), despawn_screen::<GameOver>) .add_systems(OnExit(GameState::End), despawn_screen::<GameOver>)
.add_systems(OnEnter(GameState::Explo), explo_state::setup) .add_systems(OnEnter(GameState::Explo), explo_state::setup)
.add_systems(Update, explo_state::player_interact.run_if(in_state(GameState::Explo))) .add_systems(Update, explo_state::player_interact.run_if(in_state(GameState::Explo)))
.add_systems(Update, explo_state::constellation_opacity.run_if(in_state(GameState::Explo)))
.add_systems(OnExit(GameState::Explo), despawn_screen::<MainGame>) .add_systems(OnExit(GameState::Explo), despawn_screen::<MainGame>)
.run(); .run();
} }
@ -208,8 +206,7 @@ fn star_setup(
) { ) {
commands.insert_resource(ClearColor(Color::BLACK)); commands.insert_resource(ClearColor(Color::BLACK));
let stars: Vec<StarData> = serde_json::from_str(include_str!("../data/stars.json")).expect("no star json provided"); let stars = get_stars().unwrap();
let star_mesh = meshes.add(Sphere::new(1.0).mesh().ico(3).unwrap()); let star_mesh = meshes.add(Sphere::new(1.0).mesh().ico(3).unwrap());
@ -249,6 +246,14 @@ fn star_setup(
)); ));
} }
fn get_stars() -> std::io::Result<Vec<StarData>> {
let data = include_str!("../data/stars.json");
let stars: Vec<StarData> = serde_json::from_str(&data).unwrap();
Ok(stars)
}
fn star_position(star_data: StarData) -> Vec3 { fn star_position(star_data: StarData) -> Vec3 {
// Convert declination to decimal degrees // Convert declination to decimal degrees
let text_ra = star_data.ra; let text_ra = star_data.ra;
@ -284,7 +289,15 @@ fn celestial_to_cartesian(rah: f64, ded: f64) -> Vec3 {
} }
fn cons_setup(mut sky: ResMut<Sky>) { fn cons_setup(mut sky: ResMut<Sky>) {
sky.content = serde_json::from_str(include_str!("../data/constellations.json")).expect("no constellation json provided"); sky.content = get_cons().unwrap();
}
fn get_cons() -> std::io::Result<Vec<Constellation>> {
let data = include_str!("../data/constellations.json");
let sky_data: Vec<Constellation> = serde_json::from_str(&data).unwrap();
Ok(sky_data)
} }
// Generic system that takes a component as a parameter, and will despawn all entities with that component // Generic system that takes a component as a parameter, and will despawn all entities with that component