-// Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved
-
-// Util
-// ==================================================================================================================
+/* Copyright (C) 2021 Harry Godden (hgn) - All Rights Reserved */
#define VG_PIf 3.14159265358979323846264338327950288f
#define VG_TAUf 6.28318530717958647692528676655900576f
-// Simple min/max replacements
static inline float vg_minf( float a, float b )
{
return a < b? a: b;
#define VG_MIN( A, B ) ((A)<(B)?(A):(B))
#define VG_MAX( A, B ) ((A)>(B)?(A):(B))
-// Hopefully deprecate this!!
static inline int vg_min( int a, int b )
{
return a < b? a: b;
return a > b? a: b;
}
-// Convert degrees to radians
static inline float vg_rad( float deg )
{
return deg * VG_PIf / 180.0f;
}
-// Vector 2
-// ==================================================================================================================
-
+/*
+ * Vector 3
+ */
static inline void v2_copy( v2f a, v2f b )
{
b[0] = a[0]; b[1] = a[1];
d[0] = a[0]/s; d[1] = a[1]/s;
}
-
static inline void v2_mul( v2f a, v2f b, v2f d )
{
d[0] = a[0]*b[0];
d[1] = a[1] + t*(b[1]-a[1]);
}
-// Vector 3
-// ==================================================================================================================
-
+/*
+ * Vector 3
+ */
static inline void v3_zero( v3f a )
{
a[0] = 0.f; a[1] = 0.f; a[2] = 0.f;
a[2] = v;
}
-// Vector 4
-// ==================================================================================================================
-
+/*
+ * Vector 4
+ */
static inline void v4_copy( v4f a, v4f b )
{
b[0] = a[0]; b[1] = a[1]; b[2] = a[2]; b[3] = a[3];
a[0] = 0.f; a[1] = 0.f; a[2] = 0.f; a[3] = 0.f;
}
-// Matrix 2x2
-// ===========================================================================================================
+/*
+ * Matrix 2x2
+ */
#define M2X2_INDENTIY {{1.0f, 0.0f, }, \
{ 0.0f, 1.0f, }}
a[1][1] = c;
}
-// Matrix 3x3
-//======================================================================================================
+/*
+ * Matrix 3x3
+ */
#define M3X3_IDENTITY {{1.0f, 0.0f, 0.0f, },\
{ 0.0f, 1.0f, 0.0f, },\
v3_copy( res, d );
}
-static inline void m3x3_projection( m3x3f dst, float const left, float const right, float const bottom, float const top )
+static inline void m3x3_projection( m3x3f dst,
+ float const left, float const right, float const bottom, float const top )
{
float rl, tb;
m[1][2] = m02 * -s + m12 * c;
}
-// Matrix 4x3
-// ==================================================================================================================
+/*
+ * Matrix 4x3
+ */
#define M4X3_IDENTITY {{1.0f, 0.0f, 0.0f, },\
{ 0.0f, 1.0f, 0.0f, },\
v3_copy( res, d );
}
-// Affine transforms
-// ====================================================================================================================
+/*
+ * Affine transforms
+ */
static inline void m4x3_translate( m4x3f m, v3f v )
{
m4x3_mul( m, t, m );
}
-// Warning: These functions are unoptimized..
static inline void m4x3_expand_aabb_point( m4x3f m, boxf box, v3f point )
{
v3f v;
m4x3_expand_aabb_point( m, box, (v3f){ b[0], b[1], b[2] } );
}
-// Planes (double precision)
-// ==================================================================================================================
-
-static inline void tri_to_plane( double a[3], double b[3], double c[3], double p[4] )
+/*
+ * Planes (double precision)
+ */
+static inline void tri_to_plane( double a[3], double b[3],
+ double c[3], double p[4] )
{
double edge0[3];
double edge1[3];
p[2] = p[2] / l;
}
-static inline int plane_intersect( double a[4], double b[4], double c[4], double p[4] )
+static inline int plane_intersect( double a[4], double b[4],
+ double c[4], double p[4] )
{
double const epsilon = 1e-8f;