mc 1.9
[vg.git] / src / vg / vg_m.h
index 577138fb12e575698d1c941e15958f05a898beeb..392eb2f09c9d7645350320255b8e489bb37ae43a 100644 (file)
@@ -1,12 +1,8 @@
-// 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;
@@ -25,7 +21,6 @@ static inline float vg_clampf( float a, float min, float max )
 #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;
@@ -36,15 +31,14 @@ static inline int vg_max( int a, int 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];
@@ -107,7 +101,6 @@ static inline void v2_divs( v2f a, float s, v2f d )
        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]; 
@@ -159,9 +152,9 @@ static inline void v2_lerp( v2f a, v2f b, float t, v2f d )
        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;
@@ -289,9 +282,9 @@ static inline void v3_fill( v3f a, float v )
        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];
@@ -302,8 +295,9 @@ static inline void v4_zero( v4f a )
        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, }}
@@ -336,8 +330,9 @@ static inline void m2x2_create_rotation( m2x2f a, float theta )
        a[1][1] =  c;
 }
 
-// Matrix 3x3
-//======================================================================================================
+/*
+ * Matrix 3x3
+ */
 
 #define M3X3_IDENTITY  {{1.0f, 0.0f, 0.0f, },\
                                                                { 0.0f, 1.0f, 0.0f, },\
@@ -438,7 +433,8 @@ static inline void m3x3_mulv( m3x3f m, v3f v, v3f d )
        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;
        
@@ -489,8 +485,9 @@ static inline void m3x3_rotate( m3x3f m, float angle )
        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, },\
@@ -555,8 +552,9 @@ static inline void m4x3_mulv( m4x3f m, v3f v, v3f d )
        v3_copy( res, d );
 }
 
-// Affine transforms
-// ====================================================================================================================
+/*
+ * Affine transforms
+ */
 
 static inline void m4x3_translate( m4x3f m, v3f v )
 {
@@ -620,7 +618,6 @@ static inline void m4x3_rotate_z( m4x3f m, float angle )
        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;
@@ -661,10 +658,11 @@ static inline void m4x3_transform_aabb( m4x3f m, boxf box )
        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];
@@ -690,7 +688,8 @@ static inline void tri_to_plane( double a[3], double b[3], double c[3], double p
        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;