| 872 | } |
| 873 | |
| 874 | void render(int anim, int varseed, float speed, int basetime, dynent *d) |
| 875 | { |
| 876 | if(meshes.empty()) return; |
| 877 | animstate as; |
| 878 | if(!calcanimstate(anim, varseed, speed, basetime, d, as)) return; |
| 879 | |
| 880 | if(!meshes[0]->dynidx) genstrips(); |
| 881 | |
| 882 | anpos prev, cur; |
| 883 | cur.setframes(d && index<2 ? d->current[index] : as); |
| 884 | |
| 885 | float ai_t = 0; |
| 886 | bool doai = !(anim&ANIM_NOINTERP) && d && index<2 && lastmillis-d->lastanimswitchtime[index]<animationinterpolationtime && d->prev[index].range>0; |
| 887 | if(doai) |
| 888 | { |
| 889 | prev.setframes(d->prev[index]); |
| 890 | ai_t = (lastmillis-d->lastanimswitchtime[index])/(float)animationinterpolationtime; |
| 891 | } |
| 892 | |
| 893 | glPushMatrix(); |
| 894 | glMultMatrixf(matrixstack[matrixpos].v); |
| 895 | loopv(meshes) meshes[i]->render(as, cur, doai ? &prev : NULL, ai_t); |
| 896 | glPopMatrix(); |
| 897 | |
| 898 | loopi(numtags) |
| 899 | { |
| 900 | linkedpart &link = links[i]; |
| 901 | if(!(link.p || link.pos || (anim&ANIM_PARTICLE && link.emitter))) continue; |
| 902 | |
| 903 | // render the linked models - interpolate rotation and position of the 'link-tags' |
| 904 | glmatrixf linkmat; |
| 905 | gentagmatrix(cur, doai ? &prev : NULL, ai_t, i, linkmat.v); |
| 906 | |
| 907 | matrixpos++; |
| 908 | matrixstack[matrixpos].mul(matrixstack[matrixpos-1], linkmat); |
| 909 | |
| 910 | if(link.pos) *link.pos = matrixstack[matrixpos].gettranslation(); |
| 911 | |
| 912 | if(link.p) |
| 913 | { |
| 914 | vec oldshadowdir, oldshadowpos; |
| 915 | |
| 916 | if(stenciling) |
| 917 | { |
| 918 | oldshadowdir = shadowdir; |
| 919 | oldshadowpos = shadowpos; |
| 920 | linkmat.invertnormal(shadowdir); |
| 921 | linkmat.invertvertex(shadowpos); |
| 922 | } |
| 923 | |
| 924 | link.p->render(anim, varseed, speed, basetime, d); |
| 925 | |
| 926 | if(stenciling) |
| 927 | { |
| 928 | shadowdir = oldshadowdir; |
| 929 | shadowpos = oldshadowpos; |
| 930 | } |
| 931 | } |