X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=blobdiff_plain;f=vg_m.h;h=46cf38c173d09111ed17fc86176707ece7249845;hp=6d86177894e97f75273c7f67e9c6b4be0bd0e2e2;hb=52405ee9bf46dc91dd15f2ce06f5e84004a0d31f;hpb=3f8eb36bc705028519cd9e047b24f9b0e97f368e diff --git a/vg_m.h b/vg_m.h index 6d86177..46cf38c 100644 --- a/vg_m.h +++ b/vg_m.h @@ -540,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] ); +} /* * -----------------------------------------------------------------------------