]> git.nega.tv - josh/narcissus/commitdiff
shark: Move spring helper into own module
authorJosh Simmons <josh@nega.tv>
Sat, 11 May 2024 10:00:47 +0000 (12:00 +0200)
committerJosh Simmons <josh@nega.tv>
Sat, 11 May 2024 10:00:47 +0000 (12:00 +0200)
title/shark/src/main.rs
title/shark/src/spring.rs [new file with mode: 0644]

index 7054fac7e7f5f132c6375696f6b621345091471e..618672473171836361384b685895b07d37c813cd 100644 (file)
@@ -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 (file)
index 0000000..2d8e623
--- /dev/null
@@ -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),
+    )
+}