summaryrefslogtreecommitdiff
path: root/src/util.h
diff options
context:
space:
mode:
authoraura <nw@moneybot.cc>2026-07-13 10:15:03 +0200
committeraura <nw@moneybot.cc>2026-07-13 10:15:03 +0200
commit57d172df4db1451ba3caeeb0ca485d0845a61912 (patch)
treead0be7c8bec79a1eb58b25f2a631bc4b6809e7fd /src/util.h
push source
Diffstat (limited to 'src/util.h')
-rw-r--r--src/util.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/util.h b/src/util.h
new file mode 100644
index 0000000..bc06b42
--- /dev/null
+++ b/src/util.h
@@ -0,0 +1,27 @@
+#pragma once
+#include <time.h>
+#include <math.h>
+#include "typedef.h"
+
+inline F64 t_nows() {
+ struct timespec ts;
+ clock_gettime( CLOCK_MONOTONIC, &ts );
+ return (F64)ts.tv_sec + (F64)ts.tv_nsec * 1e-9;
+}
+
+
+inline F32 fade_alpha( F64 since, F64 now ) {
+ if( since <= 0.0 )
+ return 0.0f;
+ F64 a = ( now - since - 0.30 ) / 0.30;
+ if( a < 0.0 ) a = 0.0;
+ if( a > 1.0 ) a = 1.0;
+ return (F32)a;
+}
+
+inline F32 vec_dist( F32 x1, F32 y1, F32 z1, F32 x2, F32 y2, F32 z2 ) {
+ F32 dx = x1 - x2;
+ F32 dy = y1 - y2;
+ F32 dz = z1 - z2;
+ return sqrtf( dx * dx + dy * dy + dz * dz );
+}