implement special relativity (for speed cheats only, so far)
This commit is contained in:
parent
dd2e596f5c
commit
3814aa4155
14
src/game.rs
14
src/game.rs
|
@ -136,13 +136,15 @@ fn handle_cheats(
|
||||||
gforce.ignore_gforce_seconds = 1.0;
|
gforce.ignore_gforce_seconds = 1.0;
|
||||||
v.0 = DVec3::ZERO;
|
v.0 = DVec3::ZERO;
|
||||||
}
|
}
|
||||||
if key_input.pressed(settings.key_cheat_speed) {
|
if key_input.pressed(settings.key_cheat_speed) || key_input.pressed(settings.key_cheat_speed_backward) {
|
||||||
gforce.ignore_gforce_seconds = 1.0;
|
gforce.ignore_gforce_seconds = 1.0;
|
||||||
v.0 += DVec3::from(trans.rotation * Vec3::new(0.0, 0.0, boost));
|
let sign = if key_input.pressed(settings.key_cheat_speed) { 1.0 } else { -1.0 };
|
||||||
}
|
let dv = DVec3::from(trans.rotation * Vec3::new(0.0, 0.0, sign * boost));
|
||||||
if key_input.pressed(settings.key_cheat_speed_backward) {
|
let current_speed = v.0.length();
|
||||||
gforce.ignore_gforce_seconds = 1.0;
|
let next_speed = (v.0 + dv).length();
|
||||||
v.0 += DVec3::from(trans.rotation * Vec3::new(0.0, 0.0, -boost));
|
let avg_speed = (current_speed + next_speed) / 2.0;
|
||||||
|
let inv_lorentz = nature::inverse_lorentz_factor(avg_speed.clamp(0.0, nature::C));
|
||||||
|
v.0 = v.0 + inv_lorentz * dv;
|
||||||
}
|
}
|
||||||
if key_input.just_pressed(settings.key_cheat_teleport) {
|
if key_input.just_pressed(settings.key_cheat_teleport) {
|
||||||
if let Ok((transform, target_pos, target_v)) = q_target.get_single() {
|
if let Ok((transform, target_pos, target_v)) = q_target.get_single() {
|
||||||
|
|
|
@ -147,11 +147,11 @@ pub fn lorentz_factor_custom_c(speed: f64, c: f64) -> f64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inverse_lorentz_factor(speed: f64) -> f64 {
|
pub fn inverse_lorentz_factor(speed: f64) -> f64 {
|
||||||
(1.0 - (speed.powf(2.0) / C.powf(2.0))).powf(0.5)
|
(1.0 - (speed.powf(2.0) / C.powf(2.0))).sqrt()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inverse_lorentz_factor_custom_c(speed: f64, c: f64) -> f64 {
|
pub fn inverse_lorentz_factor_custom_c(speed: f64, c: f64) -> f64 {
|
||||||
(1.0 - (speed.powf(2.0) / c.powf(2.0))).powf(0.5)
|
(1.0 - (speed.powf(2.0) / c.powf(2.0))).sqrt()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn simple_orbital_period(mass: f64, distance: f64) -> f64 {
|
pub fn simple_orbital_period(mass: f64, distance: f64) -> f64 {
|
||||||
|
|
Loading…
Reference in a new issue