From aaabb7ec3b0500bd0d381805c702d904b403aa09 Mon Sep 17 00:00:00 2001 From: Josh Simmons Date: Sat, 11 May 2024 12:00:47 +0200 Subject: [PATCH] shark: Move spring helper into own module --- title/shark/src/main.rs | 23 +++-------------------- title/shark/src/spring.rs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 20 deletions(-) create mode 100644 title/shark/src/spring.rs diff --git a/title/shark/src/main.rs b/title/shark/src/main.rs index 7054fac..6186724 100644 --- a/title/shark/src/main.rs +++ b/title/shark/src/main.rs @@ -18,14 +18,15 @@ use narcissus_gpu::{ Viewport, }; use narcissus_maths::{ - clamp, exp_f32, perlin_noise3, sin_pi_f32, vec3, Affine3, Deg, HalfTurn, Mat3, Mat4, Point3, - Vec3, + clamp, perlin_noise3, sin_pi_f32, vec3, Affine3, Deg, HalfTurn, Mat3, Mat4, Point3, Vec3, }; use pipelines::{BasicUniforms, PrimitiveInstance, PrimitiveVertex, TextUniforms}; +use spring::simple_spring_damper_exact; mod fonts; mod helpers; mod pipelines; +mod spring; const SQRT_2: f32 = 0.70710677; @@ -436,24 +437,6 @@ impl GameState { } } -// https://theorangeduck.com/page/spring-roll-call -fn simple_spring_damper_exact( - x: f32, - velocity: f32, - goal: f32, - damping: f32, - delta_time: f32, -) -> (f32, f32) { - let y = damping / 2.0; - let j0 = x - goal; - let j1 = velocity + j0 * y; - let eydt = exp_f32(-y * delta_time); - ( - eydt * (j0 + j1 * delta_time) + goal, - eydt * (velocity - j1 * y * delta_time), - ) -} - pub fn main() { #[cfg(debug_assertions)] if std::env::var("RUST_BACKTRACE").is_err() { diff --git a/title/shark/src/spring.rs b/title/shark/src/spring.rs new file mode 100644 index 0000000..2d8e623 --- /dev/null +++ b/title/shark/src/spring.rs @@ -0,0 +1,19 @@ +use narcissus_maths::exp_f32; + +// https://theorangeduck.com/page/spring-roll-call +pub fn simple_spring_damper_exact( + x: f32, + velocity: f32, + goal: f32, + damping: f32, + delta_time: f32, +) -> (f32, f32) { + let y = damping / 2.0; + let j0 = x - goal; + let j1 = velocity + j0 * y; + let eydt = exp_f32(-y * delta_time); + ( + eydt * (j0 + j1 * delta_time) + goal, + eydt * (velocity - j1 * y * delta_time), + ) +} -- 2.49.0