Minor tidy.

This commit is contained in:
Joe Ardent 2022-01-17 13:40:31 -08:00
parent 20f68b2bec
commit cfc32a741f
3 changed files with 29 additions and 7 deletions

13
Cargo.lock generated
View file

@ -993,6 +993,7 @@ dependencies = [
"bevy",
"bevy_mod_debugdump",
"heron",
"rand",
]
[[package]]
@ -1572,9 +1573,9 @@ checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125"
[[package]]
name = "libloading"
version = "0.7.2"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "afe203d669ec979b7128619bae5a63b7b42e9203c1b29146079ee05e2f604b52"
checksum = "efbc0f03f9a775e9f6aed295c6a1ba2253c5757a9e03d55c6caa46a681abcddd"
dependencies = [
"cfg-if 1.0.0",
"winapi",
@ -2374,9 +2375,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.74"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142"
checksum = "c059c05b48c5c0067d4b4b2b4f0732dd65feb52daf7e0ea09cd87e7dadc1af79"
dependencies = [
"itoa",
"ryu",
@ -2622,9 +2623,9 @@ dependencies = [
[[package]]
name = "tracing-subscriber"
version = "0.3.5"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d81bfa81424cc98cb034b837c985b7a290f592e5b4322f353f94a0ab0f9f594"
checksum = "77be66445c4eeebb934a7340f227bfe7b338173d3f8c00a60a5a58005c9faecf"
dependencies = [
"ansi_term",
"lazy_static",

View file

@ -5,6 +5,7 @@ edition = "2021"
[dependencies]
bevy_mod_debugdump = "0.3.0"
rand = "0.8.4"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,6 +1,6 @@
use bevy::{
ecs::schedule::StageLabel,
prelude::{ResMut, SystemLabel, Windows},
prelude::{ResMut, SystemLabel, Vec3, Windows},
};
pub mod action;
@ -24,3 +24,23 @@ pub fn disable_mouse_trap(mut windows: ResMut<Windows>) {
window.set_cursor_lock_mode(false);
window.set_cursor_visibility(true);
}
pub fn random_sphere_vec(r: &mut impl rand::prelude::Rng) -> Vec3 {
// https://mathworld.wolfram.com/SpherePointPicking.html
// Marsaglia (1972) for picking x1 and x2 from (-1, 1) and generating surface
// points directly if their sum is less than 1.
let mut x1 = 0.0;
let mut x2 = 0.0;
let mut ssum = 2.0;
while ssum >= 1.0 {
x1 = r.gen_range(-1.0..=1.0);
x2 = r.gen_range(-1.0..=1.0);
ssum = x1.powi(2) + x2.powi(2);
}
let sqrt = (1.0 - x1.powi(2) - x2.powi(2)).sqrt();
let x = 2.0 * x1 * sqrt;
let y = 2.0 * x2 * sqrt;
let z = 1.0 - 2.0 * ssum;
Vec3::new(x, y, z)
}