| 1 | /* |
|---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
|---|
| 3 | |
|---|
| 4 | Copyright (C) 2006 orx |
|---|
| 5 | |
|---|
| 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. |
|---|
| 10 | |
|---|
| 11 | ### File Specific: |
|---|
| 12 | main-programmer: bottac@ee.ethz.ch |
|---|
| 13 | |
|---|
| 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/ |
|---|
| 18 | */ |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | #include "bsp_file.h" |
|---|
| 22 | #include "bsp_tree_node.h" |
|---|
| 23 | #include <fstream> |
|---|
| 24 | #include "util/loading/resource_manager.h" |
|---|
| 25 | |
|---|
| 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" |
|---|
| 34 | #include "movie_player.h" |
|---|
| 35 | |
|---|
| 36 | #include <SDL/SDL_endian.h> |
|---|
| 37 | #include <SDL/SDL_image.h> |
|---|
| 38 | |
|---|
| 39 | // STL Containers |
|---|
| 40 | #include <vector> |
|---|
| 41 | |
|---|
| 42 | using namespace std; |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | // Constructor |
|---|
| 46 | BspFile::BspFile() |
|---|
| 47 | {} |
|---|
| 48 | |
|---|
| 49 | /** |
|---|
| 50 | * Loads a quake3 level (*.bsp) |
|---|
| 51 | * @param name the Name of the *.bsp file |
|---|
| 52 | */ |
|---|
| 53 | int BspFile::read(const char* name) |
|---|
| 54 | { |
|---|
| 55 | this->scale = 1.0; |
|---|
| 56 | int offset; |
|---|
| 57 | int size; |
|---|
| 58 | struct stat results; |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 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]; |
|---|
| 78 | bspFile.seekg(offset); |
|---|
| 79 | bspFile.read((char*)this->nodes, size); |
|---|
| 80 | |
|---|
| 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]; |
|---|
| 90 | bspFile.seekg(offset); |
|---|
| 91 | bspFile.read((char*)this->planes, size); |
|---|
| 92 | |
|---|
| 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]; |
|---|
| 102 | bspFile.seekg(offset); |
|---|
| 103 | bspFile.read((char*)this->leaves, size); |
|---|
| 104 | |
|---|
| 105 | // Get the Models |
|---|
| 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]; |
|---|
| 114 | bspFile.seekg(offset); |
|---|
| 115 | bspFile.read((char*)this->bspModels, size); |
|---|
| 116 | |
|---|
| 117 | // Get the leafFaces |
|---|
| 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); |
|---|
| 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 |
|---|
| 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); |
|---|
| 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 |
|---|
| 142 | offset = SDL_SwapLE32(((int *)(header))[18]); |
|---|
| 143 | size = SDL_SwapLE32(((int *)(header))[19]); |
|---|
| 144 | PRINTF(4)("BSP FILE: BrushesSize: %i Bytes. \n", size); |
|---|
| 145 | PRINTF(4)("BSP FILE: NumBrushes: %i. \n", size / sizeof(brush)); |
|---|
| 146 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(brush)); |
|---|
| 147 | PRINTF(4)("BSP FILE: BrushesOffset: %i. \n", offset); |
|---|
| 148 | this->brushes = new brush [size/sizeof(brush)]; |
|---|
| 149 | bspFile.seekg(offset); |
|---|
| 150 | bspFile.read((char*)this->brushes, size); |
|---|
| 151 | |
|---|
| 152 | // Get the brushSides |
|---|
| 153 | offset = SDL_SwapLE32(((int *)(header))[20]); |
|---|
| 154 | size = SDL_SwapLE32(((int *)(header))[21]); |
|---|
| 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); |
|---|
| 159 | this->numBrushSides = size/sizeof(brushside); |
|---|
| 160 | this->brushSides = new brushside [this->numBrushSides]; |
|---|
| 161 | bspFile.seekg(offset); |
|---|
| 162 | bspFile.read((char*)this->brushSides, size); |
|---|
| 163 | |
|---|
| 164 | // Get the Vertice |
|---|
| 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); |
|---|
| 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 |
|---|
| 177 | offset = SDL_SwapLE32(((int *)(header))[24]); |
|---|
| 178 | size = SDL_SwapLE32(((int *)(header))[25]); |
|---|
| 179 | PRINTF(4)("BSP FILE: MeshVertsSize: %i Bytes. \n", size); |
|---|
| 180 | PRINTF(4)("BSP FILE: NumMeshVerts: %i. \n", size / sizeof(meshvert)); |
|---|
| 181 | PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(meshvert)); |
|---|
| 182 | PRINTF(4)("BSP FILE: MeshVertsOffset: %i. \n", offset); |
|---|
| 183 | this->meshverts = new meshvert [size / sizeof(meshvert)]; |
|---|
| 184 | bspFile.seekg(offset); |
|---|
| 185 | bspFile.read((char*)this->meshverts, size); |
|---|
| 186 | |
|---|
| 187 | // Get the Faces |
|---|
| 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]; |
|---|
| 196 | bspFile.seekg(offset); |
|---|
| 197 | bspFile.read((char*)this->faces, size); |
|---|
| 198 | |
|---|
| 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 | |
|---|
| 208 | // Get the Visdata |
|---|
| 209 | offset = SDL_SwapLE32(((int *)(header))[34]); |
|---|
| 210 | size = SDL_SwapLE32(((int *)(header))[35]); |
|---|
| 211 | |
|---|
| 212 | this->visData = new char [size]; |
|---|
| 213 | bspFile.seekg(offset); |
|---|
| 214 | bspFile.read(this->visData, size); |
|---|
| 215 | |
|---|
| 216 | PRINTF(0)("BSP FILE: VisDataSize: %i Bytes. \n", size); |
|---|
| 217 | PRINTF(0)("BSP FILE: NumVisData: %i. \n", size /1 - 8); |
|---|
| 218 | PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 1); |
|---|
| 219 | PRINTF(0)("BSP FILE: VisDataOffset: %i. \n", offset); |
|---|
| 220 | |
|---|
| 221 | // Get the Textures |
|---|
| 222 | offset = SDL_SwapLE32(((int *)(header))[4]); |
|---|
| 223 | size = SDL_SwapLE32(((int *)(header))[5]); |
|---|
| 224 | |
|---|
| 225 | this->textures= new char [size]; |
|---|
| 226 | bspFile.seekg(offset); |
|---|
| 227 | bspFile.read(this->textures, size); |
|---|
| 228 | |
|---|
| 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); |
|---|
| 233 | this->numTextures = size/72; |
|---|
| 234 | |
|---|
| 235 | bspFile.close(); |
|---|
| 236 | |
|---|
| 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(); |
|---|
| 240 | |
|---|
| 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]); |
|---|
| 245 | |
|---|
| 246 | //Create white texture for if no lightmap specified |
|---|
| 247 | glGenTextures(1, &this->whiteLightMap); |
|---|
| 248 | glBindTexture(GL_TEXTURE_2D, this->whiteLightMap); |
|---|
| 249 | //Create texture |
|---|
| 250 | this->whiteTexture[0]=255; |
|---|
| 251 | this->whiteTexture[1]=255; |
|---|
| 252 | this->whiteTexture[2]=255; |
|---|
| 253 | |
|---|
| 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); |
|---|
| 258 | |
|---|
| 259 | glTexParameterf(GL_TEXTURE_ENV, GL_TEXTURE_PRIORITY, 2); |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 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, |
|---|
| 270 | GL_RGBA8, |
|---|
| 271 | 1, |
|---|
| 272 | 1, |
|---|
| 273 | 0, |
|---|
| 274 | GL_RGB, |
|---|
| 275 | GL_UNSIGNED_BYTE, |
|---|
| 276 | (const GLvoid *)&(this->whiteTexture)); |
|---|
| 277 | |
|---|
| 278 | gluBuild2DMipmaps( GL_TEXTURE_2D, GL_RGBA8, 1, 1, |
|---|
| 279 | GL_RGB, GL_UNSIGNED_BYTE,(const GLvoid *) &(this->whiteTexture)); |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | // Get the number of patches |
|---|
| 284 | this->numPatches = 0; |
|---|
| 285 | this->patchOffset = 0; |
|---|
| 286 | |
|---|
| 287 | for( int i = 0; i < this->numFaces; i++) { |
|---|
| 288 | face& cFace = ((face *)(this->faces))[i]; |
|---|
| 289 | if (SDL_SwapLE32(cFace.type) == 2) |
|---|
| 290 | this->numPatches += (SDL_SwapLE32(cFace.size[0]) -1 ) / 2 * (SDL_SwapLE32(cFace.size[1]) -1) / 2; |
|---|
| 291 | } |
|---|
| 292 | |
|---|
| 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 | |
|---|
| 300 | PRINTF(0)("BSP FILE:NumberOfPatches: %i . \n", numPatches); |
|---|
| 301 | |
|---|
| 302 | this->swapAllBspCoordinates(); |
|---|
| 303 | |
|---|
| 304 | // Do tesselation for all Faces of type 2 |
|---|
| 305 | for( int i = 0; i < this->numFaces; i++) { |
|---|
| 306 | if (SDL_SwapLE32((this->faces)[i].type) == 2) |
|---|
| 307 | this->tesselate(i); |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | PRINTF(0)("BSP FILE:PatchOffset: %i . \n", this->patchOffset); |
|---|
| 311 | |
|---|
| 312 | return 1; |
|---|
| 313 | } else { |
|---|
| 314 | PRINTF(0)("BSP FILE: Datei nicht gefunden. \n"); |
|---|
| 315 | return -1; |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | } |
|---|
| 321 | |
|---|
| 322 | void BspFile::build_tree() |
|---|
| 323 | { |
|---|
| 324 | |
|---|
| 325 | PRINTF(0)("BSP FILE:\n"); |
|---|
| 326 | PRINTF(0)("BSP FILE: Building Tree...\n"); |
|---|
| 327 | root = this->build_tree_rec(0); |
|---|
| 328 | PRINTF(0)("BSP FILE: ...done. \n"); |
|---|
| 329 | PRINTF(0)("BSP FILE: \n"); |
|---|
| 330 | PRINTF(0)("BSP FILE: Node #0: \n"); |
|---|
| 331 | PRINTF(0)("BSP FILE: x: %f \n",root->plane.x); |
|---|
| 332 | PRINTF(0)("BSP FILE: y: %f\n",root->plane.y); |
|---|
| 333 | PRINTF(0)("BSP FILE: z: %f\n",root->plane.z); |
|---|
| 334 | } |
|---|
| 335 | |
|---|
| 336 | /** |
|---|
| 337 | * Called by BspFile::build_tree() only. |
|---|
| 338 | */ |
|---|
| 339 | BspTreeNode* BspFile::build_tree_rec(int i) |
|---|
| 340 | { |
|---|
| 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; |
|---|
| 350 | thisNode->d = (((plane *) this->planes) [planeIndex]).d; |
|---|
| 351 | |
|---|
| 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); |
|---|
| 366 | } // assign leav |
|---|
| 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; |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | /** |
|---|
| 383 | * returns the root node of the bsp-tree |
|---|
| 384 | */ |
|---|
| 385 | BspTreeNode* BspFile::get_root() |
|---|
| 386 | { |
|---|
| 387 | return root; |
|---|
| 388 | } |
|---|
| 389 | |
|---|
| 390 | void BspFile::load_textures() |
|---|
| 391 | { |
|---|
| 392 | ::std::string absFileName; |
|---|
| 393 | char* baseName = "/worlds/bsp/"; |
|---|
| 394 | |
|---|
| 395 | char fileName [500]; |
|---|
| 396 | char ext [500]; |
|---|
| 397 | struct stat results; |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | this->Materials = new AMat[this->numTextures]; |
|---|
| 401 | for(int i = 0 ; i < this->numTextures; i++) { |
|---|
| 402 | PRINTF(0)("BSP FILE: Texture : %s. \n", &this->textures[8+ 72*i]); |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | strcpy(fileName, &this->textures[8+ 72*i]); |
|---|
| 406 | if(strlen(fileName) == 0) |
|---|
| 407 | { |
|---|
| 408 | |
|---|
| 409 | // Default Material |
|---|
| 410 | this->Materials[i].mat = new Material(); |
|---|
| 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); |
|---|
| 414 | //this->Materials[i]->setShininess(100.0); |
|---|
| 415 | // this->Materials[i].mat->setTransparency(1.0); |
|---|
| 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; |
|---|
| 420 | this->Materials[i].animated = false; |
|---|
| 421 | continue; |
|---|
| 422 | } |
|---|
| 423 | |
|---|
| 424 | // Check for mov |
|---|
| 425 | strcpy(fileName, baseName); |
|---|
| 426 | strcpy(ext, &this->textures[8+ 72*i]); |
|---|
| 427 | strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); |
|---|
| 428 | strcpy(ext, ".mov"); |
|---|
| 429 | strncat (fileName, ext, strlen(fileName) ); |
|---|
| 430 | |
|---|
| 431 | PRINTF(0)("BSP FILE: Name %s . \n", fileName); |
|---|
| 432 | |
|---|
| 433 | absFileName = ResourceManager::getFullName(fileName); |
|---|
| 434 | |
|---|
| 435 | if(File(absFileName).exists()) { |
|---|
| 436 | PRINTF(0)("BSP FILE: gefunden . \n"); |
|---|
| 437 | this->Materials[i] = this->loadAVI(fileName); |
|---|
| 438 | continue; |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | // Check for avi |
|---|
| 442 | strcpy(fileName, baseName); |
|---|
| 443 | strcpy(ext, &this->textures[8+ 72*i]); |
|---|
| 444 | strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); |
|---|
| 445 | strcpy(ext, ".avi"); |
|---|
| 446 | strncat (fileName, ext, strlen(fileName)); |
|---|
| 447 | |
|---|
| 448 | absFileName = ResourceManager::getFullName(fileName); |
|---|
| 449 | |
|---|
| 450 | if(File(absFileName).exists()) { |
|---|
| 451 | PRINTF(0)("BSP FILE: gefunden . \n"); |
|---|
| 452 | this->Materials[i] = this->loadAVI(fileName); |
|---|
| 453 | continue; |
|---|
| 454 | } |
|---|
| 455 | |
|---|
| 456 | // Check for mpg |
|---|
| 457 | strcpy(fileName, baseName); |
|---|
| 458 | strcpy(ext, &this->textures[8+ 72*i]); |
|---|
| 459 | strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); |
|---|
| 460 | strcpy(ext, ".mpg"); |
|---|
| 461 | strncat (fileName, ext, strlen(fileName)); |
|---|
| 462 | |
|---|
| 463 | absFileName = ResourceManager::getFullName(fileName); |
|---|
| 464 | |
|---|
| 465 | if(File(absFileName).exists()) { |
|---|
| 466 | PRINTF(0)("BSP FILE: gefunden . \n"); |
|---|
| 467 | this->Materials[i] = this->loadAVI(fileName); |
|---|
| 468 | continue; |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | // Check for tga |
|---|
| 472 | strcpy(fileName, baseName); |
|---|
| 473 | strcpy(ext, &this->textures[8+ 72*i]); |
|---|
| 474 | strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); |
|---|
| 475 | strcpy(ext, ".tga"); |
|---|
| 476 | strncat (fileName, ext, strlen(fileName)); |
|---|
| 477 | |
|---|
| 478 | absFileName = ResourceManager::getFullName(fileName); |
|---|
| 479 | |
|---|
| 480 | if(File(absFileName).exists()) { |
|---|
| 481 | PRINTF(0)("BSP FILE: gefunden . \n"); |
|---|
| 482 | this->Materials[i] = this->loadMat(fileName); |
|---|
| 483 | continue; |
|---|
| 484 | } |
|---|
| 485 | // Check for TGA |
|---|
| 486 | strcpy(fileName, baseName); |
|---|
| 487 | strcpy(ext, &this->textures[8+ 72*i]); |
|---|
| 488 | strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); |
|---|
| 489 | strcpy(ext, ".TGA"); |
|---|
| 490 | strncat (fileName, ext, strlen(fileName)); |
|---|
| 491 | absFileName = ResourceManager::getFullName(fileName); |
|---|
| 492 | |
|---|
| 493 | if(File(absFileName).exists()/*stat( absFileName.c_str() , &results) == 0*/) { |
|---|
| 494 | PRINTF(0)("BSP FILE: gefunden . \n"); |
|---|
| 495 | this->Materials[i] = this->loadMat(fileName); |
|---|
| 496 | continue; |
|---|
| 497 | } |
|---|
| 498 | // Check for jpg |
|---|
| 499 | strcpy(fileName, baseName); |
|---|
| 500 | strcpy(ext, &this->textures[8+ 72*i]); |
|---|
| 501 | strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); |
|---|
| 502 | strcpy(ext, ".jpg"); |
|---|
| 503 | strncat (fileName, ext, strlen(fileName)); |
|---|
| 504 | absFileName = ResourceManager::getFullName(fileName); |
|---|
| 505 | if(File(absFileName).exists()) { |
|---|
| 506 | PRINTF(0)("BSP FILE: gefunden . \n"); |
|---|
| 507 | this->Materials[i] =this->loadMat(fileName); |
|---|
| 508 | continue; |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | |
|---|
| 512 | // Check for JPG |
|---|
| 513 | strcpy(fileName, baseName); |
|---|
| 514 | strcpy(ext, &this->textures[8+ 72*i]); |
|---|
| 515 | strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); |
|---|
| 516 | strcpy(ext, ".JPG"); |
|---|
| 517 | strncat (fileName, ext, strlen(fileName)); |
|---|
| 518 | absFileName = ResourceManager::getFullName(fileName); |
|---|
| 519 | if(File(absFileName).exists()) { |
|---|
| 520 | PRINTF(0)("BSP FILE: gefunden . \n"); |
|---|
| 521 | this->Materials[i] =this->loadMat(fileName); |
|---|
| 522 | continue; |
|---|
| 523 | } |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | // Check for bmp |
|---|
| 528 | strcpy(fileName, baseName); |
|---|
| 529 | strcpy(ext, &this->textures[8+ 72*i]); |
|---|
| 530 | strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); |
|---|
| 531 | strcpy(ext, ".bmp"); |
|---|
| 532 | strncat (fileName, ext, strlen(fileName)); |
|---|
| 533 | absFileName = ResourceManager::getFullName(fileName); |
|---|
| 534 | |
|---|
| 535 | if(File(absFileName).exists()) { |
|---|
| 536 | PRINTF(0)("BSP FILE: gefunden . \n"); |
|---|
| 537 | this->Materials[i] =this->loadMat(fileName); |
|---|
| 538 | continue; |
|---|
| 539 | } |
|---|
| 540 | |
|---|
| 541 | // Check for BMP |
|---|
| 542 | strcpy(fileName, baseName); |
|---|
| 543 | strcpy(ext, &this->textures[8+ 72*i]); |
|---|
| 544 | strncat(fileName, ext, strlen(fileName) + strlen(&this->textures[8+ 72*i]) ); |
|---|
| 545 | strcpy(ext, ".BMP"); |
|---|
| 546 | strncat (fileName, ext, strlen(fileName)); |
|---|
| 547 | absFileName = ResourceManager::getFullName(fileName); |
|---|
| 548 | |
|---|
| 549 | if(File(absFileName).exists()) { |
|---|
| 550 | PRINTF(0)("BSP FILE: gefunden . \n"); |
|---|
| 551 | this->Materials[i] = this->loadMat(fileName); |
|---|
| 552 | continue; |
|---|
| 553 | } |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | // Default Material |
|---|
| 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); |
|---|
| 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; |
|---|
| 568 | |
|---|
| 569 | } |
|---|
| 570 | } |
|---|
| 571 | |
|---|
| 572 | |
|---|
| 573 | AMat BspFile::loadMat(char* mat) |
|---|
| 574 | { |
|---|
| 575 | AMat tmpAMat; |
|---|
| 576 | this->testSurf = NULL; |
|---|
| 577 | |
|---|
| 578 | this->testSurf = IMG_Load(ResourceManager::getFullName(mat).c_str()); |
|---|
| 579 | if(this->testSurf != NULL) { |
|---|
| 580 | if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; |
|---|
| 581 | else tmpAMat.alpha = false; |
|---|
| 582 | } else tmpAMat.alpha = false; |
|---|
| 583 | |
|---|
| 584 | Material* tmp = new Material(); |
|---|
| 585 | tmp->setDiffuse(1.0,1.0,1.0); |
|---|
| 586 | tmp->setAmbient(1.0,1.0,1.0 ); |
|---|
| 587 | tmp->setSpecular(1.0,1.0,1.0); |
|---|
| 588 | // tmp->setShininess(.5); |
|---|
| 589 | // tmp->setTransparency(0.0); |
|---|
| 590 | |
|---|
| 591 | tmp->setDiffuseMap(mat); |
|---|
| 592 | |
|---|
| 593 | tmpAMat.mat = tmp; |
|---|
| 594 | tmpAMat.animated = false; |
|---|
| 595 | return tmpAMat; |
|---|
| 596 | } |
|---|
| 597 | |
|---|
| 598 | AMat BspFile::loadAVI(char* mat) |
|---|
| 599 | { |
|---|
| 600 | AMat tmpAMat; |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | MoviePlayer * testMC = new MoviePlayer(mat); |
|---|
| 604 | testMC->start(0); |
|---|
| 605 | |
|---|
| 606 | this->MovieMaterials.push_back(testMC); |
|---|
| 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); |
|---|
| 612 | // tmp->setShininess(.5);tmpAMat |
|---|
| 613 | // tmp->setTransparency(0.0); |
|---|
| 614 | |
|---|
| 615 | //tmp->setDiffuseMap(mat); |
|---|
| 616 | |
|---|
| 617 | tmpAMat.aviMat = testMC; |
|---|
| 618 | tmpAMat.animated = true; |
|---|
| 619 | tmpAMat.alpha = true; |
|---|
| 620 | return tmpAMat; |
|---|
| 621 | } |
|---|
| 622 | |
|---|
| 623 | unsigned int BspFile::loadLightMapToGL(lightmap& lightMapTexture) |
|---|
| 624 | { |
|---|
| 625 | int errorCode = 0; //!< the error code for the texture loading functions |
|---|
| 626 | unsigned int lightMap; //!< the OpenGL texture handle |
|---|
| 627 | int mipmapLevel = 0; //!< the maximum mipmap level for this texture |
|---|
| 628 | int mipmapWidth = 0; //!< the width of the mipmap |
|---|
| 629 | int mipmapHight = 0; //!< the height of the mipmap3 |
|---|
| 630 | float sc, scale, temp; |
|---|
| 631 | for(int i = 0; i < 128*128*3 ; i++) |
|---|
| 632 | { |
|---|
| 633 | sc = ((unsigned char *)(&lightMapTexture))[i]; |
|---|
| 634 | sc *= 1/255.0; |
|---|
| 635 | |
|---|
| 636 | scale = 1.0f; // Adjust brightness here |
|---|
| 637 | |
|---|
| 638 | if(sc > 1.0f && (temp = (1.0f/sc)) < scale) scale=temp; |
|---|
| 639 | scale*=255.0; |
|---|
| 640 | sc*=scale; |
|---|
| 641 | if(false) |
|---|
| 642 | ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc + 75; |
|---|
| 643 | else |
|---|
| 644 | ((unsigned char *)(&lightMapTexture))[i] = (unsigned char)sc ; |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 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 | |
|---|
| 672 | |
|---|
| 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 | |
|---|
| 685 | |
|---|
| 686 | return lightMap; |
|---|
| 687 | |
|---|
| 688 | } |
|---|
| 689 | |
|---|
| 690 | /** |
|---|
| 691 | * Generates a vertex-array, a indice-array and a texture-coordinates-array for iface. |
|---|
| 692 | * @param iface integer index of face |
|---|
| 693 | * @todo cleanup this function, let the user choose the level of tesselation |
|---|
| 694 | */ |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | void BspFile::tesselate(int iface) |
|---|
| 698 | { |
|---|
| 699 | face* Face = &((this->faces)[iface]); |
|---|
| 700 | BspVertex * BspVrtx = (BspVertex*)this->vertice; |
|---|
| 701 | int level = 7; |
|---|
| 702 | int level1 = 8; |
|---|
| 703 | int size0 = (Face->size[0]); |
|---|
| 704 | int size1 = (Face->size[1]); |
|---|
| 705 | // For each patch... |
|---|
| 706 | for(int i = 0; i < ( size0 - 1) ; i+=2) { |
|---|
| 707 | for(int j = 0; j < ( size1 -1) ; j+=2) { |
|---|
| 708 | |
|---|
| 709 | |
|---|
| 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++) { |
|---|
| 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*/ |
|---|
| 720 | |
|---|
| 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*/ |
|---|
| 724 | |
|---|
| 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]); |
|---|
| 728 | |
|---|
| 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]); |
|---|
| 732 | |
|---|
| 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]); |
|---|
| 737 | |
|---|
| 738 | |
|---|
| 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]); |
|---|
| 747 | |
|---|
| 748 | for(int v=0; v<=level; ++v) { |
|---|
| 749 | px=(float)v/level; |
|---|
| 750 | |
|---|
| 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); |
|---|
| 754 | |
|---|
| 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); |
|---|
| 758 | |
|---|
| 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); |
|---|
| 763 | |
|---|
| 764 | } |
|---|
| 765 | |
|---|
| 766 | |
|---|
| 767 | for(int u=1; u<=level; ++u) { |
|---|
| 768 | py=(float)u/level; |
|---|
| 769 | |
|---|
| 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); |
|---|
| 774 | |
|---|
| 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); |
|---|
| 778 | |
|---|
| 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); |
|---|
| 783 | |
|---|
| 784 | |
|---|
| 785 | |
|---|
| 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); |
|---|
| 790 | |
|---|
| 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); |
|---|
| 794 | |
|---|
| 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); |
|---|
| 799 | |
|---|
| 800 | |
|---|
| 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); |
|---|
| 805 | |
|---|
| 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); |
|---|
| 809 | |
|---|
| 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); |
|---|
| 814 | |
|---|
| 815 | |
|---|
| 816 | |
|---|
| 817 | |
|---|
| 818 | for(int v=0; v<=level; ++v) { |
|---|
| 819 | px=(float)v/level; |
|---|
| 820 | |
|---|
| 821 | |
|---|
| 822 | |
|---|
| 823 | |
|---|
| 824 | |
|---|
| 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); |
|---|
| 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); |
|---|
| 829 | |
|---|
| 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); |
|---|
| 833 | |
|---|
| 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); |
|---|
| 838 | |
|---|
| 839 | |
|---|
| 840 | |
|---|
| 841 | } |
|---|
| 842 | } |
|---|
| 843 | |
|---|
| 844 | //Create indices |
|---|
| 845 | GLuint* indices= & ((GLuint*)(this->patchIndexes))[level*level1*2*this->patchOffset]; |
|---|
| 846 | |
|---|
| 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 | //*********************************************************************************************************************** |
|---|
| 860 | |
|---|
| 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; |
|---|
| 1011 | int sz = (size0 -1)/2 * (size1 -1)/2; // num patches |
|---|
| 1012 | Face->meshvert = patchOffset -sz; //3*(patchOffset-sz)*level1*level1; |
|---|
| 1013 | Face->n_meshverts = sz; |
|---|
| 1014 | PRINTF(0)("BSP FILE: sz: %i. \n", sz); |
|---|
| 1015 | PRINTF(0)("BSP FILE: Face->meshvert %i . \n", Face->meshvert); |
|---|
| 1016 | |
|---|
| 1017 | //Face->n_meshverts = sz; |
|---|
| 1018 | } |
|---|
| 1019 | |
|---|
| 1020 | //!TODO: This is a good place to do LittleEndian to BigEndian conversion! |
|---|
| 1021 | void BspFile::swapAllBspCoordinates() |
|---|
| 1022 | { |
|---|
| 1023 | |
|---|
| 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 | |
|---|
| 1029 | |
|---|
| 1030 | } |
|---|
| 1031 | |
|---|
| 1032 | for(int i = 0; i < this->numLeafs ; ++i) |
|---|
| 1033 | { |
|---|
| 1034 | this->swapCoords(this->leaves[i].mins); |
|---|
| 1035 | this->swapCoords(this->leaves[i].maxs); |
|---|
| 1036 | |
|---|
| 1037 | } |
|---|
| 1038 | |
|---|
| 1039 | for(int i = 0; i < this->numPlanes; ++i) |
|---|
| 1040 | { |
|---|
| 1041 | float sto = this->planes[i].x; |
|---|
| 1042 | this->planes[i].x = this->planes[i].y; |
|---|
| 1043 | this->planes[i].y = this->planes[i].z; |
|---|
| 1044 | this->planes[i].z = sto; |
|---|
| 1045 | this->planes[i].d = scale * this->planes[i].d ; |
|---|
| 1046 | } |
|---|
| 1047 | |
|---|
| 1048 | |
|---|
| 1049 | for(int i = 0; i < this->numFaces; ++i) |
|---|
| 1050 | { |
|---|
| 1051 | this->swapCoords(this->faces[i].normal); |
|---|
| 1052 | } |
|---|
| 1053 | |
|---|
| 1054 | } |
|---|
| 1055 | |
|---|
| 1056 | void BspFile::swapCoords(int *array) |
|---|
| 1057 | { |
|---|
| 1058 | if( scale < 1) |
|---|
| 1059 | { |
|---|
| 1060 | int sto = array[0]; |
|---|
| 1061 | array[0] = array[1] / (int) ( 1/ scale); |
|---|
| 1062 | array[1] = array[2] / (int) (1/scale); |
|---|
| 1063 | array[2] = sto / (int) (1/scale); |
|---|
| 1064 | } |
|---|
| 1065 | else |
|---|
| 1066 | { |
|---|
| 1067 | int sto = array[0]; |
|---|
| 1068 | array[0] = scale * array[1] ; |
|---|
| 1069 | array[1] = scale * array[2]; |
|---|
| 1070 | array[2] = scale * sto ; |
|---|
| 1071 | } |
|---|
| 1072 | |
|---|
| 1073 | } |
|---|
| 1074 | |
|---|
| 1075 | void BspFile::swapCoords(float * array) |
|---|
| 1076 | { |
|---|
| 1077 | float sto = array[0]; |
|---|
| 1078 | array[0] = scale * array[1]; |
|---|
| 1079 | array[1] = scale * array[2]; |
|---|
| 1080 | array[2] = scale * sto; |
|---|
| 1081 | } |
|---|
| 1082 | |
|---|