[7353] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
[8088] | 3 | |
---|
[7353] | 4 | Copyright (C) 2006 orx |
---|
[8088] | 5 | |
---|
[7353] | 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
[8088] | 10 | |
---|
[7353] | 11 | ### File Specific: |
---|
| 12 | main-programmer: bottac@ee.ethz.ch |
---|
[8088] | 13 | |
---|
[8081] | 14 | Inspired by: |
---|
| 15 | Rendering Q3 Maps by Morgan McGuire http://graphics.cs.brown.edu/games/quake/quake3.html |
---|
| 16 | Unofficial Quake 3 Map Specs by Kekoa Proudfoot http://graphics.stanford.edu/~kekoa/q3/ |
---|
| 17 | Quake 3 Collision Detection by Nathan Ostgard http://www.devmaster.net/articles/quake3collision/ |
---|
[7353] | 18 | */ |
---|
| 19 | |
---|
[8088] | 20 | |
---|
[7353] | 21 | #include "bsp_file.h" |
---|
| 22 | #include "bsp_tree_node.h" |
---|
| 23 | #include <fstream> |
---|
[8330] | 24 | #include "util/loading/resource_manager.h" |
---|
| 25 | |
---|
[7353] | 26 | #include <sys/stat.h> |
---|
| 27 | #include <string.h> |
---|
| 28 | #include "debug.h" |
---|
| 29 | #include "material.h" |
---|
| 30 | #include "vertex_array_model.h" |
---|
| 31 | // Necessary ? |
---|
| 32 | #include "base_object.h" |
---|
| 33 | #include "vector.h" |
---|
[7801] | 34 | #include "movie_player.h" |
---|
[7353] | 35 | |
---|
[7385] | 36 | #include <SDL/SDL_endian.h> |
---|
| 37 | #include <SDL/SDL_image.h> |
---|
| 38 | |
---|
[7353] | 39 | using namespace std; |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | // Constructor |
---|
| 43 | BspFile::BspFile() |
---|
[7395] | 44 | {} |
---|
[7353] | 45 | |
---|
[7511] | 46 | /** |
---|
| 47 | * Loads a quake3 level (*.bsp) |
---|
| 48 | * @param name the Name of the *.bsp file |
---|
| 49 | */ |
---|
[7596] | 50 | int BspFile::read(const char* name) |
---|
[7353] | 51 | { |
---|
[8081] | 52 | //this->scale = 0.4; |
---|
[7353] | 53 | int offset; |
---|
| 54 | int size; |
---|
| 55 | struct stat results; |
---|
| 56 | |
---|
[7801] | 57 | |
---|
[7395] | 58 | if (stat( name , &results) == 0) { |
---|
| 59 | PRINTF(0)("BSP FILE: Datei %s gefunden. \n", name); |
---|
| 60 | ifstream bspFile (name, ios::in | ios::binary); |
---|
| 61 | bspFile.read(this->header, 260); |
---|
| 62 | PRINTF(0)("BSP FILE: BSPVersion: %i. \n", ((int *)(header) )[1]); |
---|
| 63 | if(SDL_SwapLE32(((int *)(header) )[1]) == 46) PRINTF(0)("BSP FILE: This is the good one! :-) \n"); |
---|
| 64 | else PRINTF(0)("BSP FILE: Wrong BSPVersion.\n"); //!< now, we should do some error handling |
---|
| 65 | |
---|
| 66 | // Get the Nodes |
---|
| 67 | offset = SDL_SwapLE32(((int *)(header) )[8]); |
---|
| 68 | size = SDL_SwapLE32(((int *)(header))[9]); |
---|
| 69 | PRINTF(4)("BSP FILE: NodeSize: %i Bytes. \n", size); |
---|
| 70 | PRINTF(4)("BSP FILE: NumNodes: %i. \n", size / sizeof(node)); |
---|
| 71 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(node)); |
---|
| 72 | PRINTF(4)("BSP FILE: NodeOffset: %i. \n", offset); |
---|
| 73 | this->numNodes = size/sizeof(node); |
---|
| 74 | this->nodes = new node [this->numNodes]; |
---|
[7353] | 75 | bspFile.seekg(offset); |
---|
[7395] | 76 | bspFile.read((char*)this->nodes, size); |
---|
[7353] | 77 | |
---|
[7395] | 78 | // and their Planes |
---|
| 79 | offset = SDL_SwapLE32(((int *)(header) )[6]); |
---|
| 80 | size = SDL_SwapLE32(((int *)(header))[7]); |
---|
| 81 | PRINTF(4)("BSP FILE: PlanesSize: %i Bytes. \n", size); |
---|
| 82 | PRINTF(4)("BSP FILE: NumPlanes: %i. \n", size / sizeof(plane)); |
---|
| 83 | PRINTF(4)("BSP FILE: Remainder: %i. \n", sizeof(plane)); |
---|
| 84 | PRINTF(4)("BSP FILE: PlanesOffset: %i. \n", offset); |
---|
| 85 | this->numPlanes = size/sizeof(plane); |
---|
| 86 | this->planes = new plane [this->numPlanes]; |
---|
[7353] | 87 | bspFile.seekg(offset); |
---|
[7395] | 88 | bspFile.read((char*)this->planes, size); |
---|
[7353] | 89 | |
---|
[7395] | 90 | // Get the Leafs |
---|
| 91 | offset = SDL_SwapLE32(((int *)(header) )[10]); |
---|
| 92 | size = SDL_SwapLE32(((int *)(header))[11]); |
---|
| 93 | PRINTF(4)("BSP FILE: LeaveSize: %i Bytes. \n", size); |
---|
| 94 | PRINTF(4)("BSP FILE: NumLeaves: %i. \n", size / sizeof(leaf)); |
---|
| 95 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(leaf)); |
---|
| 96 | PRINTF(4)("BSP FILE: LeaveOffset: %i. \n", offset); |
---|
| 97 | this->numLeafs = size/sizeof(leaf); |
---|
| 98 | this->leaves = new leaf [this->numLeafs]; |
---|
[7353] | 99 | bspFile.seekg(offset); |
---|
[7395] | 100 | bspFile.read((char*)this->leaves, size); |
---|
[7353] | 101 | |
---|
| 102 | // Get the Models |
---|
[7395] | 103 | offset = SDL_SwapLE32(((int *)(header))[16]); |
---|
| 104 | size = SDL_SwapLE32(((int *)(header))[17]); |
---|
| 105 | PRINTF(4)("BSP FILE: ModelsSize: %i Bytes. \n", size); |
---|
| 106 | PRINTF(4)("BSP FILE: NumModels: %i. \n", size / sizeof(model)); |
---|
| 107 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(model)); |
---|
| 108 | PRINTF(4)("BSP FILE: ModelsOffset: %i. \n", offset); |
---|
| 109 | this->numBspModels = size/sizeof(model); |
---|
| 110 | this->bspModels = new model [this->numBspModels]; |
---|
[7353] | 111 | bspFile.seekg(offset); |
---|
[7395] | 112 | bspFile.read((char*)this->bspModels, size); |
---|
[7353] | 113 | |
---|
| 114 | // Get the leafFaces |
---|
[7395] | 115 | offset = SDL_SwapLE32(((int *)(header))[12]); |
---|
| 116 | size = SDL_SwapLE32(((int *)(header))[13]); |
---|
| 117 | PRINTF(4)("BSP FILE: leafFacesSize: %i Bytes. \n", size); |
---|
| 118 | PRINTF(4)("BSP FILE: NumleafFaces: %i. \n", size / 4); |
---|
| 119 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4); |
---|
| 120 | PRINTF(4)("BSP FILE: leafFacesOffset: %i. \n", offset); |
---|
[7353] | 121 | this->numLeafFaces = size/4; |
---|
| 122 | this->leafFaces = new char [size]; |
---|
| 123 | bspFile.seekg(offset); |
---|
| 124 | bspFile.read(this->leafFaces, size); |
---|
| 125 | |
---|
| 126 | // Get the leafBrushes |
---|
[7395] | 127 | offset = SDL_SwapLE32(((int *)(header))[14]); |
---|
| 128 | size = SDL_SwapLE32(((int *)(header))[15]); |
---|
| 129 | PRINTF(4)("BSP FILE: leafBrushesSize: %i Bytes. \n", size); |
---|
| 130 | PRINTF(4)("BSP FILE: NumleafBrushes: %i. \n", size / 4); |
---|
| 131 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4); |
---|
| 132 | PRINTF(4)("BSP FILE: leafBrushesOffset: %i. \n", offset); |
---|
[7353] | 133 | this->numLeafBrushes = size/4; |
---|
| 134 | this->leafBrushes = new char [size]; |
---|
| 135 | bspFile.seekg(offset); |
---|
| 136 | bspFile.read(this->leafBrushes, size); |
---|
| 137 | |
---|
| 138 | // Get the brushes |
---|
[7395] | 139 | offset = SDL_SwapLE32(((int *)(header))[18]); |
---|
| 140 | size = SDL_SwapLE32(((int *)(header))[19]); |
---|
| 141 | PRINTF(4)("BSP FILE: BrushesSize: %i Bytes. \n", size); |
---|
[7410] | 142 | PRINTF(4)("BSP FILE: NumBrushes: %i. \n", size / sizeof(brush)); |
---|
| 143 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(brush)); |
---|
[7395] | 144 | PRINTF(4)("BSP FILE: BrushesOffset: %i. \n", offset); |
---|
[7410] | 145 | this->brushes = new brush [size/sizeof(brush)]; |
---|
[7353] | 146 | bspFile.seekg(offset); |
---|
[7410] | 147 | bspFile.read((char*)this->brushes, size); |
---|
[7353] | 148 | |
---|
| 149 | // Get the brushSides |
---|
[7395] | 150 | offset = SDL_SwapLE32(((int *)(header))[20]); |
---|
[7385] | 151 | size = SDL_SwapLE32(((int *)(header))[21]); |
---|
[7395] | 152 | PRINTF(4)("BSP FILE: BrushSidesSize: %i Bytes. \n", size); |
---|
| 153 | PRINTF(4)("BSP FILE: NumBrushSides: %i. \n", size / 8); |
---|
| 154 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 8); |
---|
| 155 | PRINTF(4)("BSP FILE: BrushSidesOffset: %i. \n", offset); |
---|
[7507] | 156 | this->numBrushSides = size/sizeof(brushside); |
---|
| 157 | this->brushSides = new brushside [this->numBrushSides]; |
---|
[7353] | 158 | bspFile.seekg(offset); |
---|
[7507] | 159 | bspFile.read((char*)this->brushSides, size); |
---|
[7353] | 160 | |
---|
| 161 | // Get the Vertice |
---|
[7395] | 162 | offset = SDL_SwapLE32(((int *)(header))[22]); |
---|
| 163 | size = SDL_SwapLE32(((int *)(header))[23]); |
---|
| 164 | PRINTF(4)("BSP FILE: VerticeSize: %i Bytes. \n", size); |
---|
| 165 | PRINTF(4)("BSP FILE: NumVertice: %i. \n", size / 44); |
---|
| 166 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 44); |
---|
| 167 | PRINTF(4)("BSP FILE: VerticeOffset: %i. \n", offset); |
---|
[7353] | 168 | this->numVertex = size/44; |
---|
| 169 | this->vertice = new char [size]; |
---|
| 170 | bspFile.seekg(offset); |
---|
| 171 | bspFile.read(this->vertice, size); |
---|
| 172 | |
---|
| 173 | // Get the MeshVerts |
---|
[7395] | 174 | offset = SDL_SwapLE32(((int *)(header))[24]); |
---|
| 175 | size = SDL_SwapLE32(((int *)(header))[25]); |
---|
| 176 | PRINTF(4)("BSP FILE: MeshVertsSize: %i Bytes. \n", size); |
---|
[7410] | 177 | PRINTF(4)("BSP FILE: NumMeshVerts: %i. \n", size / sizeof(meshvert)); |
---|
| 178 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(meshvert)); |
---|
[7395] | 179 | PRINTF(4)("BSP FILE: MeshVertsOffset: %i. \n", offset); |
---|
[7410] | 180 | this->meshverts = new meshvert [size / sizeof(meshvert)]; |
---|
[7353] | 181 | bspFile.seekg(offset); |
---|
[7410] | 182 | bspFile.read((char*)this->meshverts, size); |
---|
[7353] | 183 | |
---|
| 184 | // Get the Faces |
---|
[7395] | 185 | offset = SDL_SwapLE32(((int *)(header))[28]); |
---|
| 186 | size = SDL_SwapLE32(((int *)(header))[29]); |
---|
| 187 | PRINTF(4)("BSP FILE: FacesSize: %i Bytes. \n", size); |
---|
| 188 | PRINTF(4)("BSP FILE: NumFaces: %i. \n", size / sizeof(face)); |
---|
| 189 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(face)); |
---|
| 190 | PRINTF(4)("BSP FILE: FacesOffset: %i. \n", offset); |
---|
| 191 | this->numFaces = size/sizeof(face); |
---|
| 192 | this->faces = new face [this->numFaces]; |
---|
[7353] | 193 | bspFile.seekg(offset); |
---|
[7395] | 194 | bspFile.read((char*)this->faces, size); |
---|
[7353] | 195 | |
---|
[7465] | 196 | //Get the lightmaps |
---|
| 197 | offset = SDL_SwapLE32(((int *)(header))[30]); |
---|
| 198 | size = SDL_SwapLE32(((int *)(header))[31]); |
---|
| 199 | this->numLightMaps = size/ sizeof(lightmap); |
---|
| 200 | this->lightMaps = new lightmap [this->numLightMaps]; |
---|
| 201 | bspFile.seekg(offset); |
---|
| 202 | bspFile.read((char*)this->lightMaps, size); |
---|
| 203 | |
---|
| 204 | |
---|
[7353] | 205 | // Get the Visdata |
---|
[7395] | 206 | offset = SDL_SwapLE32(((int *)(header))[34]); |
---|
| 207 | size = SDL_SwapLE32(((int *)(header))[35]); |
---|
[7353] | 208 | |
---|
| 209 | this->visData = new char [size]; |
---|
| 210 | bspFile.seekg(offset); |
---|
| 211 | bspFile.read(this->visData, size); |
---|
| 212 | |
---|
[7395] | 213 | PRINTF(4)("BSP FILE: VisDataSize: %i Bytes. \n", size); |
---|
| 214 | PRINTF(4)("BSP FILE: NumVisData: %i. \n", size /1 - 8); |
---|
| 215 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 1); |
---|
| 216 | PRINTF(4)("BSP FILE: VisDataOffset: %i. \n", offset); |
---|
[7353] | 217 | |
---|
| 218 | // Get the Textures |
---|
[7395] | 219 | offset = SDL_SwapLE32(((int *)(header))[4]); |
---|
| 220 | size = SDL_SwapLE32(((int *)(header))[5]); |
---|
[7353] | 221 | |
---|
| 222 | this->textures= new char [size]; |
---|
| 223 | bspFile.seekg(offset); |
---|
| 224 | bspFile.read(this->textures, size); |
---|
| 225 | |
---|
[7395] | 226 | PRINTF(4)("BSP FILE: TextureSize: %i Bytes. \n", size); |
---|
| 227 | PRINTF(4)("BSP FILE: NumTextures: %i. \n", size /72); |
---|
| 228 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 72); |
---|
| 229 | PRINTF(4)("BSP FILE: TextureOffset: %i. \n", offset); |
---|
[7353] | 230 | this->numTextures = size/72; |
---|
| 231 | |
---|
[7395] | 232 | bspFile.close(); |
---|
[7353] | 233 | |
---|
[7395] | 234 | for(int i = 0 ; i < this->numTextures; i++) |
---|
| 235 | PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]); |
---|
| 236 | this->load_textures(); |
---|
[8088] | 237 | |
---|
[7465] | 238 | // Load the lightMaps |
---|
| 239 | this->glLightMapTextures = new GLuint[this->numLightMaps]; |
---|
| 240 | for(int i = 0; i < this->numLightMaps; i++) |
---|
| 241 | this->glLightMapTextures[i] = this->loadLightMapToGL(this->lightMaps[i]); |
---|
[8088] | 242 | |
---|
[7465] | 243 | //Create white texture for if no lightmap specified |
---|
| 244 | glGenTextures(1, &this->whiteLightMap); |
---|
| 245 | glBindTexture(GL_TEXTURE_2D, this->whiteLightMap); |
---|
[8088] | 246 | //Create texture |
---|
[7465] | 247 | this->whiteTexture[0]=255; |
---|
| 248 | this->whiteTexture[1]=255; |
---|
| 249 | this->whiteTexture[2]=255; |
---|
[8088] | 250 | |
---|
[7465] | 251 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
---|
| 252 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
---|
| 253 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
---|
| 254 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
---|
[7353] | 255 | |
---|
[7465] | 256 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2); |
---|
| 257 | |
---|
| 258 | |
---|
[8088] | 259 | |
---|
[7465] | 260 | /* control the mipmap levels */ |
---|
| 261 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); |
---|
| 262 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); |
---|
| 263 | |
---|
| 264 | /* build the Texture OpenGL V >= 1.1 */ |
---|
| 265 | glTexImage2D(GL_TEXTURE_2D, |
---|
| 266 | 0, |
---|
[7544] | 267 | GL_RGBA8, |
---|
[7465] | 268 | 1, |
---|
| 269 | 1, |
---|
| 270 | 0, |
---|
| 271 | GL_RGB, |
---|
| 272 | GL_UNSIGNED_BYTE, |
---|
| 273 | (const GLvoid *)&(this->whiteTexture)); |
---|
| 274 | |
---|
[8088] | 275 | gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, 1, 1, |
---|
[7544] | 276 | GL_RGB, GL_UNSIGNED_BYTE,(const GLvoid *) &(this->whiteTexture)); |
---|
[7465] | 277 | |
---|
[8088] | 278 | |
---|
| 279 | |
---|
[7395] | 280 | // Get the number of patches |
---|
| 281 | this->numPatches = 0; |
---|
| 282 | this->patchOffset = 0; |
---|
[7353] | 283 | |
---|
[7395] | 284 | for( int i = 0; i < this->numFaces; i++) { |
---|
| 285 | face& cFace = ((face *)(this->faces))[i]; |
---|
[7410] | 286 | if (SDL_SwapLE32(cFace.type) == 2) |
---|
| 287 | this->numPatches += (SDL_SwapLE32(cFace.size[0]) -1 ) / 2 * (SDL_SwapLE32(cFace.size[1]) -1) / 2; |
---|
[7395] | 288 | } |
---|
[7353] | 289 | |
---|
[7395] | 290 | // Allocate Memory |
---|
| 291 | this->patchVertice = new char[8*8*44*(this->numPatches+10)]; |
---|
| 292 | this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)]; |
---|
| 293 | this->patchRowIndexes = new int*[7*4*this->numPatches]; |
---|
| 294 | this->patchTrianglesPerRow = new char[7*4*this->numPatches]; |
---|
| 295 | this->VertexArrayModels = new VertexArrayModel*[this->numPatches]; |
---|
| 296 | |
---|
[7353] | 297 | PRINTF(0)("BSP FILE:NumberOfPatches: %i . \n", numPatches); |
---|
[8088] | 298 | |
---|
[7805] | 299 | this->swapAllBspCoordinates(); |
---|
[8088] | 300 | |
---|
[7353] | 301 | // Do tesselation for all Faces of type 2 |
---|
[7395] | 302 | for( int i = 0; i < this->numFaces; i++) { |
---|
[7410] | 303 | if (SDL_SwapLE32((this->faces)[i].type) == 2) |
---|
[7395] | 304 | this->tesselate(i); |
---|
| 305 | } |
---|
[7353] | 306 | |
---|
[7395] | 307 | PRINTF(0)("BSP FILE:PatchOffset: %i . \n", this->patchOffset); |
---|
[7353] | 308 | |
---|
[7395] | 309 | return 1; |
---|
| 310 | } else { |
---|
| 311 | PRINTF(0)("BSP FILE: Datei nicht gefunden. \n"); |
---|
| 312 | return -1; |
---|
[7353] | 313 | } |
---|
[7395] | 314 | |
---|
[8088] | 315 | |
---|
| 316 | |
---|
[7353] | 317 | } |
---|
| 318 | |
---|
| 319 | void BspFile::build_tree() |
---|
| 320 | { |
---|
| 321 | |
---|
[7395] | 322 | PRINTF(0)("BSP FILE:\n"); |
---|
| 323 | PRINTF(0)("BSP FILE: Building Tree...\n"); |
---|
| 324 | root = this->build_tree_rec(0); |
---|
| 325 | PRINTF(0)("BSP FILE: ...done. \n"); |
---|
| 326 | PRINTF(0)("BSP FILE: \n"); |
---|
| 327 | PRINTF(0)("BSP FILE: Node #0: \n"); |
---|
| 328 | PRINTF(0)("BSP FILE: x: %f \n",root->plane.x); |
---|
| 329 | PRINTF(0)("BSP FILE: y: %f\n",root->plane.y); |
---|
| 330 | PRINTF(0)("BSP FILE: z: %f\n",root->plane.z); |
---|
[7353] | 331 | } |
---|
| 332 | |
---|
[7511] | 333 | /** |
---|
| 334 | * Called by BspFile::build_tree() only. |
---|
| 335 | */ |
---|
[7353] | 336 | BspTreeNode* BspFile::build_tree_rec(int i) |
---|
| 337 | { |
---|
[7395] | 338 | // PRINTF(0)("BSP FILE: Node #%i\n", i); |
---|
| 339 | BspTreeNode* thisNode = new BspTreeNode(); |
---|
| 340 | int left =(((node *) nodes) [i]).left; |
---|
| 341 | int right =(((node *) nodes) [i]).right; |
---|
| 342 | int planeIndex = (((node *) nodes) [i]).plane; |
---|
| 343 | float x1 =(((plane *) this->planes) [planeIndex]).x; |
---|
| 344 | float y1 =(((plane *) this->planes) [planeIndex]).y; |
---|
| 345 | float z1 =(((plane *) this->planes) [planeIndex]).z; |
---|
| 346 | thisNode->leafIndex = 0; |
---|
[8088] | 347 | thisNode->d = (((plane *) this->planes) [planeIndex]).d; |
---|
[7353] | 348 | |
---|
[7395] | 349 | thisNode->plane = Vector(x1,y1,z1); |
---|
| 350 | thisNode->isLeaf = false; |
---|
| 351 | |
---|
| 352 | if(left >= 0) { |
---|
| 353 | thisNode->left = this->build_tree_rec(left); |
---|
| 354 | } else { |
---|
| 355 | //BspTreeLeaf tmp = BspTreeLeaf(); |
---|
| 356 | //tmp.isLeaf = true; |
---|
| 357 | //tmp.leafIndex = -left -1; |
---|
| 358 | //thisNode->left = (BspTreeNode*) (&tmp); |
---|
| 359 | thisNode->left = new BspTreeNode(); |
---|
| 360 | thisNode->left->isLeaf = true; |
---|
| 361 | thisNode->left->leafIndex = - (left +1); |
---|
| 362 | //PRINTF(0)("BSP FILE: LeafIndex: %i\n",-left); |
---|
[7353] | 363 | } // assign leav |
---|
[7395] | 364 | if(right >= 0) { |
---|
| 365 | thisNode->right = this->build_tree_rec(right); |
---|
| 366 | } else { |
---|
| 367 | //BspTreeLeaf tmp = BspTreeLeaf(); |
---|
| 368 | //tmp.isLeaf = true; |
---|
| 369 | //tmp.leafIndex = -right -1; |
---|
| 370 | //thisNode->right = (BspTreeNode*) (&tmp); |
---|
| 371 | thisNode->right = new BspTreeNode(); |
---|
| 372 | thisNode->right->isLeaf = true; |
---|
| 373 | thisNode->right->leafIndex = -(right +1); |
---|
| 374 | //PRINTF(0)("BSP FILE: LeafIndex: %i\n",-right); |
---|
| 375 | } // assign leaf |
---|
| 376 | return thisNode; |
---|
[7353] | 377 | } |
---|
| 378 | |
---|
[7511] | 379 | /** |
---|
| 380 | * returns the root node of the bsp-tree |
---|
| 381 | */ |
---|
[7353] | 382 | BspTreeNode* BspFile::get_root() |
---|
| 383 | { |
---|
[7395] | 384 | return root; |
---|
[7353] | 385 | } |
---|
| 386 | |
---|
| 387 | void BspFile::load_textures() |
---|
| 388 | { |
---|
[7544] | 389 | ::std::string absFileName; |
---|
[7353] | 390 | char fileName [228]; |
---|
| 391 | char ext [100]; |
---|
| 392 | struct stat results; |
---|
[8088] | 393 | |
---|
| 394 | |
---|
[7385] | 395 | this->Materials = new AMat[this->numTextures]; |
---|
[7395] | 396 | for(int i = 0 ; i < this->numTextures; i++) { |
---|
[7353] | 397 | PRINTF(0)("BSP FILE: Texture : %s. \n", &this->textures[8+ 72*i]); |
---|
[8088] | 398 | |
---|
| 399 | |
---|
[7544] | 400 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 401 | if(strlen(fileName) == 0) |
---|
| 402 | { |
---|
[8088] | 403 | // Default Material |
---|
[7544] | 404 | this->Materials[i].mat = new Material(); |
---|
[7579] | 405 | this->Materials[i].mat->setDiffuse(0.1,0.1,1.0); |
---|
| 406 | this->Materials[i].mat->setAmbient(0.1,0.1,1.0 ); |
---|
| 407 | this->Materials[i].mat->setSpecular(0.4,0.4,1.0); |
---|
[7544] | 408 | //this->Materials[i]->setShininess(100.0); |
---|
[7801] | 409 | // this->Materials[i].mat->setTransparency(1.0); |
---|
[7544] | 410 | this->Materials[i].mat->setDiffuseMap("pictures/ground.tga"); |
---|
| 411 | this->Materials[i].mat->setAmbientMap("pictures/ground.tga"); |
---|
| 412 | this->Materials[i].mat->setSpecularMap("pictures/ground.tga"); |
---|
| 413 | this->Materials[i].alpha = false; |
---|
[7801] | 414 | this->Materials[i].animated = false; |
---|
[7544] | 415 | continue; |
---|
[8088] | 416 | } |
---|
| 417 | |
---|
[7801] | 418 | // Check for mov |
---|
| 419 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 420 | strcpy(ext, ".mov"); |
---|
| 421 | strncat (fileName, ext, strlen(fileName)); |
---|
| 422 | |
---|
| 423 | absFileName = ResourceManager::getFullName(fileName); |
---|
| 424 | |
---|
[8088] | 425 | if(File(absFileName).exists()) { |
---|
[7801] | 426 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
| 427 | this->Materials[i] = this->loadAVI(fileName); |
---|
| 428 | continue; |
---|
| 429 | } |
---|
[8088] | 430 | |
---|
[7801] | 431 | // Check for avi |
---|
| 432 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 433 | strcpy(ext, ".avi"); |
---|
| 434 | strncat (fileName, ext, strlen(fileName)); |
---|
| 435 | |
---|
| 436 | absFileName = ResourceManager::getFullName(fileName); |
---|
| 437 | |
---|
[8088] | 438 | if(File(absFileName).exists()) { |
---|
[7801] | 439 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
| 440 | this->Materials[i] = this->loadAVI(fileName); |
---|
| 441 | continue; |
---|
| 442 | } |
---|
[8088] | 443 | |
---|
[7801] | 444 | // Check for mpg |
---|
| 445 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 446 | strcpy(ext, ".mpg"); |
---|
| 447 | strncat (fileName, ext, strlen(fileName)); |
---|
| 448 | |
---|
| 449 | absFileName = ResourceManager::getFullName(fileName); |
---|
| 450 | |
---|
[8088] | 451 | if(File(absFileName).exists()) { |
---|
[7801] | 452 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
| 453 | this->Materials[i] = this->loadAVI(fileName); |
---|
| 454 | continue; |
---|
| 455 | } |
---|
[8088] | 456 | |
---|
[7395] | 457 | // Check for tga |
---|
[7353] | 458 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 459 | strcpy(ext, ".tga"); |
---|
| 460 | strncat (fileName, ext, strlen(fileName)); |
---|
[7395] | 461 | |
---|
[7544] | 462 | absFileName = ResourceManager::getFullName(fileName); |
---|
| 463 | |
---|
[8088] | 464 | if(File(absFileName).exists()) { |
---|
[7395] | 465 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
| 466 | this->Materials[i] = this->loadMat(fileName); |
---|
| 467 | continue; |
---|
[7353] | 468 | } |
---|
| 469 | // Check for TGA |
---|
| 470 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 471 | strcpy(ext, ".TGA"); |
---|
| 472 | strncat (fileName, ext, strlen(fileName)); |
---|
[7544] | 473 | absFileName = ResourceManager::getFullName(fileName); |
---|
[7385] | 474 | |
---|
[8088] | 475 | if(File(absFileName).exists()/*stat( absFileName.c_str() , &results) == 0*/) { |
---|
[7395] | 476 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
| 477 | this->Materials[i] = this->loadMat(fileName); |
---|
| 478 | continue; |
---|
[7353] | 479 | } |
---|
| 480 | // Check for jpg |
---|
| 481 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 482 | strcpy(ext, ".jpg"); |
---|
| 483 | strncat (fileName, ext, strlen(fileName)); |
---|
[7544] | 484 | absFileName = ResourceManager::getFullName(fileName); |
---|
[8088] | 485 | if(File(absFileName).exists()) { |
---|
[7395] | 486 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
| 487 | this->Materials[i] =this->loadMat(fileName); |
---|
| 488 | continue; |
---|
[7353] | 489 | } |
---|
| 490 | |
---|
| 491 | |
---|
[7395] | 492 | // Check for JPG |
---|
| 493 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 494 | strcpy(ext, ".JPG"); |
---|
| 495 | strncat (fileName, ext, strlen(fileName)); |
---|
[7544] | 496 | absFileName = ResourceManager::getFullName(fileName); |
---|
[8088] | 497 | if(File(absFileName).exists()) { |
---|
[7395] | 498 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
| 499 | this->Materials[i] =this->loadMat(fileName); |
---|
| 500 | continue; |
---|
[7353] | 501 | } |
---|
| 502 | |
---|
| 503 | |
---|
[8088] | 504 | |
---|
[7395] | 505 | // Check for bmp |
---|
| 506 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 507 | strcpy(ext, ".bmp"); |
---|
| 508 | strncat (fileName, ext, strlen(fileName)); |
---|
[7544] | 509 | absFileName = ResourceManager::getFullName(fileName); |
---|
[7395] | 510 | |
---|
[8088] | 511 | if(File(absFileName).exists()) { |
---|
[7395] | 512 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
| 513 | this->Materials[i] =this->loadMat(fileName); |
---|
[7544] | 514 | continue; |
---|
[7353] | 515 | } |
---|
| 516 | |
---|
[7395] | 517 | // Check for BMP |
---|
[7353] | 518 | strcpy(fileName, &this->textures[8+ 72*i]); |
---|
| 519 | strcpy(ext, ".BMP"); |
---|
| 520 | strncat (fileName, ext, strlen(fileName)); |
---|
[7544] | 521 | absFileName = ResourceManager::getFullName(fileName); |
---|
[7353] | 522 | |
---|
[8088] | 523 | if(File(absFileName).exists()) { |
---|
[7395] | 524 | PRINTF(0)("BSP FILE: gefunden . \n"); |
---|
| 525 | this->Materials[i] = this->loadMat(fileName); |
---|
| 526 | continue; |
---|
[7353] | 527 | } |
---|
[8088] | 528 | |
---|
| 529 | |
---|
| 530 | // Default Material |
---|
[7395] | 531 | this->Materials[i].mat = new Material(); |
---|
| 532 | this->Materials[i].mat->setDiffuse(0.1,0.1,0.1); |
---|
| 533 | this->Materials[i].mat->setAmbient(0.1,0.1,0.1 ); |
---|
| 534 | this->Materials[i].mat->setSpecular(0.4,0.4,0.4); |
---|
| 535 | //this->Materials[i]->setShininess(100.0); |
---|
[7801] | 536 | //this->Materials[i].mat->setTransparency(1.0); |
---|
| 537 | this->Materials[i].mat->setDiffuseMap("pictures/error_texture.png"); |
---|
| 538 | this->Materials[i].mat->setAmbientMap("pictures/error_texture.png"); |
---|
| 539 | this->Materials[i].mat->setSpecularMap("pictures/error_texture.png"); |
---|
| 540 | this->Materials[i].alpha = true; |
---|
| 541 | this->Materials[i].animated = false; |
---|
[8088] | 542 | |
---|
[7353] | 543 | } |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | |
---|
[7385] | 547 | AMat BspFile::loadMat(char* mat) |
---|
[7353] | 548 | { |
---|
[7385] | 549 | AMat tmpAMat; |
---|
| 550 | this->testSurf = NULL; |
---|
| 551 | |
---|
| 552 | this->testSurf = IMG_Load(ResourceManager::getFullName(mat).c_str()); |
---|
[7395] | 553 | if(this->testSurf != NULL) { |
---|
| 554 | if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; |
---|
[8088] | 555 | else tmpAMat.alpha = false; |
---|
[7395] | 556 | } else tmpAMat.alpha = false; |
---|
[7385] | 557 | |
---|
[7353] | 558 | Material* tmp = new Material(); |
---|
[7801] | 559 | tmp->setDiffuse(1.0,1.0,1.0); |
---|
| 560 | tmp->setAmbient(1.0,1.0,1.0 ); |
---|
[7395] | 561 | tmp->setSpecular(1.0,1.0,1.0); |
---|
[8088] | 562 | // tmp->setShininess(.5); |
---|
| 563 | // tmp->setTransparency(0.0); |
---|
[7353] | 564 | |
---|
[7395] | 565 | tmp->setDiffuseMap(mat); |
---|
| 566 | |
---|
[7385] | 567 | tmpAMat.mat = tmp; |
---|
[7801] | 568 | tmpAMat.animated = false; |
---|
| 569 | return tmpAMat; |
---|
| 570 | } |
---|
[7353] | 571 | |
---|
[7801] | 572 | AMat BspFile::loadAVI(char* mat) |
---|
| 573 | { |
---|
| 574 | AMat tmpAMat; |
---|
| 575 | |
---|
| 576 | |
---|
| 577 | MoviePlayer * testMC = new MoviePlayer(mat); |
---|
| 578 | testMC->start(0); |
---|
| 579 | |
---|
| 580 | //Material* tmp = new Material(); |
---|
| 581 | // tmp->setDiffuse(1.0,1.0,1.0); |
---|
| 582 | //tmp->setAmbient(1.0,1.0,1.0 ); |
---|
| 583 | //tmp->setSpecular(1.0,1.0,1.0); |
---|
[8088] | 584 | // tmp->setShininess(.5);tmpAMat |
---|
| 585 | // tmp->setTransparency(0.0); |
---|
[7801] | 586 | |
---|
| 587 | //tmp->setDiffuseMap(mat); |
---|
| 588 | |
---|
| 589 | tmpAMat.aviMat = testMC; |
---|
| 590 | tmpAMat.animated = true; |
---|
| 591 | tmpAMat.alpha = true; |
---|
[7385] | 592 | return tmpAMat; |
---|
[7353] | 593 | } |
---|
| 594 | |
---|
[7465] | 595 | unsigned int BspFile::loadLightMapToGL(lightmap& lightMapTexture) |
---|
| 596 | { |
---|
| 597 | int errorCode = 0; //!< the error code for the texture loading functions |
---|
[7544] | 598 | unsigned int lightMap; //!< the OpenGL texture handle |
---|
[7465] | 599 | int mipmapLevel = 0; //!< the maximum mipmap level for this texture |
---|
| 600 | int mipmapWidth = 0; //!< the width of the mipmap |
---|
[8081] | 601 | int mipmapHight = 0; //!< the height of the mipmap3 |
---|
[7465] | 602 | float sc, scale, temp; |
---|
| 603 | for(int i = 0; i < 128*128*3 ; i++) |
---|
| 604 | { |
---|
| 605 | sc = ((unsigned char *)(&lightMapTexture))[i]; |
---|
[7544] | 606 | sc *= 1/255.0; |
---|
[8081] | 607 | scale = 2.0; |
---|
[7465] | 608 | if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp; |
---|
| 609 | scale*=255.0; |
---|
| 610 | sc*=scale; |
---|
[8030] | 611 | if(false) |
---|
[8088] | 612 | ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc + 75; |
---|
[7544] | 613 | else |
---|
[8081] | 614 | ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc ; |
---|
[7465] | 615 | } |
---|
[8088] | 616 | |
---|
[7465] | 617 | glGenTextures(1, &lightMap); |
---|
| 618 | glBindTexture(GL_TEXTURE_2D, lightMap); |
---|
| 619 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); |
---|
| 620 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
---|
| 621 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
---|
| 622 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
---|
| 623 | |
---|
| 624 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2); |
---|
| 625 | |
---|
| 626 | |
---|
| 627 | /* control the mipmap levels */ |
---|
| 628 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MIN_LOD, 5); |
---|
| 629 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_MAX_LOD, 0); |
---|
| 630 | |
---|
| 631 | /* build the Texture OpenGL V >= 1.1 */ |
---|
| 632 | glTexImage2D(GL_TEXTURE_2D, |
---|
| 633 | 0, |
---|
| 634 | GL_RGBA8, |
---|
| 635 | 128, |
---|
| 636 | 128, |
---|
| 637 | 0, |
---|
| 638 | GL_RGB, |
---|
| 639 | GL_UNSIGNED_BYTE, |
---|
| 640 | (const GLvoid *)&lightMapTexture); |
---|
| 641 | |
---|
[8088] | 642 | |
---|
[7465] | 643 | // build the MipMaps automaticaly |
---|
| 644 | errorCode = gluBuild2DMipmaps(GL_TEXTURE_2D, |
---|
| 645 | GL_RGBA8, |
---|
| 646 | 128, |
---|
| 647 | 128, |
---|
| 648 | GL_RGB, |
---|
| 649 | GL_UNSIGNED_BYTE, |
---|
| 650 | (const GLvoid *)&lightMapTexture |
---|
| 651 | ); |
---|
| 652 | |
---|
| 653 | |
---|
| 654 | |
---|
[8088] | 655 | |
---|
[7465] | 656 | return lightMap; |
---|
| 657 | |
---|
| 658 | } |
---|
| 659 | |
---|
[7511] | 660 | /** |
---|
| 661 | * Generates a vertex-array, a indice-array and a texture-coordinates-array for iface. |
---|
[8088] | 662 | * @param iface integer index of face |
---|
[7511] | 663 | * @todo cleanup this function, let the user choose the level of tesselation |
---|
| 664 | */ |
---|
[8088] | 665 | |
---|
| 666 | |
---|
[7353] | 667 | void BspFile::tesselate(int iface) |
---|
| 668 | { |
---|
[7410] | 669 | face* Face = &((this->faces)[iface]); |
---|
[7395] | 670 | BspVertex * BspVrtx = (BspVertex*)this->vertice; |
---|
| 671 | int level = 7; |
---|
| 672 | int level1 = 8; |
---|
[7801] | 673 | int size0 = (Face->size[0]); |
---|
| 674 | int size1 = (Face->size[1]); |
---|
[7395] | 675 | // For each patch... |
---|
[7410] | 676 | for(int i = 0; i < ( size0 - 1) ; i+=2) { |
---|
| 677 | for(int j = 0; j < ( size1 -1) ; j+=2) { |
---|
[7353] | 678 | |
---|
| 679 | |
---|
[7395] | 680 | // Make a patch... |
---|
| 681 | // Get controls[9]; |
---|
| 682 | BspVec controls[9]; |
---|
| 683 | BspVec controlsTmp[9]; |
---|
| 684 | BspVertex VControls[9]; |
---|
| 685 | for(int k = 0; k < 3; k++) { |
---|
| 686 | for(int l = 0; l < 3; l++) { |
---|
[7801] | 687 | controls[k +3*l]. position[0] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[0]); |
---|
| 688 | controls[k +3*l]. position[1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]); |
---|
| 689 | controls[k +3*l]. position[2] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/ |
---|
[7353] | 690 | |
---|
[7801] | 691 | controlsTmp[2-k +6-3*l]. position[0] = ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]); |
---|
| 692 | controlsTmp[2-k +6-3*l]. position[1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]); |
---|
| 693 | controlsTmp[2-k +6-3*l]. position[2] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); /*Face->n_vertexes*/ |
---|
[7353] | 694 | |
---|
[7801] | 695 | VControls[k +3*l]. position[0] = ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].position[0]); |
---|
| 696 | VControls[k +3*l]. position[1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].position[1]); |
---|
| 697 | VControls[k +3*l]. position[2] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].position[2]); |
---|
[7353] | 698 | |
---|
[7801] | 699 | VControls[k +3*l]. normal[0] = ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].normal[0]); |
---|
| 700 | VControls[k +3*l]. normal[1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].normal[1]); |
---|
| 701 | VControls[k +3*l]. normal[2] = ( BspVrtx[Face->vertex + (j * size0)+ i + l+ size0*k].normal[2]); |
---|
[7353] | 702 | |
---|
[7801] | 703 | VControls[k +3*l]. texcoord[0][0]= ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[0][0]); |
---|
| 704 | VControls[k +3*l]. texcoord[0][1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[0][1]); |
---|
| 705 | VControls[k +3*l]. texcoord[1][0] = ( BspVrtx[Face->vertex +( j * size0)+ i + l+ size0*k].texcoord[1][0]); |
---|
| 706 | VControls[k +3*l]. texcoord[1][1] = ( BspVrtx[Face->vertex + (j * size0)+ i +l+ size0*k].texcoord[1][1]); |
---|
[7353] | 707 | |
---|
| 708 | |
---|
[7395] | 709 | } |
---|
| 710 | } |
---|
| 711 | //*********************************************************************************************************************** |
---|
| 712 | // Compute the vertice |
---|
| 713 | //*********************************************************************************************************************** |
---|
| 714 | float px, py; |
---|
| 715 | BspVertex temp[3]; |
---|
| 716 | BspVertex* Vertice = &(((BspVertex*)this->patchVertice)[level1*level1*this->patchOffset]); |
---|
[7353] | 717 | |
---|
[7395] | 718 | for(int v=0; v<=level; ++v) { |
---|
| 719 | px=(float)v/level; |
---|
[7353] | 720 | |
---|
[7395] | 721 | Vertice[v].position[0]=VControls[0].position[0]*((1.0f-px)*(1.0f-px))+VControls[3].position[0]*((1.0f-px)*px*2)+VControls[6].position[0]*(px*px); |
---|
| 722 | Vertice[v].position[1]=VControls[0].position[1]*((1.0f-px)*(1.0f-px))+VControls[3].position[1]*((1.0f-px)*px*2)+VControls[6].position[1]*(px*px); |
---|
| 723 | Vertice[v].position[2]=VControls[0].position[2]*((1.0f-px)*(1.0f-px))+VControls[3].position[2]*((1.0f-px)*px*2)+VControls[6].position[2]*(px*px); |
---|
[7353] | 724 | |
---|
[7395] | 725 | Vertice[v].normal[0]=VControls[0].normal[0]*((1.0f-px)*(1.0f-px))+VControls[3].normal[0]*((1.0f-px)*px*2)+VControls[6].normal[0]*(px*px); |
---|
| 726 | Vertice[v].normal[1]=VControls[0].normal[1]*((1.0f-px)*(1.0f-px))+VControls[3].normal[1]*((1.0f-px)*px*2)+VControls[6].normal[1]*(px*px); |
---|
| 727 | Vertice[v].normal[2]=VControls[0].normal[2]*((1.0f-px)*(1.0f-px))+VControls[3].normal[2]*((1.0f-px)*px*2)+VControls[6].normal[2]*(px*px); |
---|
[7353] | 728 | |
---|
[7395] | 729 | Vertice[v].texcoord[0][0]=VControls[0].texcoord[0][0]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[0][0]*((1.0f-px)*px*2)+VControls[6].texcoord[0][0]*(px*px); |
---|
| 730 | Vertice[v].texcoord[0][1]=VControls[0].texcoord[0][1]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[0][1]*((1.0f-px)*px*2)+VControls[6].texcoord[0][1]*(px*px); |
---|
| 731 | Vertice[v].texcoord[1][0]=VControls[0].texcoord[1][0]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[1][0]*((1.0f-px)*px*2)+VControls[6].texcoord[1][0]*(px*px); |
---|
| 732 | Vertice[v].texcoord[1][1]=VControls[0].texcoord[1][1]*((1.0f-px)*(1.0f-px))+VControls[3].texcoord[1][1]*((1.0f-px)*px*2)+VControls[6].texcoord[1][1]*(px*px); |
---|
[7353] | 733 | |
---|
[7395] | 734 | } |
---|
[7353] | 735 | |
---|
| 736 | |
---|
[7395] | 737 | for(int u=1; u<=level; ++u) { |
---|
| 738 | py=(float)u/level; |
---|
[7353] | 739 | |
---|
[7395] | 740 | // temp[0]=controlPoints[0]*((1.0f-py)*(1.0f-py))+ controlPoints[1]*((1.0f-py)*py*2)+ controlPoints[2]*(py*py); |
---|
| 741 | temp[0].position[0]=VControls[0].position[0]*((1.0f-py)*(1.0f-py))+VControls[1].position[0]*((1.0f-py)*py*2)+VControls[2].position[0]*(py*py); |
---|
| 742 | temp[0].position[1]=VControls[0].position[1]*((1.0f-py)*(1.0f-py))+VControls[1].position[1]*((1.0f-py)*py*2)+VControls[2].position[1]*(py*py); |
---|
| 743 | temp[0].position[2]=VControls[0].position[2]*((1.0f-py)*(1.0f-py))+VControls[1].position[2]*((1.0f-py)*py*2)+VControls[2].position[2]*(py*py); |
---|
[7353] | 744 | |
---|
[7395] | 745 | temp[0].normal[0]=VControls[0].normal[0]*((1.0f-py)*(1.0f-py))+VControls[1].normal[0]*((1.0f-py)*py*2)+VControls[2].normal[0]*(py*py); |
---|
| 746 | temp[0].normal[1]=VControls[0].normal[1]*((1.0f-py)*(1.0f-py))+VControls[1].normal[1]*((1.0f-py)*py*2)+VControls[2].normal[1]*(py*py); |
---|
| 747 | temp[0].normal[2]=VControls[0].normal[2]*((1.0f-py)*(1.0f-py))+VControls[1].normal[2]*((1.0f-py)*py*2)+VControls[2].normal[2]*(py*py); |
---|
[7353] | 748 | |
---|
[7395] | 749 | temp[0].texcoord[0][0]=VControls[0].texcoord[0][0]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[0][0]*((1.0f-py)*py*2)+VControls[2].texcoord[0][0]*(py*py); |
---|
| 750 | temp[0].texcoord[0][1]=VControls[0].texcoord[0][1]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[0][1]*((1.0f-py)*py*2)+VControls[2].texcoord[0][1]*(py*py); |
---|
| 751 | temp[0].texcoord[1][0]=VControls[0].texcoord[1][0]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[1][0]*((1.0f-py)*py*2)+VControls[2].texcoord[1][0]*(py*py); |
---|
| 752 | temp[0].texcoord[1][1]=VControls[0].texcoord[1][1]*((1.0f-py)*(1.0f-py))+VControls[1].texcoord[1][1]*((1.0f-py)*py*2)+VControls[2].texcoord[1][1]*(py*py); |
---|
[7353] | 753 | |
---|
| 754 | |
---|
| 755 | |
---|
[7395] | 756 | // temp[1]=controlPoints[3]*((1.0f-py)*(1.0f-py))+ controlPoints[4]*((1.0f-py)*py*2)+ controlPoints[5]*(py*py); |
---|
| 757 | temp[1].position[0]=VControls[3].position[0]*((1.0f-py)*(1.0f-py))+VControls[4].position[0]*((1.0f-py)*py*2)+VControls[5].position[0]*(py*py); |
---|
| 758 | temp[1].position[1]=VControls[3].position[1]*((1.0f-py)*(1.0f-py))+VControls[4].position[1]*((1.0f-py)*py*2)+VControls[5].position[1]*(py*py); |
---|
| 759 | temp[1].position[2]=VControls[3].position[2]*((1.0f-py)*(1.0f-py))+VControls[4].position[2]*((1.0f-py)*py*2)+VControls[5].position[2]*(py*py); |
---|
[7353] | 760 | |
---|
[7395] | 761 | temp[1].normal[0]=VControls[3].normal[0]*((1.0f-py)*(1.0f-py))+VControls[4].normal[0]*((1.0f-py)*py*2)+VControls[5].normal[0]*(py*py); |
---|
| 762 | temp[1].normal[1]=VControls[3].normal[1]*((1.0f-py)*(1.0f-py))+VControls[4].normal[1]*((1.0f-py)*py*2)+VControls[5].normal[1]*(py*py); |
---|
| 763 | temp[1].normal[2]=VControls[3].normal[2]*((1.0f-py)*(1.0f-py))+VControls[4].normal[2]*((1.0f-py)*py*2)+VControls[5].normal[2]*(py*py); |
---|
[7353] | 764 | |
---|
[7395] | 765 | temp[1].texcoord[0][0]=VControls[3].texcoord[0][0]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[0][0]*((1.0f-py)*py*2)+VControls[5].texcoord[0][0]*(py*py); |
---|
| 766 | temp[1].texcoord[0][1]=VControls[3].texcoord[0][1]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[0][1]*((1.0f-py)*py*2)+VControls[5].texcoord[0][1]*(py*py); |
---|
| 767 | temp[1].texcoord[1][0]=VControls[3].texcoord[1][0]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[1][0]*((1.0f-py)*py*2)+VControls[5].texcoord[1][0]*(py*py); |
---|
| 768 | temp[1].texcoord[1][1]=VControls[3].texcoord[1][1]*((1.0f-py)*(1.0f-py))+VControls[4].texcoord[1][1]*((1.0f-py)*py*2)+VControls[5].texcoord[1][1]*(py*py); |
---|
[7353] | 769 | |
---|
| 770 | |
---|
[7395] | 771 | // temp[2]=controlPoints[6]*((1.0f-py)*(1.0f-py))+controlPoints[7]*((1.0f-py)*py*2)+controlPoints[8]*(py*py); |
---|
| 772 | temp[2].position[0]=VControls[6].position[0]*((1.0f-py)*(1.0f-py))+VControls[7].position[0]*((1.0f-py)*py*2)+VControls[8].position[0]*(py*py); |
---|
| 773 | temp[2].position[1]=VControls[6].position[1]*((1.0f-py)*(1.0f-py))+VControls[7].position[1]*((1.0f-py)*py*2)+VControls[8].position[1]*(py*py); |
---|
| 774 | temp[2].position[2]=VControls[6].position[2]*((1.0f-py)*(1.0f-py))+VControls[7].position[2]*((1.0f-py)*py*2)+VControls[8].position[2]*(py*py); |
---|
[7353] | 775 | |
---|
[7395] | 776 | temp[2].normal[0]=VControls[6].normal[0]*((1.0f-py)*(1.0f-py))+VControls[7].normal[0]*((1.0f-py)*py*2)+VControls[8].normal[0]*(py*py); |
---|
| 777 | temp[2].normal[1]=VControls[6].normal[1]*((1.0f-py)*(1.0f-py))+VControls[7].normal[1]*((1.0f-py)*py*2)+VControls[8].normal[1]*(py*py); |
---|
| 778 | temp[2].normal[2]=VControls[6].normal[2]*((1.0f-py)*(1.0f-py))+VControls[7].normal[2]*((1.0f-py)*py*2)+VControls[8].normal[2]*(py*py); |
---|
[7353] | 779 | |
---|
[7395] | 780 | temp[2].texcoord[0][0]=VControls[6].texcoord[0][0]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[0][0]*((1.0f-py)*py*2)+VControls[8].texcoord[0][0]*(py*py); |
---|
| 781 | temp[2].texcoord[0][1]=VControls[6].texcoord[0][1]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[0][1]*((1.0f-py)*py*2)+VControls[8].texcoord[0][1]*(py*py); |
---|
| 782 | temp[2].texcoord[1][0]=VControls[6].texcoord[1][0]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[1][0]*((1.0f-py)*py*2)+VControls[8].texcoord[1][0]*(py*py); |
---|
| 783 | temp[2].texcoord[1][1]=VControls[6].texcoord[1][1]*((1.0f-py)*(1.0f-py))+VControls[7].texcoord[1][1]*((1.0f-py)*py*2)+VControls[8].texcoord[1][1]*(py*py); |
---|
[7353] | 784 | |
---|
| 785 | |
---|
| 786 | |
---|
| 787 | |
---|
[7395] | 788 | for(int v=0; v<=level; ++v) { |
---|
| 789 | px=(float)v/level; |
---|
[7353] | 790 | |
---|
[7410] | 791 | |
---|
| 792 | |
---|
| 793 | |
---|
| 794 | |
---|
[8088] | 795 | //Vertice[u*(tesselation+1)+v]= temp[0]*((1.0f-px)*(1.0f-px))+ temp[1]*((1.0f-px)*px*2)+ temp[2]*(px*px); |
---|
[7395] | 796 | Vertice[u*(level1)+v].position[0]=temp[0].position[0]*((1.0f-px)*(1.0f-px))+temp[1].position[0]*((1.0f-px)*px*2)+temp[2].position[0]*(px*px); |
---|
| 797 | Vertice[u*(level1)+v].position[1]=temp[0].position[1]*((1.0f-px)*(1.0f-px))+temp[1].position[1]*((1.0f-px)*px*2)+temp[2].position[1]*(px*px); |
---|
| 798 | Vertice[u*(level1)+v].position[2]=temp[0].position[2]*((1.0f-px)*(1.0f-px))+temp[1].position[2]*((1.0f-px)*px*2)+temp[2].position[2]*(px*px); |
---|
[7353] | 799 | |
---|
[7395] | 800 | Vertice[u*(level1)+v].normal[0]=temp[0].normal[0]*((1.0f-px)*(1.0f-px))+temp[1].normal[0]*((1.0f-px)*px*2)+temp[2].normal[0]*(px*px); |
---|
| 801 | Vertice[u*(level1)+v].normal[1]=temp[0].normal[1]*((1.0f-px)*(1.0f-px))+temp[1].normal[1]*((1.0f-px)*px*2)+temp[2].normal[1]*(px*px); |
---|
| 802 | Vertice[u*(level1)+v].normal[2]=temp[0].normal[2]*((1.0f-px)*(1.0f-px))+temp[1].normal[2]*((1.0f-px)*px*2)+temp[2].normal[2]*(px*px); |
---|
[7353] | 803 | |
---|
[7395] | 804 | Vertice[u*(level1)+v].texcoord[0][0]=temp[0].texcoord[0][0]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[0][0]*((1.0f-px)*px*2)+temp[2].texcoord[0][0]*(px*px); |
---|
| 805 | Vertice[u*(level1)+v].texcoord[0][1]=temp[0].texcoord[0][1]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[0][1]*((1.0f-px)*px*2)+temp[2].texcoord[0][1]*(px*px); |
---|
| 806 | Vertice[u*(level1)+v].texcoord[1][0]=temp[0].texcoord[1][0]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[1][0]*((1.0f-px)*px*2)+temp[2].texcoord[1][0]*(px*px); |
---|
| 807 | Vertice[u*(level1)+v].texcoord[1][1]=temp[0].texcoord[1][1]*((1.0f-px)*(1.0f-px))+temp[1].texcoord[1][1]*((1.0f-px)*px*2)+temp[2].texcoord[1][1]*(px*px); |
---|
[7353] | 808 | |
---|
| 809 | |
---|
| 810 | |
---|
[7395] | 811 | } |
---|
| 812 | } |
---|
[7353] | 813 | |
---|
[7395] | 814 | //Create indices |
---|
| 815 | GLuint* indices= & ((GLuint*)(this->patchIndexes))[level*level1*2*this->patchOffset]; |
---|
[7353] | 816 | |
---|
[7395] | 817 | for(int row=0; row<level; ++row) { |
---|
| 818 | for(int point=0; point<=level; ++point) { |
---|
| 819 | //calculate indices |
---|
| 820 | //reverse them to reverse winding |
---|
| 821 | indices[(row*(level1)+point)*2+1]=row*(level1)+point; |
---|
| 822 | indices[(row*(level1)+point)*2]=(row+1)*(level1)+point; |
---|
| 823 | } |
---|
| 824 | } |
---|
| 825 | |
---|
| 826 | |
---|
| 827 | //*********************************************************************************************************************** |
---|
| 828 | // Debug Model |
---|
| 829 | //*********************************************************************************************************************** |
---|
[8088] | 830 | |
---|
[7395] | 831 | this->VertexArrayModels[this->patchOffset] = new VertexArrayModel(); |
---|
| 832 | VertexArrayModel* tmp = this->VertexArrayModels[this->patchOffset]; |
---|
| 833 | tmp->newStripe(); |
---|
| 834 | int a = 0; |
---|
| 835 | int b = -1; |
---|
| 836 | tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]); |
---|
| 837 | tmp->addNormal(1,0,0); |
---|
| 838 | tmp->addTexCoor(0.0,0.0); |
---|
| 839 | tmp->addColor(0.3,0.0,0.0); |
---|
| 840 | tmp->addIndice(1+b); |
---|
| 841 | tmp->addIndice(4+a); |
---|
| 842 | tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]); |
---|
| 843 | tmp->addNormal(1,0,0); |
---|
| 844 | tmp->addTexCoor(0.0,0.4); |
---|
| 845 | tmp->addColor(0.3,0.0,0.0); |
---|
| 846 | tmp->addIndice(2+b); |
---|
| 847 | tmp->addIndice(5+a); |
---|
| 848 | tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); |
---|
| 849 | tmp->addNormal(1,0,0); |
---|
| 850 | tmp->addTexCoor(0.0,1.0); |
---|
| 851 | tmp->addColor(0.1,0.0,0.0); |
---|
| 852 | tmp->addIndice(3+b); |
---|
| 853 | tmp->addIndice(6+a); |
---|
| 854 | |
---|
| 855 | tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); |
---|
| 856 | tmp->addNormal(1,0,0); |
---|
| 857 | tmp->addTexCoor(0.0,1.0); |
---|
| 858 | tmp->addColor(0.1,0.0,0.0); |
---|
| 859 | tmp->addIndice(7+a); |
---|
| 860 | //tmp->addIndice(6); |
---|
| 861 | |
---|
| 862 | tmp->newStripe(); |
---|
| 863 | |
---|
| 864 | tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]); |
---|
| 865 | tmp->addNormal(1,0,0); |
---|
| 866 | tmp->addTexCoor(0.0,0.0); |
---|
| 867 | tmp->addColor(0.1,0.1,0.1); |
---|
| 868 | tmp->addIndice(5+b); |
---|
| 869 | tmp->addIndice(8+a); |
---|
| 870 | tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]); |
---|
| 871 | tmp->addNormal(1,0,0); |
---|
| 872 | tmp->addTexCoor(0.0,0.4); |
---|
| 873 | tmp->addColor(0.1,0.1,0.1); |
---|
| 874 | tmp->addIndice(6+b); |
---|
| 875 | tmp->addIndice(9+a); |
---|
| 876 | tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); |
---|
| 877 | tmp->addNormal(1,0,0); |
---|
| 878 | tmp->addTexCoor(0.0,1.0); |
---|
| 879 | tmp->addColor(0.1,0.1,0.1); |
---|
| 880 | tmp->addIndice(7+b); |
---|
| 881 | tmp->addIndice(10+a); |
---|
| 882 | tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]+0.01); |
---|
| 883 | tmp->addNormal(1,0,0); |
---|
| 884 | tmp->addTexCoor(0.0,1.0); |
---|
| 885 | tmp->addColor(0.1,0.1,0.1); |
---|
| 886 | //tmp->addIndice(5); |
---|
| 887 | tmp->addIndice(11+a); |
---|
| 888 | |
---|
| 889 | tmp->newStripe(); |
---|
| 890 | |
---|
| 891 | |
---|
| 892 | |
---|
| 893 | tmp->addVertex(controlsTmp[3].position[0],controlsTmp[3].position[1], controlsTmp[3].position[2]); |
---|
| 894 | tmp->addNormal(0,1,0); |
---|
| 895 | tmp->addTexCoor(0.5,0.0); |
---|
| 896 | tmp->addColor(0.1,0.1,0.1); |
---|
| 897 | tmp->addIndice(9+b); |
---|
| 898 | tmp->addIndice(12+a); |
---|
| 899 | tmp->addVertex(controlsTmp[4].position[0],controlsTmp[4].position[1], controlsTmp[4].position[2]); |
---|
| 900 | tmp->addNormal(1,0,0); |
---|
| 901 | tmp->addTexCoor(0.5,0.5); |
---|
| 902 | tmp->addColor(0.1,0.1,0.1); |
---|
| 903 | tmp->addIndice(10+b); |
---|
| 904 | tmp->addIndice(13+a); |
---|
| 905 | tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]); |
---|
| 906 | tmp->addNormal(1,0,0); |
---|
| 907 | tmp->addTexCoor(0.5,1.0); |
---|
| 908 | tmp->addColor(0.1,0.1,0.1); |
---|
| 909 | tmp->addIndice(11+b); |
---|
| 910 | tmp->addIndice(14+a); |
---|
| 911 | tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]+0.01); |
---|
| 912 | tmp->addNormal(1,0,0); |
---|
| 913 | tmp->addTexCoor(0.5,1.0); |
---|
| 914 | tmp->addColor(0.1,0.1,0.1); |
---|
| 915 | |
---|
| 916 | tmp->addIndice(15+a); |
---|
| 917 | //tmp->addIndice(9); |
---|
| 918 | tmp->newStripe(); |
---|
| 919 | |
---|
| 920 | tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]); |
---|
| 921 | tmp->addNormal(1,0,0); |
---|
| 922 | tmp->addTexCoor(1.0,0.0); |
---|
| 923 | tmp->addColor(0.1,0.1,0.1); |
---|
| 924 | tmp->addIndice(13+b); |
---|
| 925 | tmp->addIndice(16+a); |
---|
| 926 | |
---|
| 927 | tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]); |
---|
| 928 | tmp->addNormal(0,1,0); |
---|
| 929 | tmp->addTexCoor(1.0,0.5); |
---|
| 930 | tmp->addColor(0.1,0.1,0.1); |
---|
| 931 | tmp->addIndice(14+b); |
---|
| 932 | tmp->addIndice(17+a); |
---|
| 933 | tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); |
---|
| 934 | tmp->addNormal(1,0,0); |
---|
| 935 | tmp->addTexCoor(1.0,1.0); |
---|
| 936 | tmp->addColor(0.1,0.1,0.1); |
---|
| 937 | tmp->addIndice(15+b); |
---|
| 938 | tmp->addIndice(18+a); |
---|
| 939 | tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); |
---|
| 940 | tmp->addNormal(1,0,0); |
---|
| 941 | tmp->addTexCoor(1.0,1.0); |
---|
| 942 | tmp->addColor(0.1,0.1,0.1); |
---|
| 943 | tmp->addIndice(19+a); |
---|
| 944 | //tmp->addIndice(13); |
---|
| 945 | |
---|
| 946 | tmp->newStripe(); |
---|
| 947 | tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]); |
---|
| 948 | tmp->addNormal(1,0,0); |
---|
| 949 | tmp->addTexCoor(1.0,0.0); |
---|
| 950 | tmp->addColor(0.1,0.1,0.1); |
---|
| 951 | tmp->addIndice(17+b); |
---|
| 952 | |
---|
| 953 | tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]); |
---|
| 954 | tmp->addNormal(0,1,0); |
---|
| 955 | tmp->addTexCoor(1.0,0.5); |
---|
| 956 | tmp->addColor(0.1,0.1,0.1); |
---|
| 957 | tmp->addIndice(18+b); |
---|
| 958 | |
---|
| 959 | tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); |
---|
| 960 | tmp->addNormal(1,0,0); |
---|
| 961 | tmp->addTexCoor(1.0,1.0); |
---|
| 962 | tmp->addColor(0.1,0.1,0.1); |
---|
| 963 | tmp->addIndice(19+b); |
---|
| 964 | |
---|
| 965 | tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); |
---|
| 966 | tmp->addNormal(1,0,0); |
---|
| 967 | tmp->addTexCoor(1.0,1.0); |
---|
| 968 | tmp->addColor(0.1,0.1,0.1); |
---|
| 969 | |
---|
| 970 | tmp->newStripe(); |
---|
| 971 | |
---|
| 972 | tmp->finalize(); |
---|
| 973 | // End of DebugModel |
---|
| 974 | |
---|
| 975 | this->patchOffset++; |
---|
| 976 | }// For |
---|
| 977 | } // For |
---|
| 978 | |
---|
| 979 | // Overwrite Face->meshvert; |
---|
| 980 | // Overwrite Face->n_meshverts; |
---|
[7465] | 981 | int sz = (size0 -1)/2 * (size1 -1)/2; // num patches |
---|
[7395] | 982 | Face->meshvert = patchOffset -sz; //3*(patchOffset-sz)*level1*level1; |
---|
| 983 | Face->n_meshverts = sz; |
---|
| 984 | PRINTF(0)("BSP FILE: sz: %i. \n", sz); |
---|
| 985 | PRINTF(0)("BSP FILE: Face->meshvert %i . \n", Face->meshvert); |
---|
| 986 | |
---|
| 987 | //Face->n_meshverts = sz; |
---|
[7353] | 988 | } |
---|
[7801] | 989 | |
---|
[8081] | 990 | //!TODO: This is a good place to do LittleEndian to BigEndian conversion! |
---|
[7801] | 991 | void BspFile::swapAllBspCoordinates() |
---|
| 992 | { |
---|
[8088] | 993 | |
---|
[7805] | 994 | for(int i = 0; i < this->numVertex ; ++i) |
---|
| 995 | { |
---|
| 996 | this->swapCoords(&((BspVertex *)this->vertice)[i].position[0]); |
---|
| 997 | this->swapCoords(&((BspVertex *)this->vertice)[i].normal[0]); |
---|
| 998 | |
---|
[8088] | 999 | |
---|
[7805] | 1000 | } |
---|
[8088] | 1001 | |
---|
[7805] | 1002 | for(int i = 0; i < this->numLeafs ; ++i) |
---|
| 1003 | { |
---|
| 1004 | this->swapCoords(this->leaves[i].mins); |
---|
| 1005 | this->swapCoords(this->leaves[i].maxs); |
---|
[8088] | 1006 | |
---|
[7805] | 1007 | } |
---|
[8088] | 1008 | |
---|
[7805] | 1009 | for(int i = 0; i < this->numPlanes; ++i) |
---|
| 1010 | { |
---|
| 1011 | float sto = this->planes[i].x; |
---|
[8030] | 1012 | this->planes[i].x = this->planes[i].y; |
---|
| 1013 | this->planes[i].y = this->planes[i].z; |
---|
[7805] | 1014 | this->planes[i].z = sto; |
---|
[8030] | 1015 | this->planes[i].d = scale * this->planes[i].d ; |
---|
[7805] | 1016 | } |
---|
| 1017 | |
---|
[8088] | 1018 | |
---|
[7805] | 1019 | for(int i = 0; i < this->numFaces; ++i) |
---|
| 1020 | { |
---|
| 1021 | this->swapCoords(this->faces[i].normal); |
---|
| 1022 | } |
---|
[8088] | 1023 | |
---|
[7801] | 1024 | } |
---|
| 1025 | |
---|
[7805] | 1026 | void BspFile::swapCoords(int *array) |
---|
[7801] | 1027 | { |
---|
[8081] | 1028 | if( scale < 1) |
---|
| 1029 | { |
---|
[7805] | 1030 | int sto = array[0]; |
---|
[8030] | 1031 | array[0] = array[1] / (int) ( 1/ scale); |
---|
| 1032 | array[1] = array[2] / (int) (1/scale); |
---|
| 1033 | array[2] = sto / (int) (1/scale); |
---|
[8081] | 1034 | } |
---|
| 1035 | else |
---|
| 1036 | { |
---|
| 1037 | int sto = array[0]; |
---|
| 1038 | array[0] = scale * array[1] ; |
---|
| 1039 | array[1] = scale * array[2]; |
---|
[8088] | 1040 | array[2] = scale * sto ; |
---|
[8081] | 1041 | } |
---|
[8088] | 1042 | |
---|
[7801] | 1043 | } |
---|
| 1044 | |
---|
[7805] | 1045 | void BspFile::swapCoords(float * array) |
---|
[7801] | 1046 | { |
---|
[7805] | 1047 | float sto = array[0]; |
---|
[8030] | 1048 | array[0] = scale * array[1]; |
---|
| 1049 | array[1] = scale * array[2]; |
---|
| 1050 | array[2] = scale * sto; |
---|
[7801] | 1051 | } |
---|
| 1052 | |
---|