jdidjjjjjjjjjjjjjjjjjjjjjj
[vg.git] / src / vg / vg_m.h
index 03f197f94b18003b731430a6ac2228ce38eb2b62..0736752364113b85a711349926d3df5208e22f2a 100644 (file)
@@ -298,6 +298,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 +1222,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 );
 }