add PI/PI32 to common.rs
This commit is contained in:
parent
3b7e3e94dc
commit
c292c66900
|
@ -22,8 +22,6 @@ use bevy::transform::TransformSystem;
|
||||||
use bevy::math::{DVec3, DQuat};
|
use bevy::math::{DVec3, DQuat};
|
||||||
use bevy_xpbd_3d::prelude::*;
|
use bevy_xpbd_3d::prelude::*;
|
||||||
use bevy_xpbd_3d::plugins::sync;
|
use bevy_xpbd_3d::plugins::sync;
|
||||||
use std::f32::consts::PI;
|
|
||||||
use std::f64::consts::PI as PI64;
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
pub const INITIAL_ZOOM_LEVEL: f64 = 10.0;
|
pub const INITIAL_ZOOM_LEVEL: f64 = 10.0;
|
||||||
|
@ -85,7 +83,7 @@ impl Default for MapCam {
|
||||||
initialized: false,
|
initialized: false,
|
||||||
zoom_level: 2.0,
|
zoom_level: 2.0,
|
||||||
target_zoom_level: INITIAL_ZOOM_LEVEL,
|
target_zoom_level: INITIAL_ZOOM_LEVEL,
|
||||||
pitch: PI64 * 0.3,
|
pitch: PI * 0.3,
|
||||||
yaw: 0.0,
|
yaw: 0.0,
|
||||||
offset_x: 0.0,
|
offset_x: 0.0,
|
||||||
offset_z: 0.0,
|
offset_z: 0.0,
|
||||||
|
@ -124,7 +122,7 @@ pub fn setup_camera(
|
||||||
shadows_enabled: settings.shadows_sun,
|
shadows_enabled: settings.shadows_sun,
|
||||||
..default()
|
..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 {
|
cascade_shadow_config: CascadeShadowConfigBuilder {
|
||||||
num_cascades: 4,
|
num_cascades: 4,
|
||||||
minimum_distance: 0.1,
|
minimum_distance: 0.1,
|
||||||
|
@ -197,7 +195,7 @@ pub fn update_map_camera(
|
||||||
// at the extreme values and the orientation will flicker back/forth.
|
// at the extreme values and the orientation will flicker back/forth.
|
||||||
let min_zoom: f64 = target_trans.scale.x as f64 * 2.0;
|
let min_zoom: f64 = target_trans.scale.x as f64 * 2.0;
|
||||||
let max_zoom: f64 = 17e18; // at this point, camera starts glitching
|
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;
|
mapcam.yaw += mouse_delta.x as f64 / 180.0 * settings.mouse_sensitivity as f64;
|
||||||
|
|
||||||
// Reset movement offset if target changes
|
// Reset movement offset if target changes
|
||||||
|
@ -659,7 +657,7 @@ pub fn find_closest_target<TargetSpecifier>(
|
||||||
// not on the player mesh but on the camera, which doesn't have a position.
|
// 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(
|
let (angular_diameter, angle, distance) = calc_angular_diameter_known_target_vector(
|
||||||
trans, camera_transform, &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!
|
// It's in the field of view!
|
||||||
//commands.entity(entity).insert(IsTargeted);
|
//commands.entity(entity).insert(IsTargeted);
|
||||||
let distance_to_surface = distance - trans.scale.x;
|
let distance_to_surface = distance - trans.scale.x;
|
||||||
|
|
12
src/cmd.rs
12
src/cmd.rs
|
@ -17,8 +17,6 @@ use bevy::math::DVec3;
|
||||||
use bevy::pbr::{NotShadowCaster, NotShadowReceiver};
|
use bevy::pbr::{NotShadowCaster, NotShadowReceiver};
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::f32::consts::PI;
|
|
||||||
use std::f64::consts::PI as PI64;
|
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
pub struct CmdPlugin;
|
pub struct CmdPlugin;
|
||||||
|
@ -252,7 +250,7 @@ pub fn load_defs(
|
||||||
["orbit", radius_str, phase_str] => {
|
["orbit", radius_str, phase_str] => {
|
||||||
if let (Ok(r), Ok(phase)) = (radius_str.parse::<f64>(), phase_str.parse::<f64>()) {
|
if let (Ok(r), Ok(phase)) = (radius_str.parse::<f64>(), phase_str.parse::<f64>()) {
|
||||||
state.orbit_distance = Some(r);
|
state.orbit_distance = Some(r);
|
||||||
state.orbit_phase = Some(phase * PI64 * 2.0);
|
state.orbit_phase = Some(phase * PI * 2.0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
error!("Can't parse float: {line}");
|
error!("Can't parse float: {line}");
|
||||||
|
@ -261,7 +259,7 @@ pub fn load_defs(
|
||||||
}
|
}
|
||||||
["orbit_phase_offset", value] => {
|
["orbit_phase_offset", value] => {
|
||||||
if let Ok(value_float) = value.parse::<f64>() {
|
if let Ok(value_float) = value.parse::<f64>() {
|
||||||
let offset_radians = 2.0 * PI64 * value_float;
|
let offset_radians = 2.0 * PI * value_float;
|
||||||
if let Some(phase_radians) = state.orbit_phase {
|
if let Some(phase_radians) = state.orbit_phase {
|
||||||
state.orbit_phase = Some(phase_radians + offset_radians);
|
state.orbit_phase = Some(phase_radians + offset_radians);
|
||||||
}
|
}
|
||||||
|
@ -569,7 +567,7 @@ fn spawn_entities(
|
||||||
let orbital_period = nature::simple_orbital_period(mass, r);
|
let orbital_period = nature::simple_orbital_period(mass, r);
|
||||||
phase_radians += if let Ok(epoch) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
|
phase_radians += if let Ok(epoch) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) {
|
||||||
let now = epoch.as_secs_f64() + 614533234154.0; // random
|
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 {
|
} else {
|
||||||
error!("Can't determine current time `{id}`");
|
error!("Can't determine current time `{id}`");
|
||||||
0.0
|
0.0
|
||||||
|
@ -775,8 +773,8 @@ fn spawn_entities(
|
||||||
intensity: 40_000_000.0, // lumens
|
intensity: 40_000_000.0, // lumens
|
||||||
color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
shadows_enabled: true,
|
shadows_enabled: true,
|
||||||
inner_angle: PI / 8.0 * 0.85,
|
inner_angle: PI32 / 8.0 * 0.85,
|
||||||
outer_angle: PI / 4.0,
|
outer_angle: PI32 / 4.0,
|
||||||
range: 2000.0,
|
range: 2000.0,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
use bevy::prelude::*;
|
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 EPSILON32: f32 = 1e-9;
|
||||||
pub const EPSILON: f64 = 1e-9;
|
pub const EPSILON: f64 = 1e-9;
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// This module manages the messy, impure parts of our universe.
|
// This module manages the messy, impure parts of our universe.
|
||||||
|
|
||||||
use bevy::math::DVec3;
|
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 OXYGEN_USE_KG_PER_S: f32 = 1e-5;
|
||||||
pub const OXY_S: f32 = OXYGEN_USE_KG_PER_S;
|
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 {
|
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 {
|
pub fn phase_dist_to_coords(phase_radians: f64, distance: f64) -> DVec3 {
|
||||||
|
|
|
@ -17,7 +17,6 @@ use bevy::scene::{InstanceId, SceneInstance};
|
||||||
use bevy::render::mesh::Indices;
|
use bevy::render::mesh::Indices;
|
||||||
use bevy_xpbd_3d::prelude::*;
|
use bevy_xpbd_3d::prelude::*;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::f32::consts::PI;
|
|
||||||
use fastrand;
|
use fastrand;
|
||||||
|
|
||||||
const ASTEROID_UPDATE_INTERVAL: f32 = 0.1; // seconds
|
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)),
|
AngularVelocity(DVec3::new(0.1, 0.1, 0.03)),
|
||||||
LinearVelocity(DVec3::new(0.0, 0.0, 0.35)),
|
LinearVelocity(DVec3::new(0.0, 0.0, 0.35)),
|
||||||
Collider::sphere(1.0),
|
Collider::sphere(1.0),
|
||||||
Rotation::from(Quat::from_rotation_y(-PI / 3.)),
|
Rotation::from(Quat::from_rotation_y(-PI32 / 3.)),
|
||||||
Position::new(pos),
|
Position::new(pos),
|
||||||
hud::IsClickable {
|
hud::IsClickable {
|
||||||
name: Some("Uncharted Rock".to_string()),
|
name: Some("Uncharted Rock".to_string()),
|
||||||
|
|
Loading…
Reference in a new issue