Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
Code:int QuakeModel::loadModel(const char *path, D3DXVECTOR4 *scale, D3DXVECTOR4 *pos, D3DXVECTOR4 *rot, const char *texPath) { FILE *file = 0; int fileLen = -1; unsigned char *buffer = 0; HEADER *header = 0; file = fopen(path, "rb"); if(file == 0) { return -1; } /* To get the length of the file i need to set the filepointer position at the end of the file, and save the current filepointer position, after that return to the begining */ fseek(file, 0, SEEK_END); fileLen = ftell(file); fseek(file, 0, SEEK_SET); buffer = (unsigned char*)malloc(fileLen+1); // allocate memory for the file int readBytes = fread(buffer, sizeof(unsigned char), fileLen, file); /* first there is the header, so we can set a header pointer to the buffer and access with it to each field */ header = (HEADER*)buffer; if(header->identifier != MD2_MAG_NUM || header->version != MD2_VERSION) { fclose(file); return -1; } // save the header information in this object this->state = 0; this->attr = 0; this->color = 0; this->numFrames = header->numFrames; this->numPolygons = header->numPolygons; this->numTextureCoords = header->numTextureCoords; this->numVertices = header->numVertices; this->currFrame = 0; if(pos) this->worldPos = *pos; else this->worldPos = D3DXVECTOR4(0.0f, 0.0f, 0.0f, 0.0f); printf("Anzahl Polygone: %d\nAnzahl Vertices: %d\n", header->numPolygons, header->numVertices); printf("Version: %d\nHoehe: %d\nBreite: %d\n", header->version, header->skinHeight, header->skinWidth); printf("Skins: %d\n", header->numSkins); // first load the texture if(texPath) { this->skin = new Texture(m_pD3DDevice, 123); this->skin->loadTexture(texPath); } this->frames = new LOADED_FRAME[header->numFrames]; // extract every single frame FRAME *frame; for(int i = 0; i < 1/*header->numFrames*/; i++) { frame = (FRAME*)(buffer + header->offFrames + (header->frameSize * i)); memcpy(this->frames[i].name, frame->name, sizeof(char)*16); memcpy(this->frames[i].scale, frame->scale, sizeof(float)*3); memcpy(this->frames[i].translate, frame->translate, sizeof(float)*3); // this->frames[i].vlist = new MD2_POINT[header->numVertices]; for(int j = 0; j < header->numVertices; j++) { MD2_POINT tempPoint; memcpy(&tempPoint, frame->vlist[j], sizeof(MD2_POINT)); printf("Vector: %f %f %f\n", tempPoint.v[0], tempPoint.v[1], tempPoint.v[2]); } printf("Name of Frame: %s\n", this->frames[i].name); //printf("Scale: %f %f %f\n", frame->scale[0], frame->scale[1], frame->scale[2]); //printf("Transform: %f %f %f\n", frame->translate[0], frame->translate[1], frame->translate[2]); } fclose(file); return 0; } |
Quellcode |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
struct HEADER { int identifier; int version; int skinWidth; int skinHeight; int frameSize; int numSkins; int numVertices; int numTextureCoords; int numPolygons; int numGLCmds; int numFrames; int offSkins; int offTextureCoords; int offPolygons; int offFrames; int offGLCmds; int offEnd; }; struct TEX_COORD { short u; short v; }; struct TRIANGLE { short index_vertex[3]; short index_texture[3]; }; struct POLYGON { unsigned short vIndex[3]; // vertex indices unsigned short tIndex[3]; // texture indices }; struct MD2_POINT { unsigned char v[3]; // x, y, z coordinates unsigned char normal; // unused (just for id-soft games) }; struct FRAME { float scale[3]; // scaling factors float translate[3]; // translation factors char name[16]; // name of the frame MD2_POINT vlist[1]; // beginning of the vertex list }; |