From: havoc Date: Mon, 23 May 2011 15:46:32 +0000 (+0000) Subject: added LoopingFrameNumberFromDouble function to do this operation X-Git-Tag: xonotic-v0.6.0~163^2~383 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6bb2c4cecb8a4e633fc0faf90c939fc180f7163b;p=xonotic%2Fdarkplaces.git added LoopingFrameNumberFromDouble function to do this operation correctly (using divide, floor, and multiply), since doing it the lazy way (cast to int, use modulus operator) breaks down after a certain amount of time in the level git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11163 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/mathlib.c b/mathlib.c index d6170d28..dae0de50 100644 --- a/mathlib.c +++ b/mathlib.c @@ -756,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; +} + diff --git a/mathlib.h b/mathlib.h index b3a9f7ea..e1c7f647 100644 --- a/mathlib.h +++ b/mathlib.h @@ -291,5 +291,7 @@ int Math_atov(const char *s, vec3_t out); void BoxFromPoints(vec3_t mins, vec3_t maxs, int numpoints, vec_t *point3f); +int LoopingFrameNumberFromDouble(double t, int loopframes); + #endif