]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
added LoopingFrameNumberFromDouble function to do this operation
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 23 May 2011 15:46:32 +0000 (15:46 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 23 May 2011 15:46:32 +0000 (15:46 +0000)
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

mathlib.c
mathlib.h

index d6170d28977c27645f71b9987887854670d34916..dae0de50ba070a4f144e6830e47e5fa4da125700 100644 (file)
--- 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;
+}
+
index b3a9f7ea3c319b80f01ab78d1c5b09e0eebeac7e..e1c7f647d8eb17f90d1fd9065fc9c48dd432071e 100644 (file)
--- 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