Tweak temperatures

a6b113de6b0b5e13d1c9a1605885dbc189dda096

Also fix mouse world position, FPS display, and possible Divide-By-Zero
This commit is contained in:
Tobias Berger 2022-09-06 23:16:47 +02:00
parent 7ae8dba296
commit 8aaf20242e
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
3 changed files with 23 additions and 20 deletions

View file

@ -62,11 +62,10 @@ pub fn random_point_in_sphere(radius: f32) -> Vec3A {
let x = rng.gen_range(-radius..radius);
let y = rng.gen_range(-radius..radius);
let z = rng.gen_range(-radius..radius);
let mult = 1.0 / (x * x + y * y + z * z).sqrt();
if x == 0.0 && y == 0.0 && z == 0.0 {
return Vec3A::X;
return Vec3A::ZERO;
}
let mult = 1.0 / (x * x + y * y + z * z).sqrt();
Vec3A::new(mult * x, mult * y, mult * z)
}

View file

@ -127,8 +127,8 @@ impl World {
pub const RAINFALL_SPAN: f32 = Self::MAX_RAINFALL - Self::MIN_RAINFALL;
pub const RAINFALL_ALTITUDE_FACTOR: f32 = 1.0;
pub const MIN_TEMPERATURE: f32 = -100.0;
pub const MAX_TEMPERATURE: f32 = 100.0;
pub const MIN_TEMPERATURE: f32 = -50.0;
pub const MAX_TEMPERATURE: f32 = 30.0;
pub const TEMPERATURE_SPAN: f32 = Self::MAX_TEMPERATURE - Self::MIN_RAINFALL;
pub const TEMPERATURE_ALTITUDE_FACTOR: f32 = 1.0;
@ -418,17 +418,13 @@ impl World {
let cell = &mut self.terrain[y][x];
let altitude_factor = 1.0
- f32::clamp(
(cell.altitude / Self::MAX_ALTITUDE) * Self::TEMPERATURE_ALTITUDE_FACTOR,
0.0,
1.0,
);
let altitude_factor = (cell.altitude / Self::MAX_ALTITUDE)
* (2.5 * Self::TEMPERATURE_ALTITUDE_FACTOR);
let latitude_modifer = (alpha * 0.8) + (random_noise * 0.2 * PI);
let base_temperature = Self::calculate_temperature(f32::sin(latitude_modifer));
cell.temperature = base_temperature * altitude_factor;
cell.temperature = base_temperature * (1.0 - altitude_factor);
}
}
@ -438,7 +434,7 @@ impl World {
fn calculate_temperature(raw_temperature: f32) -> f32 {
f32::clamp(
(raw_temperature * Self::TEMPERATURE_SPAN) + Self::MIN_TEMPERATURE,
0.0,
Self::MIN_TEMPERATURE,
Self::MAX_TEMPERATURE,
)
}

View file

@ -182,7 +182,7 @@ fn update_cursor_map_position(
let window_size = Vec2::new(window.width(), window.height());
// GPU coordinates [-1..1]
let ndc = (screen_position / window_size) * 2.0;
let ndc = (screen_position / window_size) * 2.0 - Vec2::ONE;
// Matrix to reverse camera transform
let ndc_to_world = transform.compute_matrix() * camera.projection_matrix().inverse();
@ -190,8 +190,9 @@ fn update_cursor_map_position(
let world_position =
ndc_to_world.project_point3(ndc.extend(-1.0)).truncate() / WORLD_SCALE as f32;
cursor_map_position.x = world_position.x.round() as i32;
cursor_map_position.y = world_manager.world().height - world_position.y.round() as i32;
let world = world_manager.world();
cursor_map_position.x = world_position.x as i32 + world.width / 2 - 1;
cursor_map_position.y = world.height / 2 - world_position.y as i32 - 1;
}
}
@ -219,10 +220,10 @@ fn update_info_panel(
#[cfg(feature = "debug")]
{
format!(
"FPS: {}\nMouse position: {}\nAltitude: {}\nRainfall: {}\nTemperature: {}",
"FPS: ~{}\nMouse position: {}\nAltitude: {}\nRainfall: {}\nTemperature: {}",
match diagnostics.get_measurement(FrameTimeDiagnosticsPlugin::FPS) {
None => f64::NAN,
Some(fps) => fps.value,
Some(fps) => fps.value.round(),
},
*cursor_position,
cell.altitude,
@ -238,7 +239,14 @@ fn update_info_panel(
)
}
} else {
format!("Mouse position: {}\nOut of bounds", *cursor_position)
format!(
"FPS: ~{}\nMouse position: {}\nOut of bounds",
match diagnostics.get_measurement(FrameTimeDiagnosticsPlugin::FPS) {
None => f64::NAN,
Some(fps) => fps.value.round(),
},
*cursor_position
)
};
}
@ -404,7 +412,7 @@ fn generate_graphics(
}
#[cfg(feature = "render")]
const WORLD_SCALE: i32 = 3;
const WORLD_SCALE: i32 = 4;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut app = App::new();
let mut manager = WorldManager::new();