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