Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4162 in orxonox.OLD for orxonox/branches


Ignore:
Timestamp:
May 11, 2005, 9:58:06 AM (20 years ago)
Author:
patrick
Message:

orxonox/branches/md2_importer: reimplemented the animation functions, compiles again

Location:
orxonox/branches/md2_loader/src/lib/graphics/importer
Files:
2 edited

Legend:

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

    r4161 r4162  
    4949
    5050
    51 MD2Model::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];
     51void MD2Model::animate(t3DModel *pModel)
     52{
     53  if( unlikely(pModel->objectList.size() <= 0)) return;
     54  /* get current animation from the list */
     55  tAnimationInfo *pAnim = &(pModel->animationList[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->objectList[pModel->currentFrame];
     62  t3DObject *pNextFrame = &pModel->objectList[nextFrame];
     63
     64  /* we have stored the texture and face information only in the first frame */
     65  t3DObject *pFirstFrame = &pModel->objectList[0];
     66
     67  /* get the current time as a value in the domain [0..1] :)) */
     68  float t = this->getCurrentTime(pModel, nextFrame);
     69
     70  glBegin(GL_TRIANGLES);
     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];
    7777                                               
    78                                 if( likely(pFirstFrame->pTexVerts != NULL))
    79                                 {
    80                                         glTexCoord2f(pFirstFrame->pTexVerts[ texIndex ].x,
    81                                                                 pFirstFrame->pTexVerts[ texIndex ].y);
    82                                 }
     78          if( likely(pFirstFrame->pTexVerts != NULL))
     79            {
     80              glTexCoord2f(pFirstFrame->pTexVerts[ texIndex ].x,
     81                          pFirstFrame->pTexVerts[ texIndex ].y);
     82            }
    8383                       
    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 
    96 float 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;
     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::getCurrentTime(t3DModel *pModel, int nextFrame)
     97{
     98  /* stretch the time with animation speed (and make seconds out of it) */
     99  float t = this->dtS / (1000.0f / kAnimationSpeed);
     100       
     101  if ( unlikely(this->dtS >= (1000.0f / kAnimationSpeed)) )
     102      pModel->currentFrame = nextFrame;
     103  return t;
     104}
     105
     106
     107void MD2Model::tick(float dtS)
     108{
     109  /* TEMP TEMP TEMP: save the current step length */
     110  this->dtS = dtS;
    114111}
    115112
  • orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.h

    r4147 r4162  
    124124  void setAnim(int type);
    125125  void scaleModel(float s);
     126
     127  void tick(float dtS);
    126128 
    127129private:
    128   void animate(float time);
     130  void animate(/*float time*/ t3DModel *pModel);
    129131  void processLightning();
    130132  void interpolate(CVector3* vertlist);
    131133  void renderFrame();
     134  float getCurrentTime(t3DModel *pModel, int nextFrame);
     135
     136  float dtS;
    132137};
    133138
Note: See TracChangeset for help on using the changeset viewer.