Compare commits
No commits in common. "c0103ec2475b7359ece2ddddcccb65af0ead6e60" and "3430f377837763b71148ed4085402e6a239ec86e" have entirely different histories.
c0103ec247
...
3430f37783
|
@ -13,8 +13,7 @@ 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::MOVE_SPEED;
|
use crate::MOUSE_SPEED;
|
||||||
use crate::ROT_SPEED;
|
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct InfoLabel;
|
pub struct InfoLabel;
|
||||||
|
@ -76,7 +75,7 @@ pub fn player_mouse_move (
|
||||||
let local_transform = &global_transform.compute_transform();
|
let local_transform = &global_transform.compute_transform();
|
||||||
|
|
||||||
if !buttons.pressed(MouseButton::Left) {
|
if !buttons.pressed(MouseButton::Left) {
|
||||||
player.l_drag_pos = None;
|
player.dragging_pos = None;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +85,8 @@ pub fn player_mouse_move (
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(old_cursor) = player.l_drag_pos else {
|
let Some(old_cursor) = player.dragging_pos else {
|
||||||
player.l_drag_pos = Some(new_cursor);
|
player.dragging_pos = Some(new_cursor);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -106,69 +105,7 @@ pub fn player_mouse_move (
|
||||||
let delta_rotation = rotate_to_align(new_ray, old_ray);
|
let delta_rotation = rotate_to_align(new_ray, old_ray);
|
||||||
|
|
||||||
player.target_rotation = Some(delta_rotation * local_transform.rotation );
|
player.target_rotation = Some(delta_rotation * local_transform.rotation );
|
||||||
player.l_drag_pos = Some(new_cursor);
|
player.dragging_pos = Some(new_cursor);
|
||||||
}
|
|
||||||
|
|
||||||
pub fn player_mouse_rotate (
|
|
||||||
buttons: Res<ButtonInput<MouseButton>>,
|
|
||||||
mut player_query: Query<(&mut Player, &mut GlobalTransform)>,
|
|
||||||
window_query: Query<&Window, With<bevy::window::PrimaryWindow>>,
|
|
||||||
ui_query: Query<&Interaction, With<Button>>,
|
|
||||||
) {
|
|
||||||
for interaction in ui_query.iter() {
|
|
||||||
if *interaction == Interaction::Pressed {
|
|
||||||
// Button clicked
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let Ok((mut player, global_transform)) = player_query.get_single_mut() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
let local_transform = &global_transform.compute_transform();
|
|
||||||
|
|
||||||
if !buttons.pressed(MouseButton::Right) {
|
|
||||||
player.r_drag_pos = None;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let window = window_query.single();
|
|
||||||
|
|
||||||
let Some(new_cursor) = window.cursor_position() else {
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
let Some(old_cursor) = player.r_drag_pos else {
|
|
||||||
player.r_drag_pos = Some(new_cursor);
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if old_cursor.distance(new_cursor) < 1.0 {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let center = Vec2::new(window.width()/2.0, window.height()/2.0);
|
|
||||||
|
|
||||||
let old_vec = old_cursor - center;
|
|
||||||
let new_vec = new_cursor - center;
|
|
||||||
|
|
||||||
if new_vec.length() < f32::EPSILON || old_vec.length() < f32::EPSILON {
|
|
||||||
player.r_drag_pos = Some(new_cursor);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let angle = (old_vec.dot(new_vec) / (old_vec.length() * new_vec.length())).acos() * ROT_SPEED;
|
|
||||||
|
|
||||||
let signed_angle = if old_vec.perp_dot(new_vec) < 0.0 {
|
|
||||||
angle
|
|
||||||
} else {
|
|
||||||
-angle
|
|
||||||
};
|
|
||||||
|
|
||||||
let delta_rotation = Quat::from_axis_angle(local_transform.forward().into(), signed_angle);
|
|
||||||
|
|
||||||
player.target_rotation = Some(delta_rotation * local_transform.rotation);
|
|
||||||
player.r_drag_pos = Some(new_cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn zoom(
|
pub fn zoom(
|
||||||
|
@ -176,12 +113,10 @@ pub fn zoom(
|
||||||
mut projection_query: Query<&mut Projection, With<Player>>,
|
mut projection_query: Query<&mut Projection, With<Player>>,
|
||||||
) {
|
) {
|
||||||
let Ok(mut projection) = projection_query.get_single_mut() else {
|
let Ok(mut projection) = projection_query.get_single_mut() else {
|
||||||
//info!("no camera projection");
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Projection::Perspective(ref mut perspective) = *projection else {
|
let Projection::Perspective(ref mut perspective) = *projection else {
|
||||||
//info!("no camera perspective");
|
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -189,10 +124,9 @@ pub fn zoom(
|
||||||
match ev.unit {
|
match ev.unit {
|
||||||
MouseScrollUnit::Line => {
|
MouseScrollUnit::Line => {
|
||||||
perspective.fov = (0.6*PI).min((0.02*PI).max(perspective.fov * 0.9_f32.powf(ev.y)));
|
perspective.fov = (0.6*PI).min((0.02*PI).max(perspective.fov * 0.9_f32.powf(ev.y)));
|
||||||
//info!("Scroll (line units): vertical: {}, horizontal: {}", ev.y, ev.x);
|
|
||||||
}
|
}
|
||||||
MouseScrollUnit::Pixel => {
|
MouseScrollUnit::Pixel => {
|
||||||
//info!("Scroll (pixel units): vertical: {}, horizontal: {}", ev.y, ev.x);
|
println!("Scroll (pixel units): vertical: {}, horizontal: {}", ev.y, ev.x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,7 +146,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() * MOVE_SPEED;
|
let angle_of_rotation = dot_product.acos() * MOUSE_SPEED;
|
||||||
|
|
||||||
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;
|
||||||
|
|
|
@ -215,7 +215,7 @@ pub fn player_interact(
|
||||||
return
|
return
|
||||||
};
|
};
|
||||||
|
|
||||||
if player.l_drag_pos.is_some() || player.r_drag_pos.is_some() {
|
if player.dragging_pos.is_some() {
|
||||||
game_data.target_cons_focused = false;
|
game_data.target_cons_focused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,7 @@ 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 MOVE_SPEED: f32 = 12.0;
|
const MOUSE_SPEED: f32 = 12.0;
|
||||||
const ROT_SPEED: f32 = 9.0;
|
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
struct StarData {
|
struct StarData {
|
||||||
|
@ -114,8 +113,7 @@ struct GameOver;
|
||||||
#[derive(Component, Default)]
|
#[derive(Component, Default)]
|
||||||
struct Player {
|
struct Player {
|
||||||
target_rotation: Option<Quat>,
|
target_rotation: Option<Quat>,
|
||||||
r_drag_pos: Option<Vec2>,
|
dragging_pos: Option<Vec2>,
|
||||||
l_drag_pos: Option<Vec2>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)]
|
#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)]
|
||||||
|
@ -142,7 +140,6 @@ fn main() {
|
||||||
.add_systems(OnEnter(GameState::Game), game_state::setup)
|
.add_systems(OnEnter(GameState::Game), game_state::setup)
|
||||||
.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::player_mouse_rotate.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, 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)))
|
||||||
|
|
Loading…
Reference in a new issue