Changeset 5085 in orxonox.OLD for trunk/src/lib/graphics/importer
- Timestamp:
- Aug 20, 2005, 3:37:12 PM (19 years ago)
- Location:
- trunk/src/lib/graphics/importer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/importer/md2Model.cc
r5075 r5085 169 169 glPushMatrix(); 170 170 171 this->renderFrame(); 171 this->renderFrameGLList(); 172 // this->renderFrameTriangles(); 172 173 173 174 glPopMatrix(); … … 178 179 \brief this is an internal function to render this special frame selected by animate() 179 180 */ 180 void MD2Model::renderFrame ()181 void MD2Model::renderFrameGLList() 181 182 { 182 183 static sVec3D verticesList[MD2_MAX_VERTICES]; /* performance: created only once in a lifetime */ … … 209 210 for(; i > 0; i--, pCommands += 3) /* down counting for loop, next 3 gl commands */ 210 211 { 212 verticesList[pCommands[2]][2]); 211 213 glTexCoord2f( ((float *)pCommands)[0], ((float *)pCommands)[1] ); 212 214 glNormal3fv(anorms[this->data->pLightNormals[pCommands[2]]]); … … 216 218 217 219 } 220 glDisable(GL_CULL_FACE); 221 glPopAttrib(); 222 } 223 224 225 /** 226 * renders the frame using triangles 227 */ 228 void MD2Model::renderFrameTriangles() 229 { 230 static sVec3D verticesList[MD2_MAX_VERTICES]; /* performance: created only once in a lifetime */ 231 int* pCommands = this->data->pGLCommands; 232 233 /* some face culling stuff */ 234 glPushAttrib(GL_POLYGON_BIT); 235 glFrontFace(GL_CW); 236 glEnable(GL_CULL_FACE); 237 glCullFace(GL_BACK); 238 239 this->processLighting(); 240 this->interpolate(verticesList); 241 this->data->material->select(); 242 243 /* draw the triangles */ 244 glBegin(GL_TRIANGLES); 245 246 for( int i = 0, k = 0; i < this->data->numTriangles; ++i, k += 3) 247 { 248 printf("%i: (%f, %f)\n", i, (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[2]].s, (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[2]].t); 249 250 glTexCoord2f((float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[0]].s, 251 (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[0]].t); 252 //glNormal3f(Md2Model.normal[i].x, Md2Model.normal[i].y, Md2Model.normal[i].z); 253 glVertex3fv(verticesList[this->data->pTriangles[i].indexToVertices[0]]); 254 255 glTexCoord2f((float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[1]].s, 256 (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[1]].t); 257 258 // glNormal3f(Md2Model.normal[i].x, Md2Model.normal[i].y, Md2Model.normal[i].z); 259 glVertex3fv(verticesList[this->data->pTriangles[i].indexToVertices[1]]); 260 261 glTexCoord2f((float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[2]].s, 262 (float)this->data->pTexCoor[this->data->pTriangles[i].indexToTexCoor[2]].t); 263 // glNormal3f(Md2Model.normal[i].x, Md2Model.normal[i].y, Md2Model.normal[i].z); 264 glVertex3fv(verticesList[this->data->pTriangles[i].indexToVertices[2]]); 265 } 266 267 glEnd(); 268 269 218 270 glDisable(GL_CULL_FACE); 219 271 glPopAttrib(); … … 288 340 this->pGLCommands = NULL; 289 341 this->pLightNormals = NULL; 342 this->pTexCoor = NULL; 290 343 291 344 this->numFrames = 0; 292 345 this->numVertices = 0; 293 346 this->numGLCommands = 0; 347 this->numTexCoor = 0; 294 348 295 349 this->scaleFactor = 0.2f; … … 313 367 delete [] this->pGLCommands; 314 368 delete [] this->pLightNormals; 369 delete [] this->pTexCoor; 315 370 316 371 delete this->material; … … 354 409 this->numTriangles = this->header->numTriangles; 355 410 this->numGLCommands = this->header->numGlCommands; 411 this->numTexCoor = this->header->numTexCoords; 356 412 /* allocate memory for the data storage */ 357 413 this->pVertices = new sVec3D[this->numVertices * this->numFrames]; … … 359 415 this->pLightNormals = new int[this->numVertices * this->numFrames]; 360 416 this->pTriangles = new sTriangle[this->numTriangles]; 417 this->pTexCoor = new sTexCoor[this->numTexCoor]; 361 418 buffer = new char[this->numFrames * this->header->frameSize]; 362 363 /*364 TriangleList = new stTriangleIndice[md2Header.numTriangles];365 366 // Next extract the data by moving to the spot in the data where the triangle data start.367 stTriangleIndice *pTriList;368 369 // Get the data.370 pTriList = (stTriangleIndice*)&buffer[md2Header.offsetTriangles];371 372 // Now we pretty much store the data in our TriangleList object.373 for(i = 0; i < md2Header.numTriangles; i++)374 {375 TriangleList[i].triIndex[0] = pTriList[i].triIndex[0];376 TriangleList[i].triIndex[1] = pTriList[i].triIndex[1];377 TriangleList[i].triIndex[2] = pTriList[i].triIndex[2];378 TriangleList[i].texCoordIndex[0] = pTriList[i].texCoordIndex[0];379 TriangleList[i].texCoordIndex[1] = pTriList[i].texCoordIndex[1];380 TriangleList[i].texCoordIndex[2] = pTriList[i].texCoordIndex[2];381 }382 */383 384 385 419 386 420 … … 394 428 fseek(pFile, this->header->offsetTriangles, SEEK_SET); 395 429 fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile); 430 /* read in texture coordinates */ 431 fseek(pFile, this->header->offsetTexCoords, SEEK_SET); 432 fread(this->pTexCoor, sizeof(sTexCoor), this->numTexCoor, pFile); 433 for( int i = 0; i < this->numTexCoor; ++i) 434 { 435 printf("%i: (%i, %i)\n", i, this->pTexCoor[i].s, this->pTexCoor[i].t); 436 } 396 437 397 438 for(int i = 0; i < this->numFrames; ++i) -
trunk/src/lib/graphics/importer/md2Model.h
r5039 r5085 66 66 67 67 68 68 69 //! animation names enumeration 69 70 typedef enum animType … … 116 117 int numVertices; //!< number of vertices 117 118 int numTriangles; //!< number of triangles 119 int numTexCoor; //!< number of texture coordinates 118 120 int numGLCommands; //!< number of gl commands in the glList (tells how to draw) 119 121 char* fileName; //!< file name of the model File … … 123 125 sVec3D* pVertices; //!< pointer to the vertices data block 124 126 sTriangle* pTriangles; //!< pointer to the triangles data 127 sTexCoor* pTexCoor; //!< pointer to the texture coordinate data 125 128 int* pGLCommands; //!< pointer to the gllist data block 126 129 int* pLightNormals; //!< pointer to the light normals … … 129 132 float scaleFactor; //!< the scale factor of the model, (global) 130 133 }; 134 135 131 136 132 137 … … 155 160 void processLighting(); 156 161 void interpolate(sVec3D* verticesList); 157 void renderFrame(); 162 void renderFrameGLList(); 163 void renderFrameTriangles(); 158 164 159 165 public:
Note: See TracChangeset
for help on using the changeset viewer.