mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added helper function density_factor_by_altitude
This commit is contained in:
parent
91a4a9e187
commit
c0911707e5
@ -1,6 +1,7 @@
|
||||
use crate::{column::ColumnSample, sim::SimChunk, Canvas, CONFIG};
|
||||
use common::terrain::{Block, BlockKind, SpriteKind};
|
||||
use noise::NoiseFn;
|
||||
use num::traits::Pow;
|
||||
use rand::prelude::*;
|
||||
use std::f32;
|
||||
use vek::*;
|
||||
@ -9,6 +10,20 @@ pub fn close(x: f32, tgt: f32, falloff: f32) -> f32 {
|
||||
(1.0 - (x - tgt).abs() / falloff).max(0.0).powf(0.125)
|
||||
}
|
||||
|
||||
/// Returns a decimal value between 0 and 1.
|
||||
/// The density is maximum at the middle of the highest and the lowest allowed
|
||||
/// altitudes, and zero otherwise. Quadratic curve.
|
||||
///
|
||||
/// The formula used is:
|
||||
///
|
||||
/// ```latex
|
||||
/// \max\left(-\frac{4\left(x-u\right)\left(x-l\right)}{\left(u-l\right)^{2}},\ 0\right)
|
||||
/// ```
|
||||
pub fn density_factor_by_altitude(lower_limit: f32, altitude: f32, upper_limit: f32) -> f32 {
|
||||
let maximum: f32 = (upper_limit - lower_limit).pow(2) / 4.0f32;
|
||||
(-((altitude - lower_limit) * (altitude - upper_limit)) / maximum).max(0.0)
|
||||
}
|
||||
|
||||
const MUSH_FACT: f32 = 1.0e-4; // To balance things around the mushroom spawning rate
|
||||
const GRASS_FACT: f32 = 1.0e-3; // To balance things around the grass spawning rate
|
||||
const DEPTH_WATER_NORM: f32 = 15.0; // Water depth at which regular underwater sprites start spawning
|
||||
|
Loading…
Reference in New Issue
Block a user