Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

tr_animation.c File Reference

#include "tr_local.h"

Include dependency graph for tr_animation.c:

Include dependency graph

Go to the source code of this file.

Functions

void R_AddAnimSurfaces (trRefEntity_t *ent)
void RB_SurfaceAnim (md4Surface_t *surface)


Function Documentation

void R_AddAnimSurfaces trRefEntity_t ent  ) 
 

Definition at line 41 of file tr_animation.c.

References byte, trGlobals_t::currentModel, header, i, model_s::md4, md4LOD_t::numSurfaces, md4LOD_t::ofsSurfaces, qfalse, R_AddDrawSurf(), R_GetShaderByHandle(), shader_t, md4Surface_t::shaderIndex, and tr.

Referenced by R_AddEntitySurfaces().

00041                                              {
00042     md4Header_t     *header;
00043     md4Surface_t    *surface;
00044     md4LOD_t        *lod;
00045     shader_t        *shader;
00046     int             i;
00047 
00048     header = tr.currentModel->md4;
00049     lod = (md4LOD_t *)( (byte *)header + header->ofsLODs );
00050 
00051     surface = (md4Surface_t *)( (byte *)lod + lod->ofsSurfaces );
00052     for ( i = 0 ; i < lod->numSurfaces ; i++ ) {
00053         shader = R_GetShaderByHandle( surface->shaderIndex );
00054         R_AddDrawSurf( (void *)surface, shader, 0 /*fogNum*/, qfalse );
00055         surface = (md4Surface_t *)( (byte *)surface + surface->ofsEnd );
00056     }
00057 }

Here is the call graph for this function:

void RB_SurfaceAnim md4Surface_t surface  ) 
 

Definition at line 65 of file tr_animation.c.

References backEnd, refEntity_t::backlerp, md4Weight_t::boneIndex, md4Frame_t::bones, md4Weight_t::boneWeight, byte, backEndState_t::currentEntity, DotProduct, trRefEntity_t::e, refEntity_t::frame, header, i, shaderCommands_s::indexes, j, k, md4Bone_t::matrix, md4Vertex_t::normal, shaderCommands_s::normal, shaderCommands_s::numIndexes, md4Surface_t::numTriangles, shaderCommands_s::numVertexes, md4Surface_t::numVerts, md4Vertex_t::numWeights, md4Weight_t::offset, md4Surface_t::ofsHeader, md4Surface_t::ofsTriangles, md4Surface_t::ofsVerts, refEntity_t::oldframe, RB_CheckOverflow(), tess, shaderCommands_s::texCoords, md4Vertex_t::texCoords, v, vec3_t, VectorClear, w, md4Vertex_t::weights, and shaderCommands_s::xyz.

00065                                              {
00066     int             i, j, k;
00067     float           frontlerp, backlerp;
00068     int             *triangles;
00069     int             indexes;
00070     int             baseIndex, baseVertex;
00071     int             numVerts;
00072     md4Vertex_t     *v;
00073     md4Bone_t       bones[MD4_MAX_BONES];
00074     md4Bone_t       *bonePtr, *bone;
00075     md4Header_t     *header;
00076     md4Frame_t      *frame;
00077     md4Frame_t      *oldFrame;
00078     int             frameSize;
00079 
00080 
00081     if (  backEnd.currentEntity->e.oldframe == backEnd.currentEntity->e.frame ) {
00082         backlerp = 0;
00083         frontlerp = 1;
00084     } else  {
00085         backlerp = backEnd.currentEntity->e.backlerp;
00086         frontlerp = 1.0f - backlerp;
00087     }
00088     header = (md4Header_t *)((byte *)surface + surface->ofsHeader);
00089 
00090     frameSize = (int)( &((md4Frame_t *)0)->bones[ header->numBones ] );
00091 
00092     frame = (md4Frame_t *)((byte *)header + header->ofsFrames + 
00093         backEnd.currentEntity->e.frame * frameSize );
00094     oldFrame = (md4Frame_t *)((byte *)header + header->ofsFrames + 
00095         backEnd.currentEntity->e.oldframe * frameSize );
00096 
00097     RB_CheckOverflow( surface->numVerts, surface->numTriangles * 3 );
00098 
00099     triangles = (int *) ((byte *)surface + surface->ofsTriangles);
00100     indexes = surface->numTriangles * 3;
00101     baseIndex = tess.numIndexes;
00102     baseVertex = tess.numVertexes;
00103     for (j = 0 ; j < indexes ; j++) {
00104         tess.indexes[baseIndex + j] = baseIndex + triangles[j];
00105     }
00106     tess.numIndexes += indexes;
00107 
00108     //
00109     // lerp all the needed bones
00110     //
00111     if ( !backlerp ) {
00112         // no lerping needed
00113         bonePtr = frame->bones;
00114     } else {
00115         bonePtr = bones;
00116         for ( i = 0 ; i < header->numBones*12 ; i++ ) {
00117             ((float *)bonePtr)[i] = frontlerp * ((float *)frame->bones)[i]
00118                 + backlerp * ((float *)oldFrame->bones)[i];
00119         }
00120     }
00121 
00122     //
00123     // deform the vertexes by the lerped bones
00124     //
00125     numVerts = surface->numVerts;
00126     // FIXME
00127     // This makes TFC's skeletons work.  Shouldn't be necessary anymore, but left
00128     // in for reference.
00129     //v = (md4Vertex_t *) ((byte *)surface + surface->ofsVerts + 12);
00130     v = (md4Vertex_t *) ((byte *)surface + surface->ofsVerts);
00131     for ( j = 0; j < numVerts; j++ ) {
00132         vec3_t  tempVert, tempNormal;
00133         md4Weight_t *w;
00134 
00135         VectorClear( tempVert );
00136         VectorClear( tempNormal );
00137         w = v->weights;
00138         for ( k = 0 ; k < v->numWeights ; k++, w++ ) {
00139             bone = bonePtr + w->boneIndex;
00140 
00141             tempVert[0] += w->boneWeight * ( DotProduct( bone->matrix[0], w->offset ) + bone->matrix[0][3] );
00142             tempVert[1] += w->boneWeight * ( DotProduct( bone->matrix[1], w->offset ) + bone->matrix[1][3] );
00143             tempVert[2] += w->boneWeight * ( DotProduct( bone->matrix[2], w->offset ) + bone->matrix[2][3] );
00144 
00145             tempNormal[0] += w->boneWeight * DotProduct( bone->matrix[0], v->normal );
00146             tempNormal[1] += w->boneWeight * DotProduct( bone->matrix[1], v->normal );
00147             tempNormal[2] += w->boneWeight * DotProduct( bone->matrix[2], v->normal );
00148         }
00149 
00150         tess.xyz[baseVertex + j][0] = tempVert[0];
00151         tess.xyz[baseVertex + j][1] = tempVert[1];
00152         tess.xyz[baseVertex + j][2] = tempVert[2];
00153 
00154         tess.normal[baseVertex + j][0] = tempNormal[0];
00155         tess.normal[baseVertex + j][1] = tempNormal[1];
00156         tess.normal[baseVertex + j][2] = tempNormal[2];
00157 
00158         tess.texCoords[baseVertex + j][0][0] = v->texCoords[0];
00159         tess.texCoords[baseVertex + j][0][1] = v->texCoords[1];
00160 
00161         // FIXME
00162         // This makes TFC's skeletons work.  Shouldn't be necessary anymore, but left
00163         // in for reference.
00164         //v = (md4Vertex_t *)( ( byte * )&v->weights[v->numWeights] + 12 );
00165         v = (md4Vertex_t *)&v->weights[v->numWeights];
00166     }
00167 
00168     tess.numVertexes += surface->numVerts;
00169 }

Here is the call graph for this function:


Generated on Thu Aug 25 14:57:44 2005 for Quake III Arena by  doxygen 1.3.9.1