4 // LordHavoc: quite tempting to break apart this function to reuse the
5 // duplicated code, but I suspect it is better for performance
7 void R_LerpAnimation(model_t *mod, int frame1, int frame2, double frame1start, double frame2start, double framelerp, frameblend_t *blend)
9 int sub1, sub2, numframes, f, i, data;
10 double sublerp, lerp, l;
11 animscene_t *scene, *scenes;
13 data = (int) Mod_Extradata(mod);
15 Host_Error("R_LerpAnimation: model not loaded\n");
16 scenes = (animscene_t *) (mod->ofs_scenes + data);
18 numframes = mod->numframes;
20 if ((frame1 >= numframes))
22 Con_Printf ("R_LerpAnimation: no such frame %d\n", frame1);
26 if ((frame2 >= numframes))
28 Con_Printf ("R_LerpAnimation: no such frame %d\n", frame2);
33 Host_Error ("R_LerpAnimation: frame1 is NULL\n");
35 // round off very close blend percentages
36 if (framelerp < (1.0f / 65536.0f))
38 if (framelerp >= (65535.0f / 65536.0f))
41 blend[0].frame = blend[1].frame = blend[2].frame = blend[3].frame = -1;
42 blend[0].lerp = blend[1].lerp = blend[2].lerp = blend[3].lerp = 0;
45 scene = scenes + frame1;
48 if (scene->framecount > 1)
50 sublerp = scene->framerate * (cl.time - frame1start);
51 sub1 = (int) (sublerp);
54 if (sublerp < (1.0f / 65536.0f))
56 if (sublerp >= (65535.0f / 65536.0f))
60 sub1 = (sub1 % scene->framecount) + scene->firstframe;
61 sub2 = (sub2 % scene->framecount) + scene->firstframe;
65 sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe;
66 sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe;
69 l = (1 - sublerp) * lerp;
74 if (blend[i].frame == f)
79 if (blend[i].lerp <= 0)
92 f = scene->firstframe;
99 if (blend[i].frame == f)
104 if (blend[i].lerp <= 0)
113 if (framelerp > 0 && frame2 >= 0)
115 scene = scenes + frame2;
118 if (scene->framecount > 1)
120 sublerp = scene->framerate * (cl.time - frame1start);
121 sub1 = (int) (sublerp);
124 if (sublerp < (1.0f / 65536.0f))
126 if (sublerp >= (65535.0f / 65536.0f))
130 sub1 = (sub1 % scene->framecount) + scene->firstframe;
131 sub2 = (sub2 % scene->framecount) + scene->firstframe;
135 sub1 = bound(0, sub1, (scene->framecount - 1)) + scene->firstframe;
136 sub2 = bound(0, sub2, (scene->framecount - 1)) + scene->firstframe;
139 l = (1 - sublerp) * lerp;
142 for (i = 0;i < 4;i++)
144 if (blend[i].frame == f)
149 if (blend[i].lerp <= 0)
162 f = scene->firstframe;
167 for (i = 0;i < 4;i++)
169 if (blend[i].frame == f)
174 if (blend[i].lerp <= 0)