simplify gitignore
[vg.git] / src / vg / vg_m.h
index 03f197f94b18003b731430a6ac2228ce38eb2b62..8e49fe55e330f4adb99d2291ae552c56fbf55274 100644 (file)
@@ -188,7 +188,14 @@ static inline void v2_lerp( v2f a, v2f b, float t, v2f d )
 
 static inline void v2_normalize( v2f a )
 {
-       v2_muls( a, 1.f / v2_length( a ), a );
+       v2_muls( a, 1.0f / v2_length( a ), a );
+}
+
+static void v2_normalize_clamp( v2f a )
+{
+   float l2 = v2_length2( a );
+   if( l2 > 1.0f )
+      v2_muls( a, 1.0f/sqrtf(l2), a );
 }
 
 static inline void v2_floor( v2f a, v2f b )
@@ -298,6 +305,19 @@ static inline float vg_lerpf( float a, float b, float t )
        return a + t*(b-a);
 }
 
+static inline double vg_lerp( double a, double b, double t )
+{
+       return a + t*(b-a);
+}
+
+/* correctly lerp around circular period -pi -> pi */
+static float vg_alerpf( float a, float b, float t )
+{
+   float d = fmodf( b-a, VG_TAUf ),
+         s = fmodf( 2.0f*d, VG_TAUf ) - d;
+   return a + s*t;
+}
+
 static inline void v3_lerp( v3f a, v3f b, float t, v3f d )
 {
        d[0] = a[0] + t*(b[0]-a[0]);
@@ -1209,7 +1229,14 @@ static inline void q_inv( v4f q, v4f d )
 
 static inline void q_nlerp( v4f a, v4f b, float t, v4f d )
 {
-   v4_lerp( a, b, t, d );
+   if( v4_dot(a,b) < 0.0f )
+   {
+      v4_muls( b, -1.0f, d );
+      v4_lerp( a, d, t, d );
+   }
+   else
+      v4_lerp( a, b, t, d );
+
    q_normalize( d );
 }