From c292c66900da2a027ae334662410a7bcffddb61e Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 13 May 2024 00:52:34 +0200 Subject: [PATCH] add PI/PI32 to common.rs --- src/camera.rs | 10 ++++------ src/cmd.rs | 12 +++++------- src/common.rs | 2 ++ src/nature.rs | 4 ++-- src/world.rs | 3 +-- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index e5cd8d7..7b9fbdf 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -22,8 +22,6 @@ use bevy::transform::TransformSystem; use bevy::math::{DVec3, DQuat}; use bevy_xpbd_3d::prelude::*; use bevy_xpbd_3d::plugins::sync; -use std::f32::consts::PI; -use std::f64::consts::PI as PI64; use crate::prelude::*; pub const INITIAL_ZOOM_LEVEL: f64 = 10.0; @@ -85,7 +83,7 @@ impl Default for MapCam { initialized: false, zoom_level: 2.0, target_zoom_level: INITIAL_ZOOM_LEVEL, - pitch: PI64 * 0.3, + pitch: PI * 0.3, yaw: 0.0, offset_x: 0.0, offset_z: 0.0, @@ -124,7 +122,7 @@ pub fn setup_camera( shadows_enabled: settings.shadows_sun, ..default() }, - transform: Transform::from_rotation(Quat::from_rotation_y(PI/2.0)), + transform: Transform::from_rotation(Quat::from_rotation_y(PI32/2.0)), cascade_shadow_config: CascadeShadowConfigBuilder { num_cascades: 4, minimum_distance: 0.1, @@ -197,7 +195,7 @@ pub fn update_map_camera( // at the extreme values and the orientation will flicker back/forth. let min_zoom: f64 = target_trans.scale.x as f64 * 2.0; let max_zoom: f64 = 17e18; // at this point, camera starts glitching - mapcam.pitch = (mapcam.pitch + mouse_delta.y as f64 / 180.0 * settings.mouse_sensitivity as f64).clamp(-PI64 / 2.0 + EPSILON, PI64 / 2.0 - EPSILON); + mapcam.pitch = (mapcam.pitch + mouse_delta.y as f64 / 180.0 * settings.mouse_sensitivity as f64).clamp(-PI / 2.0 + EPSILON, PI / 2.0 - EPSILON); mapcam.yaw += mouse_delta.x as f64 / 180.0 * settings.mouse_sensitivity as f64; // Reset movement offset if target changes @@ -659,7 +657,7 @@ pub fn find_closest_target( // not on the player mesh but on the camera, which doesn't have a position. let (angular_diameter, angle, distance) = calc_angular_diameter_known_target_vector( trans, camera_transform, &target_vector); - if angle <= angular_diameter.clamp(0.01, PI) { + if angle <= angular_diameter.clamp(0.01, PI32) { // It's in the field of view! //commands.entity(entity).insert(IsTargeted); let distance_to_surface = distance - trans.scale.x; diff --git a/src/cmd.rs b/src/cmd.rs index 89637bc..87190da 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -17,8 +17,6 @@ use bevy::math::DVec3; use bevy::pbr::{NotShadowCaster, NotShadowReceiver}; use crate::prelude::*; use regex::Regex; -use std::f32::consts::PI; -use std::f64::consts::PI as PI64; use std::time::SystemTime; pub struct CmdPlugin; @@ -252,7 +250,7 @@ pub fn load_defs( ["orbit", radius_str, phase_str] => { if let (Ok(r), Ok(phase)) = (radius_str.parse::(), phase_str.parse::()) { state.orbit_distance = Some(r); - state.orbit_phase = Some(phase * PI64 * 2.0); + state.orbit_phase = Some(phase * PI * 2.0); } else { error!("Can't parse float: {line}"); @@ -261,7 +259,7 @@ pub fn load_defs( } ["orbit_phase_offset", value] => { if let Ok(value_float) = value.parse::() { - let offset_radians = 2.0 * PI64 * value_float; + let offset_radians = 2.0 * PI * value_float; if let Some(phase_radians) = state.orbit_phase { state.orbit_phase = Some(phase_radians + offset_radians); } @@ -569,7 +567,7 @@ fn spawn_entities( let orbital_period = nature::simple_orbital_period(mass, r); phase_radians += if let Ok(epoch) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) { let now = epoch.as_secs_f64() + 614533234154.0; // random - PI64 * 2.0 * (now % orbital_period) / orbital_period + PI * 2.0 * (now % orbital_period) / orbital_period } else { error!("Can't determine current time `{id}`"); 0.0 @@ -775,8 +773,8 @@ fn spawn_entities( intensity: 40_000_000.0, // lumens color: Color::WHITE, shadows_enabled: true, - inner_angle: PI / 8.0 * 0.85, - outer_angle: PI / 4.0, + inner_angle: PI32 / 8.0 * 0.85, + outer_angle: PI32 / 4.0, range: 2000.0, ..default() }, diff --git a/src/common.rs b/src/common.rs index 09341ab..1970bdd 100644 --- a/src/common.rs +++ b/src/common.rs @@ -12,6 +12,8 @@ use bevy::prelude::*; +pub use std::f32::consts::PI as PI32; +pub use std::f64::consts::PI; pub const EPSILON32: f32 = 1e-9; pub const EPSILON: f64 = 1e-9; diff --git a/src/nature.rs b/src/nature.rs index 80f7164..e4b0a4b 100644 --- a/src/nature.rs +++ b/src/nature.rs @@ -11,7 +11,7 @@ // This module manages the messy, impure parts of our universe. use bevy::math::DVec3; -use std::f64::consts::PI as PI64; +use std::f64::consts::PI as PI; pub const OXYGEN_USE_KG_PER_S: f32 = 1e-5; pub const OXY_S: f32 = OXYGEN_USE_KG_PER_S; @@ -148,7 +148,7 @@ pub fn lorenz_factor_custom_c(speed: f64, c: f64) -> f64 { } pub fn simple_orbital_period(mass: f64, distance: f64) -> f64 { - return 2.0 * PI64 * (distance.powf(3.0) / (G * mass)).sqrt(); + return 2.0 * PI * (distance.powf(3.0) / (G * mass)).sqrt(); } pub fn phase_dist_to_coords(phase_radians: f64, distance: f64) -> DVec3 { diff --git a/src/world.rs b/src/world.rs index 4860a98..eee3a3d 100644 --- a/src/world.rs +++ b/src/world.rs @@ -17,7 +17,6 @@ use bevy::scene::{InstanceId, SceneInstance}; use bevy::render::mesh::Indices; use bevy_xpbd_3d::prelude::*; use std::collections::HashMap; -use std::f32::consts::PI; use fastrand; const ASTEROID_UPDATE_INTERVAL: f32 = 0.1; // seconds @@ -306,7 +305,7 @@ fn spawn_despawn_asteroids( AngularVelocity(DVec3::new(0.1, 0.1, 0.03)), LinearVelocity(DVec3::new(0.0, 0.0, 0.35)), Collider::sphere(1.0), - Rotation::from(Quat::from_rotation_y(-PI / 3.)), + Rotation::from(Quat::from_rotation_y(-PI32 / 3.)), Position::new(pos), hud::IsClickable { name: Some("Uncharted Rock".to_string()),