r745 - trunk

lordhavoc at icculus.org lordhavoc at icculus.org
Mon Jan 1 13:11:29 EST 2007


Author: lordhavoc
Date: 2007-01-01 13:11:29 -0500 (Mon, 01 Jan 2007)
New Revision: 745

Modified:
   trunk/modelanim.c
   trunk/modelanim.h
Log:
changed modelanim GetTransforms function (formerly called BlendPoses) to
take a 0 to 1 fraction as position in the animation, so that the game
code only needs to know the time (as a fraction) and the total play
time, no reference to frames


Modified: trunk/modelanim.c
===================================================================
--- trunk/modelanim.c	2007-01-01 17:55:58 UTC (rev 744)
+++ trunk/modelanim.c	2007-01-01 18:11:29 UTC (rev 745)
@@ -294,6 +294,8 @@
 	return modelanim->num_transforms;
 }
 
+#if 0
+// no real reason to expose these to the game, it doesn't care...
 NUint32 ModelAnim_GetNumFrames(NUint32 resourceindex)
 {
 	ModelAnim *modelanim;
@@ -311,11 +313,24 @@
 		return 0; // no modelanim
 	return modelanim->framerate;
 }
+#endif
 
-void ModelAnim_BlendPoses(NUint32 modelanimresource, NUint32 modelresource, NUint32 frame1, NUint32 frame2, float framelerp, matrix4x4_t *transforms, Nbool clearfirst)
+double ModelAnim_GetPlayTime(NUint32 resourceindex)
 {
+	ModelAnim *modelanim;
+	modelanim = Resource_GetData(resourceindex);
+	if (!modelanim)
+		return 0; // no modelanim
+	return modelanim->framerate * modelanim->numframes;
+}
+
+void ModelAnim_GetTransforms(NUint32 modelanimresource, NUint32 modelresource, Ndouble animtime, matrix4x4_t *transforms, Nbool clearfirst)
+{
 	NUint32 transformnum;
-	float iframelerp = 1 - framelerp;
+	NUint32 frame1, frame2;
+	float framelerp;
+	float frameilerp;
+	matrix4x4_t oldtransform;
 	const float *v1, *v2, *b;
 	Model *model;
 	ModelAnim *modelanim;
@@ -328,6 +343,15 @@
 		return; // no model
 	if (model->num_transforms != modelanim->num_transforms)
 		return; // error
+	// multiply the play time by framerate to find which frames to use
+	animtime *= modelanim->framerate;
+	frame1 = (NUint32)floor(animtime);
+	frame2 = frame1 + 1;
+	framelerp = Bound(0, animtime - frame1, 1);
+	frameilerp = 1 - framelerp;
+	// bound the frame indices to prevent crashes if there is no such frame
+	frame1 = Bound(0, frame1, modelanim->numframes - 1);
+	frame2 = Bound(0, frame2, modelanim->numframes - 1);
 	v1 = modelanim->values + frame1 * modelanim->numvaluesperframe;
 	v2 = modelanim->values + frame2 * modelanim->numvaluesperframe;
 	b = modelanim->basevalues;
@@ -342,11 +366,23 @@
 		for (component = 0;component < 6;component++)
 		{
 			if (valueflags & (1<<component))
-				pose[component] = *f1++ * iframelerp + *f2++ * framelerp;
+				pose[component] = *f1++ * frameilerp + *f2++ * framelerp;
 			else
 				pose[component] = b[component];
 		}
 		Matrix4x4_CreateFromDoom3Joint(&posematrix, pose[0], pose[1], pose[2], pose[3], pose[4], pose[5]);
-		Matrix4x4_Concat(&relativematrix, &posematrix, &model->data_transforminfo[transformnum].baseinversematrix);
+		if (clearfirst)
+			transforms[transformnum] = posematrix;
+		else
+		{
+			// concatenate the deformation this pose matrix represents, as an
+			// additional transform
+			// (this allows applying multiple animations affecting different
+			//  parts of a model, without conflicts)
+			// FIXME: test if this works!  (swap Concat parameters if necessary)
+			Matrix4x4_Concat(&relativematrix, &posematrix, &model->data_transforminfo[transformnum].baseinversematrix);
+			oldtransform = transforms[transformnum];
+			Matrix4x4_Concat(&transforms[transformnum], &oldtransform, &relativematrix);
+		}
 	}
 }

Modified: trunk/modelanim.h
===================================================================
--- trunk/modelanim.h	2007-01-01 17:55:58 UTC (rev 744)
+++ trunk/modelanim.h	2007-01-01 18:11:29 UTC (rev 745)
@@ -32,4 +32,5 @@
 void ModelAnim_Unload(ResourceEntry *r);
 
 NUint32 ModelAnim_GetNumTransforms(NUint32 resourceindex);
-void ModelAnim_GetTransforms(NUint32 resourceindex, NUint32 frame1, NUint32 frame2, float framelerp, matrix4x4_t *transforms);
+void ModelAnim_GetTransforms(NUint32 modelanimresource, NUint32 modelresource, Ndouble animtime, matrix4x4_t *transforms, Nbool clearfirst);
+double ModelAnim_GetPlayTime(NUint32 resourceindex);




More information about the neither-commits mailing list