X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=mathlib.c;h=dae0de50ba070a4f144e6830e47e5fa4da125700;hb=8b0fbc64175362acf3ea872029a423012b76a4f8;hp=cbd57db1d5d68458324733e17218a62cd512b8e4;hpb=c453c06f26904784393999a0173257258035bb11;p=xonotic%2Fdarkplaces.git diff --git a/mathlib.c b/mathlib.c index cbd57db1..dae0de50 100644 --- a/mathlib.c +++ b/mathlib.c @@ -523,8 +523,16 @@ void AnglesFromVectors (vec3_t angles, const vec3_t forward, const vec3_t up, qb { if (forward[0] == 0 && forward[1] == 0) { - angles[PITCH] = forward[2] > 0 ? -M_PI * 0.5 : M_PI * 0.5; - angles[YAW] = up ? atan2(-up[1], -up[0]) : 0; + if(forward[2] > 0) + { + angles[PITCH] = -M_PI * 0.5; + angles[YAW] = up ? atan2(-up[1], -up[0]) : 0; + } + else + { + angles[PITCH] = M_PI * 0.5; + angles[YAW] = up ? atan2(up[1], up[0]) : 0; + } angles[ROLL] = 0; } else @@ -748,3 +756,12 @@ void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f) } } +// LordHavoc: this has to be done right or you get severe precision breakdown +int LoopingFrameNumberFromDouble(double t, int loopframes) +{ + if (loopframes) + return (int)(t - floor(t/loopframes)*loopframes); + else + return (int)t; +} +