![Image](http://img221.imageshack.us/img221/8485/screenshotgy9vi5.jpg)
Any ideas on what is happening to the model? (It's the sydney model from Irrlicht's media folder...)
I'm rendering it with the MD2 GL Commands, but I get the same result if I use the Triangle data :-/ ...
Code: Select all
std::ifstream file(fileName.c_str(), std::ios::binary);
int magicNum;
int version;
//
int texW, texH;
//
file.read((char*)(&magicNum), 4);
file.read((char*)(&version), 4);
(rust::cLogfileManager::getInstance())->writeToLog("Opening MD2 File...");
if ((magicNum == MD2_MAGICNUM) && (version == 8)) {
(rust::cLogfileManager::getInstance())->writeToLog("Opened MD2 File...");
file.read((char*)(&texW), 4);
file.read((char*)(&texH), 4);
file.seekg(24); //Go to number of vertices in frame...
file.read((char*)(&this->vertPerFrame), 4); // read verticies in frame...
file.read((char*)(&this->numTexCoords), 4); //read number of tex coordinates in model
file.read((char*)(&this->numTriangles), 4);
file.seekg(36); //Go to number of GLCommands
file.read((char*)(&this->numGLCommands), 4); // read number of GLCommands
file.read((char*)(&this->numFrames), 4); //readnumber of frames
int texCoordOffset, frameOffset, glCmdOffset;
file.seekg(48); //Go to offset for tex coords;
file.read((char*)(&texCoordOffset), 4); // read offset to tex coords
file.seekg(56);
file.read((char*)(&frameOffset), 4); //read offset to verts, frames
file.read((char*)(&glCmdOffset), 4); //read offset to glCommands
/////////////////////////
///////Read DATA/////////
/////////////////////////
//1. Tex Coords
file.seekg(texCoordOffset);
this->texCoords = new rust::cVector2f[this->numTexCoords];
for(int i = 0; i < this->numTexCoords; i++){
short U;
short V;
file.read((char*)(&U), 2);
file.read((char*)(&V), 2);
this->texCoords[i].fX = U/texW;
this->texCoords[i].fY = V/texH;
}
//2. Verticies (automatically un-compressing them)
file.seekg(frameOffset);
this->verts = new rust::cVector3f[this->vertPerFrame * this->numFrames];
char frameNames[this->numFrames][16];
for(int frame = 0; frame < this->numFrames; frame++) {
rust::cVector3f scale;
rust::cVector3f translate;
//Read Scale Vector
file.read((char*)(&scale.fX), 4);
file.read((char*)(&scale.fY), 4);
file.read((char*)(&scale.fZ), 4);
//Read Translation Vector
file.read((char*)(&translate.fX), 4);
file.read((char*)(&translate.fY), 4);
file.read((char*)(&translate.fZ), 4);
//read Frame Name
file.read(&(frameNames[frame][0]), 16);
for(int vert = 0; vert < this->vertPerFrame; vert++){
char X, Y, Z;
file.read(&X, 1);
file.read(&Y, 1);
file.read(&Z, 1);
char lNorm;
file.read(&lNorm, 1);
//this->verts[(frame + 1) * (vert + 1) - 1].fX = scale.fX * X + translate.fX;
//this->verts[(frame + 1) * (vert + 1) - 1].fY = scale.fY * Y + translate.fY;
//this->verts[(frame + 1) * (vert + 1) - 1].fZ = scale.fZ * Z + translate.fZ;
this->verts[vert + frame * this->vertPerFrame].fX = scale.fX * X + translate.fX;
this->verts[vert + frame * this->vertPerFrame].fY = scale.fY * Y + translate.fY;
this->verts[vert + frame * this->vertPerFrame].fZ = scale.fZ * Z + translate.fZ;
}
}
//3. GL Commands
this->glCommands = new int[this->numGLCommands];
file.seekg(glCmdOffset);
for(int i = 0; i < this->numGLCommands; i++){
file.read((char*)&(this->glCommands[i]), 4);
}
this->oneFrame = new rust::cVector3f[this->vertPerFrame];
setFrame(45);
}
file.close();
Code: Select all
int i = 0;
for(; i < this->numGLCommands;) {
if (this->glCommands[i] != 0) {
int numVert;
if (this->glCommands[i] > 0) {
glBegin(GL_TRIANGLE_STRIP);
numVert = this->glCommands[i];
}else{
glBegin(GL_TRIANGLE_FAN);
numVert = -this->glCommands[i];
}
//i++;
for(int vert = 0; vert < numVert; vert++){
glTexCoord2f(*((float*)(&this->glCommands[++i])), *((float*)(&this->glCommands[++i])));
i++;
glVertex3f(this->oneFrame[this->glCommands[i]].fX,
this->oneFrame[this->glCommands[i]].fY,
this->oneFrame[this->glCommands[i]].fZ);
}
glEnd();
}
i++;
}