Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4161 in orxonox.OLD


Ignore:
Timestamp:
May 11, 2005, 9:44:17 AM (19 years ago)
Author:
patrick
Message:

orxonox/branchs/md2_model: startet working on animated md2 models. this version doesn't compile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.cc

    r4159 r4161  
    4646{
    4747  // delete what has to be deleted here
     48}
     49
     50
     51MD2Model::animateModel()
     52{
     53        if( unlikely(pModel->pObject.size() <= 0)) return;
     54        /* get current animation from the list */
     55        tAnimationInfo *pAnim = &(pModel->pAnimations[pModel->currentAnim]);
     56
     57        int nextFrame = (pModel->currentFrame + 1) % pAnim->endFrame;
     58        if( unlikely(nextFrame == 0))
     59                nextFrame =  pAnim->startFrame;
     60
     61        t3DObject *pFrame = &pModel->pObject[pModel->currentFrame];
     62        t3DObject *pNextFrame = &pModel->pObject[nextFrame];
     63
     64        /* we have stored the texture and face information only in the first frame */
     65        t3DObject *pFirstFrame = &pModel->pObject[0];
     66
     67        /* get the current time as a value in the domain [0..1] :)) */
     68        float t = ReturnCurrentTime(pModel, nextFrame);
     69
     70        glBegin(g_ViewMode);
     71                for(int j = 0; j < pFrame->numOfFaces; j++)
     72                {
     73                        for(int whichVertex = 0; whichVertex < 3; whichVertex++)
     74                        {
     75                                int vertIndex = pFirstFrame->pFaces[j].vertIndex[whichVertex];
     76                                int texIndex  = pFirstFrame->pFaces[j].coordIndex[whichVertex];
     77                                               
     78                                if( likely(pFirstFrame->pTexVerts != NULL))
     79                                {
     80                                        glTexCoord2f(pFirstFrame->pTexVerts[ texIndex ].x,
     81                                                                 pFirstFrame->pTexVerts[ texIndex ].y);
     82                                }
     83                       
     84                                /* here comes the interpolation part */
     85                                CVector3 vPoint1 = pFrame->pVerts[vertIndex];
     86                                CVector3 vPoint2 = pNextFrame->pVerts[vertIndex];
     87                                glVertex3f(vPoint1.x + t * (vPoint2.x - vPoint1.x),
     88                                                   vPoint1.y + t * (vPoint2.y - vPoint1.y),
     89                                                   vPoint1.z + t * (vPoint2.z - vPoint1.z));
     90                        }
     91                }
     92        glEnd();
     93}
     94
     95
     96float MD2Model::returnCurrentTime(t3DModel *pModel, int nextFrame)
     97{
     98        static float elapsedTime   = 0.0f;
     99        static float lastTime     = 0.0f;
     100
     101        /* this is the same like tick(float time) */
     102        //float time = GetTickCount();
     103        //elapsedTime = time - lastTime;
     104       
     105        /* stretch the time with animation speed (and make seconds out of it) */
     106        float t = elapsedTime / (1000.0f / kAnimationSpeed);
     107       
     108        if (elapsedTime >= (1000.0f / kAnimationSpeed) )
     109        {
     110                pModel->currentFrame = nextFrame;
     111                lastTime = time;
     112        }
     113        return t;
    48114}
    49115
Note: See TracChangeset for help on using the changeset viewer.