msgdump tool
[vg.git] / vg_m.h
diff --git a/vg_m.h b/vg_m.h
index 4fe4590f944cae4d614e8577ea532998d49e82fa..46cf38c173d09111ed17fc86176707ece7249845 100644 (file)
--- a/vg_m.h
+++ b/vg_m.h
@@ -107,6 +107,15 @@ static inline f32 vg_rad( f32 deg )
    return deg * VG_PIf / 180.0f;
 }
 
+/* angle to reach b from a */
+static f32 vg_angle_diff( f32 a, f32 b ){
+   f32 d = fmod(b,VG_TAUf)-fmodf(a,VG_TAUf);
+   if( fabsf(d) > VG_PIf )
+      d = -vg_signf(d) * (VG_TAUf - fabsf(d));
+
+   return d;
+}
+
 /*
  * quantize float to bit count
  */
@@ -531,6 +540,34 @@ static void v3_tangent_basis( v3f n, v3f tx, v3f ty ){
    v3_cross( n, tx, ty );
 }
 
+/*
+ * Compute yaw and pitch based of a normalized vector representing forward
+ * forward: -z
+ * result -> (YAW,PITCH,0.0)
+ */
+static void v3_angles( v3f v, v3f out_angles ){
+   float yaw = atan2f( v[0], -v[2] ),
+       pitch = atan2f( 
+                   -v[1], 
+                   sqrtf(
+                     v[0]*v[0] + v[2]*v[2]
+                   )
+               );
+
+   out_angles[0] = yaw;
+   out_angles[1] = pitch;
+   out_angles[2] = 0.0f;
+}
+
+/*
+ * Compute the forward vector from (YAW,PITCH,ROLL)
+ * forward: -z
+ */
+static void v3_angles_vector( v3f angles, v3f out_v ){
+   out_v[0] =  sinf( angles[0] ) * cosf( angles[1] );
+   out_v[1] = -sinf( angles[1] );
+   out_v[2] = -cosf( angles[0] ) * cosf( angles[1] );
+}
 
 /*
  * -----------------------------------------------------------------------------
@@ -690,6 +727,10 @@ static void q_mulv( v4f q, v3f v, v3f d )
    v3_add( v1, v2, d );
 }
 
+static f32 q_dist( v4f q0, v4f q1 ){
+   return acosf( 2.0f * v4_dot(q0,q1) -1.0f );
+}
+
 /*
  * -----------------------------------------------------------------------------
  * Section 4.a                  2x2 matrices