-/* Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved */
+/* Copyright (C) 2021-2022 Harry Godden (hgn) - All Rights Reserved */
+
+#ifndef VG_M_H
+#define VG_M_H
+
+#include "vg_platform.h"
+#include <math.h>
+#include <stdlib.h>
#define VG_PIf 3.14159265358979323846264338327950288f
#define VG_TAUf 6.28318530717958647692528676655900576f
return a - floorf( a );
}
-static inline float vg_randf(void)
-{
- return (float)rand()/(float)(RAND_MAX);
-}
-
-static inline int vg_randint(int max)
-{
- return rand()%max;
-}
-
static float stable_force( float current, float diff )
{
float fnew = current + diff;
d[3] = q[3]*s;
}
+static inline void q_nlerp( v4f a, v4f b, float t, v4f d )
+{
+ v4_lerp( a, b, t, d );
+ q_normalize( d );
+}
+
static inline void q_m3x3( v4f q, m3x3f d )
{
float
}
else return 0;
}
+
+static inline float vg_randf(void)
+{
+ return (float)rand()/(float)(RAND_MAX);
+}
+
+static inline void vg_rand_dir(v3f dir)
+{
+ dir[0] = vg_randf();
+ dir[1] = vg_randf();
+ dir[2] = vg_randf();
+
+ v3_muls( dir, 2.0f, dir );
+ v3_sub( dir, (v3f){1.0f,1.0f,1.0f}, dir );
+
+ v3_normalize( dir );
+}
+
+static inline void vg_rand_sphere( v3f co )
+{
+ vg_rand_dir(co);
+ v3_muls( co, cbrtf( vg_randf() ), co );
+}
+
+static inline int vg_randint(int max)
+{
+ return rand()%max;
+}
+
+#endif /* VG_M_H */