add EPSILON and EPSILON32 constants

This commit is contained in:
yuni 2024-05-13 00:48:41 +02:00
parent 78eeef6201
commit 3b7e3e94dc
3 changed files with 8 additions and 8 deletions

View file

@ -444,11 +444,10 @@ fn handle_wants_maxrotation(
//time: Res<Time>, //time: Res<Time>,
mut query: Query<(&mut AngularVelocity, &Engine, &WantsMaxRotation)>, mut query: Query<(&mut AngularVelocity, &Engine, &WantsMaxRotation)>,
) { ) {
let epsilon = 0.0001;
//let d = time.delta_seconds(); //let d = time.delta_seconds();
for (mut v_ang, engine, maxrot) in &mut query { for (mut v_ang, engine, maxrot) in &mut query {
let total = v_ang.0.length(); let total = v_ang.0.length();
if total <= maxrot.0 + epsilon { if total <= maxrot.0 + EPSILON {
if total > maxrot.0 { if total > maxrot.0 {
v_ang.0 = DVec3::splat(0.0); v_ang.0 = DVec3::splat(0.0);
} }
@ -465,10 +464,9 @@ fn handle_wants_maxvelocity(
mut query: Query<(&mut LinearVelocity, &Engine, &WantsMaxVelocity)>, mut query: Query<(&mut LinearVelocity, &Engine, &WantsMaxVelocity)>,
) { ) {
let dt = time.delta_seconds(); let dt = time.delta_seconds();
let epsilon = 0.0001;
for (mut v, engine, maxv) in &mut query { for (mut v, engine, maxv) in &mut query {
let total = v.0.length(); let total = v.0.length();
if total <= maxv.0 + epsilon { if total <= maxv.0 + EPSILON {
if total > maxv.0 { if total > maxv.0 {
v.0 = DVec3::splat(0.0); v.0 = DVec3::splat(0.0);
} }
@ -480,7 +478,7 @@ fn handle_wants_maxvelocity(
let avg_thrust = (engine.thrust_forward + engine.thrust_back + engine.thrust_sideways) / 3.0; let avg_thrust = (engine.thrust_forward + engine.thrust_back + engine.thrust_sideways) / 3.0;
let acceleration = (avg_thrust * dt) as f64 * -v.0; let acceleration = (avg_thrust * dt) as f64 * -v.0;
v.0 += acceleration; v.0 += acceleration;
if v.0.length() + epsilon < acceleration.length() { if v.0.length() + EPSILON < acceleration.length() {
v.0 = DVec3::splat(0.0); v.0 = DVec3::splat(0.0);
} }
} }

View file

@ -195,10 +195,9 @@ pub fn update_map_camera(
// NOTE: we need to subtract a bit from PI/2, otherwise the "up" // NOTE: we need to subtract a bit from PI/2, otherwise the "up"
// direction parameter for the Transform.look_at function is ambiguous // direction parameter for the Transform.look_at function is ambiguous
// at the extreme values and the orientation will flicker back/forth. // at the extreme values and the orientation will flicker back/forth.
let epsilon = 0.001;
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(-PI64 / 2.0 + EPSILON, PI64 / 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

View file

@ -8,10 +8,13 @@
// + + + ███ // + + + ███
// + ▀████████████████████████████████████████████████████▀ // + ▀████████████████████████████████████████████████████▀
// //
// Various common functions // Various common functions and constants
use bevy::prelude::*; use bevy::prelude::*;
pub const EPSILON32: f32 = 1e-9;
pub const EPSILON: f64 = 1e-9;
#[inline] #[inline]
pub fn bool2vis(boolean: bool) -> bevy::prelude::Visibility { pub fn bool2vis(boolean: bool) -> bevy::prelude::Visibility {
if boolean { if boolean {