- Timestamp:
- May 11, 2005, 9:58:06 AM (20 years ago)
- 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 49 49 50 50 51 MD2Model::animateModel()52 { 53 if( unlikely(pModel->pObject.size() <= 0)) return;54 55 tAnimationInfo *pAnim = &(pModel->pAnimations[pModel->currentAnim]);56 57 58 59 60 61 t3DObject *pFrame = &pModel->pObject[pModel->currentFrame];62 t3DObject *pNextFrame = &pModel->pObject[nextFrame];63 64 65 t3DObject *pFirstFrame = &pModel->pObject[0];66 67 68 float t = ReturnCurrentTime(pModel, nextFrame);69 70 glBegin(g_ViewMode);71 72 73 74 75 76 51 void 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]; 77 77 78 79 80 81 82 78 if( likely(pFirstFrame->pTexVerts != NULL)) 79 { 80 glTexCoord2f(pFirstFrame->pTexVerts[ texIndex ].x, 81 pFirstFrame->pTexVerts[ texIndex ].y); 82 } 83 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 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 96 float 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 107 void MD2Model::tick(float dtS) 108 { 109 /* TEMP TEMP TEMP: save the current step length */ 110 this->dtS = dtS; 114 111 } 115 112 -
orxonox/branches/md2_loader/src/lib/graphics/importer/md2Model.h
r4147 r4162 124 124 void setAnim(int type); 125 125 void scaleModel(float s); 126 127 void tick(float dtS); 126 128 127 129 private: 128 void animate( float time);130 void animate(/*float time*/ t3DModel *pModel); 129 131 void processLightning(); 130 132 void interpolate(CVector3* vertlist); 131 133 void renderFrame(); 134 float getCurrentTime(t3DModel *pModel, int nextFrame); 135 136 float dtS; 132 137 }; 133 138
Note: See TracChangeset
for help on using the changeset viewer.