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