From fde75b49095458f8c405fef8c5550675f7e65761 Mon Sep 17 00:00:00 2001 From: divverent Date: Thu, 4 Sep 2008 09:28:23 +0000 Subject: [PATCH] fix the mathlib corner case vectoangles2('0 0 -1', '...') git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@8491 d7cf8633-e32d-0410-b094-e92efae38249 --- mathlib.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mathlib.c b/mathlib.c index cbd57db1..d6170d28 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 -- 2.39.2