Changeset 7395 in orxonox.OLD for branches/bsp_model/src
- Timestamp:
- Apr 27, 2006, 3:35:01 PM (19 years ago)
- Location:
- branches/bsp_model/src/lib/graphics/importer
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bsp_model/src/lib/graphics/importer/bsp_file.cc
r7385 r7395 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2006 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: bottac@ee.ethz.ch … … 34 34 // Constructor 35 35 BspFile::BspFile() 36 { 37 38 } 36 {} 39 37 40 38 int BspFile::read(char* name) … … 44 42 struct stat results; 45 43 name = "/root/data/Kanti175.bsp"; 46 47 if (stat( name , &results) == 0) 48 { 49 PRINTF(0)("BSP FILE: Datei gefunden. \n"); 50 ifstream bspFile (name, ios::in | ios::binary); 51 bspFile.read(this->header, 260); 52 PRINTF(0)("BSP FILE: BSPVersion: %i. \n", ((int *)(header) )[1]); 53 if((((int *)(header) )[1]) == 46) PRINTF(0)("BSP FILE: This is the good one! :-) \n"); 54 else PRINTF(0)("BSP FILE: Wrong BSPVersion.\n"); 55 56 // Get the Nodes 57 offset = ((int *)(header) )[8]; 58 size = ((int *)(header))[9]; 59 PRINTF(0)("BSP FILE: NodeSize: %i Bytes. \n", size); 60 PRINTF(0)("BSP FILE: NumNodes: %i. \n", size / 36); 61 PRINTF(0)("BSP FILE: Remainder: %i. \n", size %36); 62 PRINTF(0)("BSP FILE: NodeOffset: %i. \n", offset); 63 this->numNodes = size/36; 64 this->nodes = new char [size]; 65 bspFile.seekg(offset); 66 bspFile.read(this->nodes, size); 67 68 // and their Planes 69 offset = ((int *)(header) )[6]; 70 size = ((int *)(header))[7]; 71 PRINTF(0)("BSP FILE: PlanesSize: %i Bytes. \n", size); 72 PRINTF(0)("BSP FILE: NumPlanes: %i. \n", size / 16); 73 PRINTF(0)("BSP FILE: Remainder: %i. \n", size %16); 74 PRINTF(0)("BSP FILE: PlanesOffset: %i. \n", offset); 75 this->numPlanes = size/16; 76 this->planes = new char [size]; 77 bspFile.seekg(offset); 78 bspFile.read(this->planes, size); 79 80 // Get the Leafs 81 offset = ((int *)(header) )[10]; 82 size = ((int *)(header))[11]; 83 PRINTF(0)("BSP FILE: LeaveSize: %i Bytes. \n", size); 84 PRINTF(0)("BSP FILE: NumLeaves: %i. \n", size / 48); 85 PRINTF(0)("BSP FILE: Remainder: %i. \n", size % 48); 86 PRINTF(0)("BSP FILE: LeaveOffset: %i. \n", offset); 87 this->numLeafs = size/48; 88 this->leaves = new char [size]; 89 bspFile.seekg(offset); 90 bspFile.read(this->leaves, size); 44 45 if (stat( name , &results) == 0) { 46 PRINTF(0)("BSP FILE: Datei %s gefunden. \n", name); 47 ifstream bspFile (name, ios::in | ios::binary); 48 bspFile.read(this->header, 260); 49 PRINTF(0)("BSP FILE: BSPVersion: %i. \n", ((int *)(header) )[1]); 50 if(SDL_SwapLE32(((int *)(header) )[1]) == 46) PRINTF(0)("BSP FILE: This is the good one! :-) \n"); 51 else PRINTF(0)("BSP FILE: Wrong BSPVersion.\n"); //!< now, we should do some error handling 52 53 // Get the Nodes 54 offset = SDL_SwapLE32(((int *)(header) )[8]); 55 size = SDL_SwapLE32(((int *)(header))[9]); 56 PRINTF(4)("BSP FILE: NodeSize: %i Bytes. \n", size); 57 PRINTF(4)("BSP FILE: NumNodes: %i. \n", size / sizeof(node)); 58 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(node)); 59 PRINTF(4)("BSP FILE: NodeOffset: %i. \n", offset); 60 this->numNodes = size/sizeof(node); 61 this->nodes = new node [this->numNodes]; 62 bspFile.seekg(offset); 63 bspFile.read((char*)this->nodes, size); 64 65 // and their Planes 66 offset = SDL_SwapLE32(((int *)(header) )[6]); 67 size = SDL_SwapLE32(((int *)(header))[7]); 68 PRINTF(4)("BSP FILE: PlanesSize: %i Bytes. \n", size); 69 PRINTF(4)("BSP FILE: NumPlanes: %i. \n", size / sizeof(plane)); 70 PRINTF(4)("BSP FILE: Remainder: %i. \n", sizeof(plane)); 71 PRINTF(4)("BSP FILE: PlanesOffset: %i. \n", offset); 72 this->numPlanes = size/sizeof(plane); 73 this->planes = new plane [this->numPlanes]; 74 bspFile.seekg(offset); 75 bspFile.read((char*)this->planes, size); 76 77 // Get the Leafs 78 offset = SDL_SwapLE32(((int *)(header) )[10]); 79 size = SDL_SwapLE32(((int *)(header))[11]); 80 PRINTF(4)("BSP FILE: LeaveSize: %i Bytes. \n", size); 81 PRINTF(4)("BSP FILE: NumLeaves: %i. \n", size / sizeof(leaf)); 82 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(leaf)); 83 PRINTF(4)("BSP FILE: LeaveOffset: %i. \n", offset); 84 this->numLeafs = size/sizeof(leaf); 85 this->leaves = new leaf [this->numLeafs]; 86 bspFile.seekg(offset); 87 bspFile.read((char*)this->leaves, size); 91 88 92 89 // Get the Models 93 offset = ((int *)(header))[16];94 size = ((int *)(header))[17];95 PRINTF( 0)("BSP FILE: ModelsSize: %i Bytes. \n", size);96 PRINTF( 0)("BSP FILE: NumModels: %i. \n", size / 40);97 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 40);98 PRINTF( 0)("BSP FILE: ModelsOffset: %i. \n", offset);99 this->numBspModels = size/ 40;100 this->bspModels = new char [size];101 bspFile.seekg(offset); 102 bspFile.read( this->bspModels, size);90 offset = SDL_SwapLE32(((int *)(header))[16]); 91 size = SDL_SwapLE32(((int *)(header))[17]); 92 PRINTF(4)("BSP FILE: ModelsSize: %i Bytes. \n", size); 93 PRINTF(4)("BSP FILE: NumModels: %i. \n", size / sizeof(model)); 94 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(model)); 95 PRINTF(4)("BSP FILE: ModelsOffset: %i. \n", offset); 96 this->numBspModels = size/sizeof(model); 97 this->bspModels = new model [this->numBspModels]; 98 bspFile.seekg(offset); 99 bspFile.read((char*)this->bspModels, size); 103 100 104 101 // Get the leafFaces 105 offset = ((int *)(header))[12];106 size = ((int *)(header))[13];107 PRINTF( 0)("BSP FILE: leafFacesSize: %i Bytes. \n", size);108 PRINTF( 0)("BSP FILE: NumleafFaces: %i. \n", size / 4);109 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 4);110 PRINTF( 0)("BSP FILE: leafFacesOffset: %i. \n", offset);102 offset = SDL_SwapLE32(((int *)(header))[12]); 103 size = SDL_SwapLE32(((int *)(header))[13]); 104 PRINTF(4)("BSP FILE: leafFacesSize: %i Bytes. \n", size); 105 PRINTF(4)("BSP FILE: NumleafFaces: %i. \n", size / 4); 106 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4); 107 PRINTF(4)("BSP FILE: leafFacesOffset: %i. \n", offset); 111 108 this->numLeafFaces = size/4; 112 109 this->leafFaces = new char [size]; … … 115 112 116 113 // Get the leafBrushes 117 offset = ((int *)(header))[14];118 size = ((int *)(header))[15];119 PRINTF( 0)("BSP FILE: leafBrushesSize: %i Bytes. \n", size);120 PRINTF( 0)("BSP FILE: NumleafBrushes: %i. \n", size / 4);121 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 4);122 PRINTF( 0)("BSP FILE: leafBrushesOffset: %i. \n", offset);114 offset = SDL_SwapLE32(((int *)(header))[14]); 115 size = SDL_SwapLE32(((int *)(header))[15]); 116 PRINTF(4)("BSP FILE: leafBrushesSize: %i Bytes. \n", size); 117 PRINTF(4)("BSP FILE: NumleafBrushes: %i. \n", size / 4); 118 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4); 119 PRINTF(4)("BSP FILE: leafBrushesOffset: %i. \n", offset); 123 120 this->numLeafBrushes = size/4; 124 121 this->leafBrushes = new char [size]; … … 127 124 128 125 // Get the brushes 129 offset = ((int *)(header))[18];130 size = ((int *)(header))[19];131 PRINTF( 0)("BSP FILE: BrushesSize: %i Bytes. \n", size);132 PRINTF( 0)("BSP FILE: NumBrushes: %i. \n", size / 12);133 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 12);134 PRINTF( 0)("BSP FILE: BrushesOffset: %i. \n", offset);126 offset = SDL_SwapLE32(((int *)(header))[18]); 127 size = SDL_SwapLE32(((int *)(header))[19]); 128 PRINTF(4)("BSP FILE: BrushesSize: %i Bytes. \n", size); 129 PRINTF(4)("BSP FILE: NumBrushes: %i. \n", size / 12); 130 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 12); 131 PRINTF(4)("BSP FILE: BrushesOffset: %i. \n", offset); 135 132 this->brushes = new char [size]; 136 133 bspFile.seekg(offset); … … 138 135 139 136 // Get the brushSides 140 offset = ((int *)(header))[20];137 offset = SDL_SwapLE32(((int *)(header))[20]); 141 138 size = SDL_SwapLE32(((int *)(header))[21]); 142 PRINTF( 0)("BSP FILE: BrushSidesSize: %i Bytes. \n", size);143 PRINTF( 0)("BSP FILE: NumBrushSides: %i. \n", size / 8);144 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 8);145 PRINTF( 0)("BSP FILE: BrushSidesOffset: %i. \n", offset);139 PRINTF(4)("BSP FILE: BrushSidesSize: %i Bytes. \n", size); 140 PRINTF(4)("BSP FILE: NumBrushSides: %i. \n", size / 8); 141 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 8); 142 PRINTF(4)("BSP FILE: BrushSidesOffset: %i. \n", offset); 146 143 this->brushSides = new char [size]; 147 144 this->numBrushSides = size/8; … … 150 147 151 148 // Get the Vertice 152 offset = ((int *)(header))[22];153 size = ((int *)(header))[23];154 PRINTF( 0)("BSP FILE: VerticeSize: %i Bytes. \n", size);155 PRINTF( 0)("BSP FILE: NumVertice: %i. \n", size / 44);156 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 44);157 PRINTF( 0)("BSP FILE: VerticeOffset: %i. \n", offset);149 offset = SDL_SwapLE32(((int *)(header))[22]); 150 size = SDL_SwapLE32(((int *)(header))[23]); 151 PRINTF(4)("BSP FILE: VerticeSize: %i Bytes. \n", size); 152 PRINTF(4)("BSP FILE: NumVertice: %i. \n", size / 44); 153 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 44); 154 PRINTF(4)("BSP FILE: VerticeOffset: %i. \n", offset); 158 155 this->numVertex = size/44; 159 156 this->vertice = new char [size]; … … 162 159 163 160 // Get the MeshVerts 164 offset = ((int *)(header))[24];165 size = ((int *)(header))[25];166 PRINTF( 0)("BSP FILE: MeshVertsSize: %i Bytes. \n", size);167 PRINTF( 0)("BSP FILE: NumMeshVerts: %i. \n", size / 4);168 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 4);169 PRINTF( 0)("BSP FILE: MeshVertsOffset: %i. \n", offset);161 offset = SDL_SwapLE32(((int *)(header))[24]); 162 size = SDL_SwapLE32(((int *)(header))[25]); 163 PRINTF(4)("BSP FILE: MeshVertsSize: %i Bytes. \n", size); 164 PRINTF(4)("BSP FILE: NumMeshVerts: %i. \n", size / 4); 165 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 4); 166 PRINTF(4)("BSP FILE: MeshVertsOffset: %i. \n", offset); 170 167 this->meshverts = new char [size]; 171 168 bspFile.seekg(offset); … … 173 170 174 171 // Get the Faces 175 offset = ((int *)(header))[28];176 size = ((int *)(header))[29];177 PRINTF( 0)("BSP FILE: FacesSize: %i Bytes. \n", size);178 PRINTF( 0)("BSP FILE: NumFaces: %i. \n", size / 104);179 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 104);180 PRINTF( 0)("BSP FILE: FacesOffset: %i. \n", offset);181 this->numFaces = size/ 104;182 this->faces = new char [size];183 bspFile.seekg(offset); 184 bspFile.read( this->faces, size);172 offset = SDL_SwapLE32(((int *)(header))[28]); 173 size = SDL_SwapLE32(((int *)(header))[29]); 174 PRINTF(4)("BSP FILE: FacesSize: %i Bytes. \n", size); 175 PRINTF(4)("BSP FILE: NumFaces: %i. \n", size / sizeof(face)); 176 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % sizeof(face)); 177 PRINTF(4)("BSP FILE: FacesOffset: %i. \n", offset); 178 this->numFaces = size/sizeof(face); 179 this->faces = new face [this->numFaces]; 180 bspFile.seekg(offset); 181 bspFile.read((char*)this->faces, size); 185 182 186 183 // Get the Visdata 187 offset = ((int *)(header))[34];188 size = ((int *)(header))[35];184 offset = SDL_SwapLE32(((int *)(header))[34]); 185 size = SDL_SwapLE32(((int *)(header))[35]); 189 186 190 187 this->visData = new char [size]; … … 192 189 bspFile.read(this->visData, size); 193 190 194 PRINTF( 0)("BSP FILE: VisDataSize: %i Bytes. \n", size);195 PRINTF( 0)("BSP FILE: NumVisData: %i. \n", size /1 - 8);196 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 1);197 PRINTF( 0)("BSP FILE: VisDataOffset: %i. \n", offset);191 PRINTF(4)("BSP FILE: VisDataSize: %i Bytes. \n", size); 192 PRINTF(4)("BSP FILE: NumVisData: %i. \n", size /1 - 8); 193 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 1); 194 PRINTF(4)("BSP FILE: VisDataOffset: %i. \n", offset); 198 195 199 196 // Get the Textures 200 offset = ((int *)(header))[4];201 size = ((int *)(header))[5];197 offset = SDL_SwapLE32(((int *)(header))[4]); 198 size = SDL_SwapLE32(((int *)(header))[5]); 202 199 203 200 this->textures= new char [size]; … … 205 202 bspFile.read(this->textures, size); 206 203 207 PRINTF( 0)("BSP FILE: TextureSize: %i Bytes. \n", size);208 PRINTF( 0)("BSP FILE: NumTextures: %i. \n", size /72);209 PRINTF( 0)("BSP FILE: Remainder: %i. \n", size % 72);210 PRINTF( 0)("BSP FILE: TextureOffset: %i. \n", offset);204 PRINTF(4)("BSP FILE: TextureSize: %i Bytes. \n", size); 205 PRINTF(4)("BSP FILE: NumTextures: %i. \n", size /72); 206 PRINTF(4)("BSP FILE: Remainder: %i. \n", size % 72); 207 PRINTF(4)("BSP FILE: TextureOffset: %i. \n", offset); 211 208 this->numTextures = size/72; 212 209 213 bspFile.close(); 214 215 for(int i = 0 ; i < this->numTextures; i++) 216 PRINTF(0)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]); 217 this->load_textures(); 218 219 // Get the number of patches 220 this->numPatches = 0; 221 this->patchOffset = 0; 222 223 for( int i = 0; i < this->numFaces; i++) 224 { 225 face& cFace = ((face *)(this->faces))[i]; 226 if ( cFace.type == 2) 227 this->numPatches += (cFace.size[0] -1 ) / 2 * (cFace.size[1] -1) / 2; 228 } 229 230 // Allocate Memory 231 this->patchVertice = new char[8*8*44*(this->numPatches+10)]; 232 this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)]; 233 this->patchRowIndexes = new int*[7*4*this->numPatches]; 234 this->patchTrianglesPerRow = new char[7*4*this->numPatches]; 235 this->VertexArrayModels = new VertexArrayModel*[this->numPatches]; 210 bspFile.close(); 211 212 for(int i = 0 ; i < this->numTextures; i++) 213 PRINTF(4)("BSP FILE: Texture 0: %s. \n", &this->textures[8+ 72*i]); 214 this->load_textures(); 215 216 // Get the number of patches 217 this->numPatches = 0; 218 this->patchOffset = 0; 219 220 for( int i = 0; i < this->numFaces; i++) { 221 face& cFace = ((face *)(this->faces))[i]; 222 if ( cFace.type == 2) 223 this->numPatches += (cFace.size[0] -1 ) / 2 * (cFace.size[1] -1) / 2; 224 } 225 226 // Allocate Memory 227 this->patchVertice = new char[8*8*44*(this->numPatches+10)]; 228 this->patchIndexes = new char[7*8*2*4*(this->numPatches+10)]; 229 this->patchRowIndexes = new int*[7*4*this->numPatches]; 230 this->patchTrianglesPerRow = new char[7*4*this->numPatches]; 231 this->VertexArrayModels = new VertexArrayModel*[this->numPatches]; 236 232 237 233 PRINTF(0)("BSP FILE:NumberOfPatches: %i . \n", numPatches); 238 234 // Do tesselation for all Faces of type 2 239 for( int i = 0; i < this->numFaces; i++) 240 { 241 if ( ((face *)(this->faces))[i].type == 2) 242 this->tesselate(i); 243 } 244 245 PRINTF(0)("BSP FILE:PatchOffset: %i . \n", this->patchOffset); 246 247 return 1; 235 for( int i = 0; i < this->numFaces; i++) { 236 if ( ((face *)(this->faces))[i].type == 2) 237 this->tesselate(i); 238 } 239 240 PRINTF(0)("BSP FILE:PatchOffset: %i . \n", this->patchOffset); 241 242 return 1; 243 } else { 244 PRINTF(0)("BSP FILE: Datei nicht gefunden. \n"); 245 return -1; 248 246 } 249 else 250 { 251 PRINTF(0)("BSP FILE: Datei nicht gefunden. \n"); 252 return -1; 253 } 254 247 255 248 } 256 249 … … 258 251 { 259 252 260 261 262 263 264 265 266 267 268 253 PRINTF(0)("BSP FILE:\n"); 254 PRINTF(0)("BSP FILE: Building Tree...\n"); 255 root = this->build_tree_rec(0); 256 PRINTF(0)("BSP FILE: ...done. \n"); 257 PRINTF(0)("BSP FILE: \n"); 258 PRINTF(0)("BSP FILE: Node #0: \n"); 259 PRINTF(0)("BSP FILE: x: %f \n",root->plane.x); 260 PRINTF(0)("BSP FILE: y: %f\n",root->plane.y); 261 PRINTF(0)("BSP FILE: z: %f\n",root->plane.z); 269 262 } 270 263 271 264 BspTreeNode* BspFile::build_tree_rec(int i) 272 265 { 273 // PRINTF(0)("BSP FILE: Node #%i\n", i); 274 BspTreeNode* thisNode = new BspTreeNode(); 275 int left =(((node *) nodes) [i]).left; 276 int right =(((node *) nodes) [i]).right; 277 int planeIndex = (((node *) nodes) [i]).plane; 278 float x1 =(((plane *) this->planes) [planeIndex]).x; 279 float y1 =(((plane *) this->planes) [planeIndex]).y; 280 float z1 =(((plane *) this->planes) [planeIndex]).z; 281 thisNode->leafIndex = 0; 282 thisNode->d = (((plane *) this->planes) [planeIndex]).d; 283 284 thisNode->plane = Vector(x1,y1,z1); 285 thisNode->isLeaf = false; 286 287 if(left >= 0) 288 { 289 thisNode->left = this->build_tree_rec(left); 290 } 291 else 292 { 293 //BspTreeLeaf tmp = BspTreeLeaf(); 294 //tmp.isLeaf = true; 295 //tmp.leafIndex = -left -1; 296 //thisNode->left = (BspTreeNode*) (&tmp); 297 thisNode->left = new BspTreeNode(); 298 thisNode->left->isLeaf = true; 299 thisNode->left->leafIndex = - (left +1); 300 //PRINTF(0)("BSP FILE: LeafIndex: %i\n",-left); 301 } // assign leav 302 if(right >= 0) 303 { 304 thisNode->right = this->build_tree_rec(right); 305 } 306 else 307 { 308 //BspTreeLeaf tmp = BspTreeLeaf(); 309 //tmp.isLeaf = true; 310 //tmp.leafIndex = -right -1; 311 //thisNode->right = (BspTreeNode*) (&tmp); 312 thisNode->right = new BspTreeNode(); 313 thisNode->right->isLeaf = true; 314 thisNode->right->leafIndex = -(right +1); 315 //PRINTF(0)("BSP FILE: LeafIndex: %i\n",-right); 266 // PRINTF(0)("BSP FILE: Node #%i\n", i); 267 BspTreeNode* thisNode = new BspTreeNode(); 268 int left =(((node *) nodes) [i]).left; 269 int right =(((node *) nodes) [i]).right; 270 int planeIndex = (((node *) nodes) [i]).plane; 271 float x1 =(((plane *) this->planes) [planeIndex]).x; 272 float y1 =(((plane *) this->planes) [planeIndex]).y; 273 float z1 =(((plane *) this->planes) [planeIndex]).z; 274 thisNode->leafIndex = 0; 275 thisNode->d = (((plane *) this->planes) [planeIndex]).d; 276 277 thisNode->plane = Vector(x1,y1,z1); 278 thisNode->isLeaf = false; 279 280 if(left >= 0) { 281 thisNode->left = this->build_tree_rec(left); 282 } else { 283 //BspTreeLeaf tmp = BspTreeLeaf(); 284 //tmp.isLeaf = true; 285 //tmp.leafIndex = -left -1; 286 //thisNode->left = (BspTreeNode*) (&tmp); 287 thisNode->left = new BspTreeNode(); 288 thisNode->left->isLeaf = true; 289 thisNode->left->leafIndex = - (left +1); 290 //PRINTF(0)("BSP FILE: LeafIndex: %i\n",-left); 316 291 } // assign leav 317 return thisNode; 292 if(right >= 0) { 293 thisNode->right = this->build_tree_rec(right); 294 } else { 295 //BspTreeLeaf tmp = BspTreeLeaf(); 296 //tmp.isLeaf = true; 297 //tmp.leafIndex = -right -1; 298 //thisNode->right = (BspTreeNode*) (&tmp); 299 thisNode->right = new BspTreeNode(); 300 thisNode->right->isLeaf = true; 301 thisNode->right->leafIndex = -(right +1); 302 //PRINTF(0)("BSP FILE: LeafIndex: %i\n",-right); 303 } // assign leaf 304 return thisNode; 318 305 } 319 306 320 307 BspTreeNode* BspFile::get_root() 321 308 { 322 return root;309 return root; 323 310 } 324 311 … … 331 318 332 319 this->Materials = new AMat[this->numTextures]; 333 for(int i = 0 ; i < this->numTextures; i++) 334 { 320 for(int i = 0 ; i < this->numTextures; i++) { 335 321 PRINTF(0)("BSP FILE: Texture : %s. \n", &this->textures[8+ 72*i]); 336 337 322 323 // Check for tga 338 324 strcpy(fileName, &this->textures[8+ 72*i]); 339 325 strcpy (absFileName,"/root/data/trunk/"); … … 342 328 strncat(absFileName,fileName,strlen(fileName)); 343 329 // absFileName = ResourceManager::getFullName(fileName); 344 345 if(stat( absFileName , &results) == 0) 346 { 347 PRINTF(0)("BSP FILE: gefunden . \n"); 348 this->Materials[i] = this->loadMat(fileName); 349 continue; 330 331 if(stat( absFileName , &results) == 0) { 332 PRINTF(0)("BSP FILE: gefunden . \n"); 333 this->Materials[i] = this->loadMat(fileName); 334 continue; 350 335 } 351 336 // Check for TGA … … 355 340 strncat (fileName, ext, strlen(fileName)); 356 341 strncat(absFileName,fileName,strlen(fileName)); 357 // absFileName = ResourceManager::getFullName(fileName); 358 359 if(stat( absFileName , &results) == 0) 360 { 361 PRINTF(0)("BSP FILE: gefunden . \n"); 362 this->Materials[i] = this->loadMat(fileName); 363 continue; 342 // absFileName = ResourceManager::getFullName(fileName); 343 344 if(stat( absFileName , &results) == 0) { 345 PRINTF(0)("BSP FILE: gefunden . \n"); 346 this->Materials[i] = this->loadMat(fileName); 347 continue; 364 348 } 365 349 // Check for jpg … … 369 353 strncat (fileName, ext, strlen(fileName)); 370 354 strncat(absFileName,fileName,strlen(fileName)); 371 // absFileName = ResourceManager::getFullName(fileName); 372 if(stat( absFileName , &results) == 0) 373 { 374 PRINTF(0)("BSP FILE: gefunden . \n"); 375 this->Materials[i] =this->loadMat(fileName); 376 continue; 377 } 378 379 380 // Check for JPG 381 strcpy(fileName, &this->textures[8+ 72*i]); 382 strcpy (absFileName,"/root/data/trunk/"); 383 strcpy(ext, ".JPG"); 384 strncat (fileName, ext, strlen(fileName)); 385 strncat(absFileName,fileName,strlen(fileName)); 386 // absFileName = ResourceManager::getFullName(fileName); 387 if(stat( absFileName , &results) == 0) 388 { 389 PRINTF(0)("BSP FILE: gefunden . \n"); 390 this->Materials[i] =this->loadMat(fileName); 391 continue; 392 } 393 394 // Check for jpeg 355 // absFileName = ResourceManager::getFullName(fileName); 356 if(stat( absFileName , &results) == 0) { 357 PRINTF(0)("BSP FILE: gefunden . \n"); 358 this->Materials[i] =this->loadMat(fileName); 359 continue; 360 } 361 362 363 // Check for JPG 364 strcpy(fileName, &this->textures[8+ 72*i]); 365 strcpy (absFileName,"/root/data/trunk/"); 366 strcpy(ext, ".JPG"); 367 strncat (fileName, ext, strlen(fileName)); 368 strncat(absFileName,fileName,strlen(fileName)); 369 // absFileName = ResourceManager::getFullName(fileName); 370 if(stat( absFileName , &results) == 0) { 371 PRINTF(0)("BSP FILE: gefunden . \n"); 372 this->Materials[i] =this->loadMat(fileName); 373 continue; 374 } 375 376 // Check for jpeg 395 377 strcpy(fileName, &this->textures[8+ 72*i]); 396 378 strcpy (absFileName,"/root/data/trunk/"); … … 399 381 strncat(absFileName,fileName,strlen(fileName)); 400 382 // absFileName = ResourceManager::getFullName(fileName); 401 if(stat( absFileName , &results) == 0) 402 { 403 PRINTF(0)("BSP FILE: gefunden . \n"); 404 this->Materials[i] =this->loadMat(fileName); 405 continue; 383 if(stat( absFileName , &results) == 0) { 384 PRINTF(0)("BSP FILE: gefunden . \n"); 385 this->Materials[i] =this->loadMat(fileName); 386 continue; 406 387 } 407 388 … … 415 396 // absFileName = ResourceManager::getFullName(fileName); 416 397 PRINTF(0)("BSP FILE: %s . \n", absFileName); 417 if(stat( absFileName , &results) == 0) 418 { 419 PRINTF(0)("BSP FILE: gefunden . \n"); 420 this->Materials[i] =this->loadMat(fileName); 421 continue; 422 } 423 424 // Check for bmp 425 strcpy(fileName, &this->textures[8+ 72*i]); 426 strcpy (absFileName,"/root/data/trunk/"); 427 strcpy(ext, ".bmp"); 428 strncat (fileName, ext, strlen(fileName)); 429 strncat(absFileName,fileName,strlen(fileName)); 430 // absFileName = ResourceManager::getFullName(fileName); 431 432 if(stat( absFileName , &results) == 0) 433 { 434 PRINTF(0)("BSP FILE: gefunden . \n"); 435 this->Materials[i] =this->loadMat(fileName); 436 continue; 437 } 438 439 // Check for BMP 398 if(stat( absFileName , &results) == 0) { 399 PRINTF(0)("BSP FILE: gefunden . \n"); 400 this->Materials[i] =this->loadMat(fileName); 401 continue; 402 } 403 404 // Check for bmp 405 strcpy(fileName, &this->textures[8+ 72*i]); 406 strcpy (absFileName,"/root/data/trunk/"); 407 strcpy(ext, ".bmp"); 408 strncat (fileName, ext, strlen(fileName)); 409 strncat(absFileName,fileName,strlen(fileName)); 410 // absFileName = ResourceManager::getFullName(fileName); 411 412 if(stat( absFileName , &results) == 0) { 413 PRINTF(0)("BSP FILE: gefunden . \n"); 414 this->Materials[i] =this->loadMat(fileName); 415 continue; 416 } 417 418 // Check for BMP 440 419 strcpy(fileName, &this->textures[8+ 72*i]); 441 420 strcpy (absFileName,"/root/data/trunk/"); … … 445 424 // absFileName = ResourceManager::getFullName(fileName); 446 425 447 if(stat( absFileName , &results) == 0) 448 { 449 PRINTF(0)("BSP FILE: gefunden . \n"); 450 this->Materials[i] = this->loadMat(fileName); 451 continue; 452 } 453 // Default Material 454 this->Materials[i].mat = new Material(); 455 this->Materials[i].mat->setDiffuse(0.1,0.1,0.1); 456 this->Materials[i].mat->setAmbient(0.1,0.1,0.1 ); 457 this->Materials[i].mat->setSpecular(0.4,0.4,0.4); 458 //this->Materials[i]->setShininess(100.0); 459 this->Materials[i].mat->setTransparency(1.0); 460 this->Materials[i].mat->setDiffuseMap("pictures/ground.tga"); 461 this->Materials[i].mat->setAmbientMap("pictures/ground.tga"); 462 this->Materials[i].mat->setSpecularMap("pictures/ground.tga"); 463 this->Materials[i].alpha = false; 426 if(stat( absFileName , &results) == 0) { 427 PRINTF(0)("BSP FILE: gefunden . \n"); 428 this->Materials[i] = this->loadMat(fileName); 429 continue; 430 } 431 // Default Material 432 this->Materials[i].mat = new Material(); 433 this->Materials[i].mat->setDiffuse(0.1,0.1,0.1); 434 this->Materials[i].mat->setAmbient(0.1,0.1,0.1 ); 435 this->Materials[i].mat->setSpecular(0.4,0.4,0.4); 436 //this->Materials[i]->setShininess(100.0); 437 this->Materials[i].mat->setTransparency(1.0); 438 this->Materials[i].mat->setDiffuseMap("pictures/ground.tga"); 439 this->Materials[i].mat->setAmbientMap("pictures/ground.tga"); 440 this->Materials[i].mat->setSpecularMap("pictures/ground.tga"); 441 this->Materials[i].alpha = false; 464 442 } 465 443 } … … 472 450 473 451 this->testSurf = IMG_Load(ResourceManager::getFullName(mat).c_str()); 474 if(this->testSurf != NULL) 475 { 476 if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; 477 else tmpAMat.alpha = false; 478 } 479 else tmpAMat.alpha = false; 452 if(this->testSurf != NULL) { 453 if(this->testSurf->format->Amask != 0 ) tmpAMat.alpha = true; 454 else tmpAMat.alpha = false; 455 } else tmpAMat.alpha = false; 480 456 481 457 Material* tmp = new Material(); 482 483 484 485 486 487 488 489 490 491 458 tmp->setDiffuse(1.0,1.0,1.0); 459 tmp->setAmbient(1.0,1.0,1.0 ); 460 tmp->setSpecular(1.0,1.0,1.0); 461 // tmp->setShininess(.5); 462 // tmp->setTransparency(1.0); 463 464 tmp->setDiffuseMap(mat); 465 tmp->setAmbientMap(mat); 466 tmp->setSpecularMap(mat); 467 492 468 tmpAMat.mat = tmp; 493 469 … … 497 473 void BspFile::tesselate(int iface) 498 474 { 499 face* Face = & (((face *)(this->faces))[iface]); 500 BspVertex * BspVrtx = (BspVertex*)this->vertice; 501 int level = 7; 502 int level1 = 8; 503 504 // For each patch... 505 for(int i = 0; i <(Face->size[0] - 1) ; i+=2) 506 { 507 for(int j = 0; j <(Face->size[1] -1) ; j+=2) 508 { 509 510 511 // Make a patch... 512 // Get controls[9]; 513 BspVec controls[9]; 514 BspVec controlsTmp[9]; 515 BspVertex VControls[9]; 516 for(int k = 0; k < 3; k++) 517 { 518 for(int l = 0; l < 3; l++) 519 { 520 controls[k +3*l]. position[0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0]; 521 controls[k +3*l]. position[1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1]; 522 controls[k +3*l]. position[2] = BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; /*Face->n_vertexes*/ 523 524 controlsTmp[2-k +6-3*l]. position[0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0]; 525 controlsTmp[2-k +6-3*l]. position[1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1]; 526 controlsTmp[2-k +6-3*l]. position[2] = BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; /*Face->n_vertexes*/ 527 528 VControls[k +3*l]. position[0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0]; 529 VControls[k +3*l]. position[1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1]; 530 VControls[k +3*l]. position[2] = BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; 531 532 VControls[k +3*l]. normal[0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].normal[0]; 533 VControls[k +3*l]. normal[1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].normal[1]; 534 VControls[k +3*l]. normal[2] = BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].normal[2]; 535 536 VControls[k +3*l]. texcoord[0][0]= BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].texcoord[0][0]; 537 VControls[k +3*l]. texcoord[0][1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].texcoord[0][1]; 538 VControls[k +3*l]. texcoord[1][0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].texcoord[1][0]; 539 VControls[k +3*l]. texcoord[1][1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].texcoord[1][1]; 540 541 542 } 543 } 544 //*********************************************************************************************************************** 545 // Compute the vertice 546 //*********************************************************************************************************************** 547 float px, py; 548 BspVertex temp[3]; 549 BspVertex* Vertice = &(((BspVertex*)this->patchVertice)[level1*level1*this->patchOffset]); 550 551 for(int v=0; v<=level; ++v) 552 { 553 px=(float)v/level; 554 555 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); 556 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); 557 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); 558 559 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); 560 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); 561 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); 562 563 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); 564 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); 565 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); 566 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); 567 568 } 569 570 571 for(int u=1; u<=level; ++u) 572 { 573 py=(float)u/level; 574 575 // temp[0]=controlPoints[0]*((1.0f-py)*(1.0f-py))+ controlPoints[1]*((1.0f-py)*py*2)+ controlPoints[2]*(py*py); 576 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); 577 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); 578 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); 579 580 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); 581 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); 582 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); 583 584 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); 585 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); 586 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); 587 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); 588 589 590 591 // temp[1]=controlPoints[3]*((1.0f-py)*(1.0f-py))+ controlPoints[4]*((1.0f-py)*py*2)+ controlPoints[5]*(py*py); 592 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); 593 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); 594 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); 595 596 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); 597 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); 598 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); 599 600 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); 601 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); 602 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); 603 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); 604 605 606 // temp[2]=controlPoints[6]*((1.0f-py)*(1.0f-py))+controlPoints[7]*((1.0f-py)*py*2)+controlPoints[8]*(py*py); 607 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); 608 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); 609 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); 610 611 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); 612 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); 613 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); 614 615 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); 616 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); 617 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); 618 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); 619 620 621 622 623 for(int v=0; v<=level; ++v) 624 { 625 px=(float)v/level; 626 627 //Vertice[u*(tesselation+1)+v]= temp[0]*((1.0f-px)*(1.0f-px))+ temp[1]*((1.0f-px)*px*2)+ temp[2]*(px*px); 628 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); 629 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); 630 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); 631 632 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); 633 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); 634 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); 635 636 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); 637 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); 638 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); 639 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); 640 641 642 643 } 644 } 645 646 //Create indices 647 GLuint* indices= & ((GLuint*)(this->patchIndexes))[level*level1*2*this->patchOffset]; 648 649 for(int row=0; row<level; ++row) 650 { 651 for(int point=0; point<=level; ++point) 652 { 653 //calculate indices 654 //reverse them to reverse winding 655 indices[(row*(level1)+point)*2+1]=row*(level1)+point; 656 indices[(row*(level1)+point)*2]=(row+1)*(level1)+point; 657 } 658 } 659 660 661 //*********************************************************************************************************************** 662 // Debug Model 663 //*********************************************************************************************************************** 664 this->VertexArrayModels[this->patchOffset] = new VertexArrayModel(); 665 VertexArrayModel* tmp = this->VertexArrayModels[this->patchOffset]; 666 tmp->newStripe(); 667 int a = 0; 668 int b = -1; 669 tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]); 670 tmp->addNormal(1,0,0); 671 tmp->addTexCoor(0.0,0.0); 672 tmp->addColor(0.3,0.0,0.0); 673 tmp->addIndice(1+b); 674 tmp->addIndice(4+a); 675 tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]); 676 tmp->addNormal(1,0,0); 677 tmp->addTexCoor(0.0,0.4); 678 tmp->addColor(0.3,0.0,0.0); 679 tmp->addIndice(2+b); 680 tmp->addIndice(5+a); 681 tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); 682 tmp->addNormal(1,0,0); 683 tmp->addTexCoor(0.0,1.0); 684 tmp->addColor(0.1,0.0,0.0); 685 tmp->addIndice(3+b); 686 tmp->addIndice(6+a); 687 688 tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); 689 tmp->addNormal(1,0,0); 690 tmp->addTexCoor(0.0,1.0); 691 tmp->addColor(0.1,0.0,0.0); 692 tmp->addIndice(7+a); 693 //tmp->addIndice(6); 694 695 tmp->newStripe(); 696 697 tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]); 698 tmp->addNormal(1,0,0); 699 tmp->addTexCoor(0.0,0.0); 700 tmp->addColor(0.1,0.1,0.1); 701 tmp->addIndice(5+b); 702 tmp->addIndice(8+a); 703 tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]); 704 tmp->addNormal(1,0,0); 705 tmp->addTexCoor(0.0,0.4); 706 tmp->addColor(0.1,0.1,0.1); 707 tmp->addIndice(6+b); 708 tmp->addIndice(9+a); 709 tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); 710 tmp->addNormal(1,0,0); 711 tmp->addTexCoor(0.0,1.0); 712 tmp->addColor(0.1,0.1,0.1); 713 tmp->addIndice(7+b); 714 tmp->addIndice(10+a); 715 tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]+0.01); 716 tmp->addNormal(1,0,0); 717 tmp->addTexCoor(0.0,1.0); 718 tmp->addColor(0.1,0.1,0.1); 719 //tmp->addIndice(5); 720 tmp->addIndice(11+a); 721 722 tmp->newStripe(); 723 724 725 726 tmp->addVertex(controlsTmp[3].position[0],controlsTmp[3].position[1], controlsTmp[3].position[2]); 727 tmp->addNormal(0,1,0); 728 tmp->addTexCoor(0.5,0.0); 729 tmp->addColor(0.1,0.1,0.1); 730 tmp->addIndice(9+b); 731 tmp->addIndice(12+a); 732 tmp->addVertex(controlsTmp[4].position[0],controlsTmp[4].position[1], controlsTmp[4].position[2]); 733 tmp->addNormal(1,0,0); 734 tmp->addTexCoor(0.5,0.5); 735 tmp->addColor(0.1,0.1,0.1); 736 tmp->addIndice(10+b); 737 tmp->addIndice(13+a); 738 tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]); 739 tmp->addNormal(1,0,0); 740 tmp->addTexCoor(0.5,1.0); 741 tmp->addColor(0.1,0.1,0.1); 742 tmp->addIndice(11+b); 743 tmp->addIndice(14+a); 744 tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]+0.01); 745 tmp->addNormal(1,0,0); 746 tmp->addTexCoor(0.5,1.0); 747 tmp->addColor(0.1,0.1,0.1); 748 749 tmp->addIndice(15+a); 750 //tmp->addIndice(9); 751 tmp->newStripe(); 752 753 tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]); 754 tmp->addNormal(1,0,0); 755 tmp->addTexCoor(1.0,0.0); 756 tmp->addColor(0.1,0.1,0.1); 757 tmp->addIndice(13+b); 758 tmp->addIndice(16+a); 759 760 tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]); 761 tmp->addNormal(0,1,0); 762 tmp->addTexCoor(1.0,0.5); 763 tmp->addColor(0.1,0.1,0.1); 764 tmp->addIndice(14+b); 765 tmp->addIndice(17+a); 766 tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); 767 tmp->addNormal(1,0,0); 768 tmp->addTexCoor(1.0,1.0); 769 tmp->addColor(0.1,0.1,0.1); 770 tmp->addIndice(15+b); 771 tmp->addIndice(18+a); 772 tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); 773 tmp->addNormal(1,0,0); 774 tmp->addTexCoor(1.0,1.0); 775 tmp->addColor(0.1,0.1,0.1); 776 tmp->addIndice(19+a); 777 //tmp->addIndice(13); 778 779 tmp->newStripe(); 780 tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]); 781 tmp->addNormal(1,0,0); 782 tmp->addTexCoor(1.0,0.0); 783 tmp->addColor(0.1,0.1,0.1); 784 tmp->addIndice(17+b); 785 786 tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]); 787 tmp->addNormal(0,1,0); 788 tmp->addTexCoor(1.0,0.5); 789 tmp->addColor(0.1,0.1,0.1); 790 tmp->addIndice(18+b); 791 792 tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); 793 tmp->addNormal(1,0,0); 794 tmp->addTexCoor(1.0,1.0); 795 tmp->addColor(0.1,0.1,0.1); 796 tmp->addIndice(19+b); 797 798 tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); 799 tmp->addNormal(1,0,0); 800 tmp->addTexCoor(1.0,1.0); 801 tmp->addColor(0.1,0.1,0.1); 802 803 tmp->newStripe(); 804 805 tmp->finalize(); 806 // End of DebugModel 807 808 this->patchOffset++; 809 }// For 810 } // For 811 812 // Overwrite Face->meshvert; 813 // Overwrite Face->n_meshverts; 814 int sz = (Face->size[0] -1)/2 * (Face->size[1] -1)/2; // num patches 815 Face->meshvert = patchOffset -sz; //3*(patchOffset-sz)*level1*level1; 816 Face->n_meshverts = sz; 817 PRINTF(0)("BSP FILE: sz: %i. \n", sz); 818 PRINTF(0)("BSP FILE: Face->meshvert %i . \n", Face->meshvert); 819 820 //Face->n_meshverts = sz; 475 face* Face = & (((face *)(this->faces))[iface]); 476 BspVertex * BspVrtx = (BspVertex*)this->vertice; 477 int level = 7; 478 int level1 = 8; 479 480 // For each patch... 481 for(int i = 0; i <(Face->size[0] - 1) ; i+=2) { 482 for(int j = 0; j <(Face->size[1] -1) ; j+=2) { 483 484 485 // Make a patch... 486 // Get controls[9]; 487 BspVec controls[9]; 488 BspVec controlsTmp[9]; 489 BspVertex VControls[9]; 490 for(int k = 0; k < 3; k++) { 491 for(int l = 0; l < 3; l++) { 492 controls[k +3*l]. position[0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0]; 493 controls[k +3*l]. position[1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1]; 494 controls[k +3*l]. position[2] = BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; /*Face->n_vertexes*/ 495 496 controlsTmp[2-k +6-3*l]. position[0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0]; 497 controlsTmp[2-k +6-3*l]. position[1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1]; 498 controlsTmp[2-k +6-3*l]. position[2] = BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; /*Face->n_vertexes*/ 499 500 VControls[k +3*l]. position[0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].position[0]; 501 VControls[k +3*l]. position[1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].position[1]; 502 VControls[k +3*l]. position[2] = BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].position[2]; 503 504 VControls[k +3*l]. normal[0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].normal[0]; 505 VControls[k +3*l]. normal[1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].normal[1]; 506 VControls[k +3*l]. normal[2] = BspVrtx[Face->vertex + (j * Face->size[0])+ i + l+ Face->size[0]*k].normal[2]; 507 508 VControls[k +3*l]. texcoord[0][0]= BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].texcoord[0][0]; 509 VControls[k +3*l]. texcoord[0][1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].texcoord[0][1]; 510 VControls[k +3*l]. texcoord[1][0] = BspVrtx[Face->vertex +( j * Face->size[0])+ i + l+ Face->size[0]*k].texcoord[1][0]; 511 VControls[k +3*l]. texcoord[1][1] = BspVrtx[Face->vertex + (j * Face->size[0])+ i +l+ Face->size[0]*k].texcoord[1][1]; 512 513 514 } 515 } 516 //*********************************************************************************************************************** 517 // Compute the vertice 518 //*********************************************************************************************************************** 519 float px, py; 520 BspVertex temp[3]; 521 BspVertex* Vertice = &(((BspVertex*)this->patchVertice)[level1*level1*this->patchOffset]); 522 523 for(int v=0; v<=level; ++v) { 524 px=(float)v/level; 525 526 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); 527 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); 528 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); 529 530 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); 531 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); 532 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); 533 534 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); 535 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); 536 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); 537 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); 538 539 } 540 541 542 for(int u=1; u<=level; ++u) { 543 py=(float)u/level; 544 545 // temp[0]=controlPoints[0]*((1.0f-py)*(1.0f-py))+ controlPoints[1]*((1.0f-py)*py*2)+ controlPoints[2]*(py*py); 546 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); 547 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); 548 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); 549 550 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); 551 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); 552 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); 553 554 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); 555 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); 556 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); 557 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); 558 559 560 561 // temp[1]=controlPoints[3]*((1.0f-py)*(1.0f-py))+ controlPoints[4]*((1.0f-py)*py*2)+ controlPoints[5]*(py*py); 562 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); 563 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); 564 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); 565 566 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); 567 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); 568 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); 569 570 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); 571 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); 572 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); 573 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); 574 575 576 // temp[2]=controlPoints[6]*((1.0f-py)*(1.0f-py))+controlPoints[7]*((1.0f-py)*py*2)+controlPoints[8]*(py*py); 577 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); 578 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); 579 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); 580 581 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); 582 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); 583 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); 584 585 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); 586 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); 587 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); 588 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); 589 590 591 592 593 for(int v=0; v<=level; ++v) { 594 px=(float)v/level; 595 596 //Vertice[u*(tesselation+1)+v]= temp[0]*((1.0f-px)*(1.0f-px))+ temp[1]*((1.0f-px)*px*2)+ temp[2]*(px*px); 597 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); 598 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); 599 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); 600 601 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); 602 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); 603 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); 604 605 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); 606 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); 607 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); 608 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); 609 610 611 612 } 613 } 614 615 //Create indices 616 GLuint* indices= & ((GLuint*)(this->patchIndexes))[level*level1*2*this->patchOffset]; 617 618 for(int row=0; row<level; ++row) { 619 for(int point=0; point<=level; ++point) { 620 //calculate indices 621 //reverse them to reverse winding 622 indices[(row*(level1)+point)*2+1]=row*(level1)+point; 623 indices[(row*(level1)+point)*2]=(row+1)*(level1)+point; 624 } 625 } 626 627 628 //*********************************************************************************************************************** 629 // Debug Model 630 //*********************************************************************************************************************** 631 this->VertexArrayModels[this->patchOffset] = new VertexArrayModel(); 632 VertexArrayModel* tmp = this->VertexArrayModels[this->patchOffset]; 633 tmp->newStripe(); 634 int a = 0; 635 int b = -1; 636 tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]); 637 tmp->addNormal(1,0,0); 638 tmp->addTexCoor(0.0,0.0); 639 tmp->addColor(0.3,0.0,0.0); 640 tmp->addIndice(1+b); 641 tmp->addIndice(4+a); 642 tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]); 643 tmp->addNormal(1,0,0); 644 tmp->addTexCoor(0.0,0.4); 645 tmp->addColor(0.3,0.0,0.0); 646 tmp->addIndice(2+b); 647 tmp->addIndice(5+a); 648 tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); 649 tmp->addNormal(1,0,0); 650 tmp->addTexCoor(0.0,1.0); 651 tmp->addColor(0.1,0.0,0.0); 652 tmp->addIndice(3+b); 653 tmp->addIndice(6+a); 654 655 tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); 656 tmp->addNormal(1,0,0); 657 tmp->addTexCoor(0.0,1.0); 658 tmp->addColor(0.1,0.0,0.0); 659 tmp->addIndice(7+a); 660 //tmp->addIndice(6); 661 662 tmp->newStripe(); 663 664 tmp->addVertex(controlsTmp[0].position[0],controlsTmp[0].position[1], controlsTmp[0].position[2]); 665 tmp->addNormal(1,0,0); 666 tmp->addTexCoor(0.0,0.0); 667 tmp->addColor(0.1,0.1,0.1); 668 tmp->addIndice(5+b); 669 tmp->addIndice(8+a); 670 tmp->addVertex(controlsTmp[1].position[0],controlsTmp[1].position[1], controlsTmp[1].position[2]); 671 tmp->addNormal(1,0,0); 672 tmp->addTexCoor(0.0,0.4); 673 tmp->addColor(0.1,0.1,0.1); 674 tmp->addIndice(6+b); 675 tmp->addIndice(9+a); 676 tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]); 677 tmp->addNormal(1,0,0); 678 tmp->addTexCoor(0.0,1.0); 679 tmp->addColor(0.1,0.1,0.1); 680 tmp->addIndice(7+b); 681 tmp->addIndice(10+a); 682 tmp->addVertex(controlsTmp[2].position[0],controlsTmp[2].position[1], controlsTmp[2].position[2]+0.01); 683 tmp->addNormal(1,0,0); 684 tmp->addTexCoor(0.0,1.0); 685 tmp->addColor(0.1,0.1,0.1); 686 //tmp->addIndice(5); 687 tmp->addIndice(11+a); 688 689 tmp->newStripe(); 690 691 692 693 tmp->addVertex(controlsTmp[3].position[0],controlsTmp[3].position[1], controlsTmp[3].position[2]); 694 tmp->addNormal(0,1,0); 695 tmp->addTexCoor(0.5,0.0); 696 tmp->addColor(0.1,0.1,0.1); 697 tmp->addIndice(9+b); 698 tmp->addIndice(12+a); 699 tmp->addVertex(controlsTmp[4].position[0],controlsTmp[4].position[1], controlsTmp[4].position[2]); 700 tmp->addNormal(1,0,0); 701 tmp->addTexCoor(0.5,0.5); 702 tmp->addColor(0.1,0.1,0.1); 703 tmp->addIndice(10+b); 704 tmp->addIndice(13+a); 705 tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]); 706 tmp->addNormal(1,0,0); 707 tmp->addTexCoor(0.5,1.0); 708 tmp->addColor(0.1,0.1,0.1); 709 tmp->addIndice(11+b); 710 tmp->addIndice(14+a); 711 tmp->addVertex(controlsTmp[5].position[0],controlsTmp[5].position[1], controlsTmp[5].position[2]+0.01); 712 tmp->addNormal(1,0,0); 713 tmp->addTexCoor(0.5,1.0); 714 tmp->addColor(0.1,0.1,0.1); 715 716 tmp->addIndice(15+a); 717 //tmp->addIndice(9); 718 tmp->newStripe(); 719 720 tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]); 721 tmp->addNormal(1,0,0); 722 tmp->addTexCoor(1.0,0.0); 723 tmp->addColor(0.1,0.1,0.1); 724 tmp->addIndice(13+b); 725 tmp->addIndice(16+a); 726 727 tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]); 728 tmp->addNormal(0,1,0); 729 tmp->addTexCoor(1.0,0.5); 730 tmp->addColor(0.1,0.1,0.1); 731 tmp->addIndice(14+b); 732 tmp->addIndice(17+a); 733 tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); 734 tmp->addNormal(1,0,0); 735 tmp->addTexCoor(1.0,1.0); 736 tmp->addColor(0.1,0.1,0.1); 737 tmp->addIndice(15+b); 738 tmp->addIndice(18+a); 739 tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); 740 tmp->addNormal(1,0,0); 741 tmp->addTexCoor(1.0,1.0); 742 tmp->addColor(0.1,0.1,0.1); 743 tmp->addIndice(19+a); 744 //tmp->addIndice(13); 745 746 tmp->newStripe(); 747 tmp->addVertex(controlsTmp[6].position[0],controlsTmp[6].position[1], controlsTmp[6].position[2]); 748 tmp->addNormal(1,0,0); 749 tmp->addTexCoor(1.0,0.0); 750 tmp->addColor(0.1,0.1,0.1); 751 tmp->addIndice(17+b); 752 753 tmp->addVertex(controlsTmp[7].position[0],controlsTmp[7].position[1], controlsTmp[7].position[2]); 754 tmp->addNormal(0,1,0); 755 tmp->addTexCoor(1.0,0.5); 756 tmp->addColor(0.1,0.1,0.1); 757 tmp->addIndice(18+b); 758 759 tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); 760 tmp->addNormal(1,0,0); 761 tmp->addTexCoor(1.0,1.0); 762 tmp->addColor(0.1,0.1,0.1); 763 tmp->addIndice(19+b); 764 765 tmp->addVertex(controlsTmp[8].position[0],controlsTmp[8].position[1], controlsTmp[8].position[2]); 766 tmp->addNormal(1,0,0); 767 tmp->addTexCoor(1.0,1.0); 768 tmp->addColor(0.1,0.1,0.1); 769 770 tmp->newStripe(); 771 772 tmp->finalize(); 773 // End of DebugModel 774 775 this->patchOffset++; 776 }// For 777 } // For 778 779 // Overwrite Face->meshvert; 780 // Overwrite Face->n_meshverts; 781 int sz = (Face->size[0] -1)/2 * (Face->size[1] -1)/2; // num patches 782 Face->meshvert = patchOffset -sz; //3*(patchOffset-sz)*level1*level1; 783 Face->n_meshverts = sz; 784 PRINTF(0)("BSP FILE: sz: %i. \n", sz); 785 PRINTF(0)("BSP FILE: Face->meshvert %i . \n", Face->meshvert); 786 787 //Face->n_meshverts = sz; 821 788 } -
branches/bsp_model/src/lib/graphics/importer/bsp_file.h
r7385 r7395 21 21 typedef struct 22 22 { 23 float x; 24 float y; 25 float z; 26 float d; 23 float x; //!< 1st component of the plane's normal 24 float y; //!< 2nd component of the plane's normal 25 float z; //!< 3rd component of the plane's normal 26 float d; //!< distance of the plane to the origin 27 27 } 28 28 plane; … … 30 30 typedef struct 31 31 { 32 float mins [ 3 ]; // Bounding box min coord.33 float maxs [ 3 ]; // Bounding box max coord.34 int face; //First face for model.35 int n_faces; //Number of faces for model.36 int brush; //First brush for model.37 int n_brushes; //32 float mins [ 3 ]; //!< Bounding box min coord. 33 float maxs [ 3 ]; //!< Bounding box max coord. 34 int face; //!< First face for model. 35 int n_faces; //!< Number of faces for model. 36 int brush; //!< First brush for model. 37 int n_brushes; //!< Number of brushes 38 38 } 39 39 model; … … 41 41 typedef struct 42 42 { 43 int plane; //Plane index.44 int left; //Children indices. Negative numbers are leaf indices: -(leaf+1).45 int right; 46 int mins[ 3 ]; //Integer bounding box min coord.47 int maxs[ 3 ]; //Integer bounding box max coord.43 int plane; //!< Plane index. 44 int left; //!< 1st Child index. Negative numbers are leaf indices: -(leaf+1). 45 int right; //!< 2nd Child index. Negative numbers are leaf indices: -(leaf+1). 46 int mins[ 3 ]; //!< Integer bounding box min coord. 47 int maxs[ 3 ]; //!< Integer bounding box max coord. 48 48 } 49 49 node; … … 51 51 typedef struct 52 52 { 53 int cluster; //Visdata cluster index.54 int area; //Areaportal area.55 int mins[ 3 ]; //Integer bounding box min coord.56 int maxs[ 3 ]; //Integer bounding box max coord.57 int leafface; //First leafface for leaf.58 int n_leaffaces; //Number of leaffaces for leaf.59 int leafbrush_first; //leafbrush for leaf.60 int n_leafbrushes; //Number of leafbrushes for leaf.53 int cluster; //!< Visdata cluster index. 54 int area; //!< Areaportal area. 55 int mins[ 3 ]; //!< Integer bounding box min coord. 56 int maxs[ 3 ]; //!< Integer bounding box max coord. 57 int leafface; //!< First leafface for leaf. 58 int n_leaffaces; //!< Number of leaffaces for leaf. 59 int leafbrush_first; //!< leafbrush for leaf. 60 int n_leafbrushes; //!< Number of leafbrushes for leaf. 61 61 } 62 62 leaf; … … 64 64 typedef struct 65 65 { 66 int brushside; // First brushside for brush.67 int n_brushsides; // Number of brushsides for brush.68 int texture; //Texture index.66 int brushside; //!< First brushside for brush. 67 int n_brushsides; //!< Number of brushsides for brush. 68 int texture; //!< Texture index. 69 69 } 70 70 brush; … … 72 72 typedef struct 73 73 { 74 int plane; //Plane index.75 int texture; // Texture index.74 int plane; //!< Plane index. 75 int texture; //!< Texture index. 76 76 } 77 77 brushside; … … 79 79 struct face 80 80 { 81 int texture; //Texture index.82 int effect; //Index into lump 12 (Effects), or -1.83 int type; //Face type. 1=polygon, 2=patch, 3=mesh, 4=billboard84 int vertex; //Index of first vertex.85 int n_vertexes; //Number of vertices.86 int meshvert; //Index of first meshvert.87 int n_meshverts; //Number of meshverts.88 int lm_index; //Lightmap index.89 int lm_start [ 2 ]; //Corner of this face's lightmap image in lightmap.90 int lm_size[ 2 ]; //Size of this face's lightmap image in lightmap.91 float lm_origin [ 3 ] ; //World space origin of lightmap.92 float lm_vecs [ 2 ][ 3 ]; //World space lightmap s and t unit vectors.93 float normal[ 3 ]; //Surface normal.94 int size [ 2 ] ; //Patch dimensions.81 int texture; //!< Texture index. 82 int effect; //!< Index into lump 12 (Effects), or -1. 83 int type; //!< Face type. 1=polygon, 2=patch, 3=mesh, 4=billboard 84 int vertex; //!< Index of first vertex. 85 int n_vertexes; //!< Number of vertices. 86 int meshvert; //!< Index of first meshvert. 87 int n_meshverts; //!< Number of meshverts. 88 int lm_index; //!< Lightmap index. 89 int lm_start [ 2 ]; //!< Corner of this face's lightmap image in lightmap. 90 int lm_size[ 2 ]; //!< Size of this face's lightmap image in lightmap. 91 float lm_origin [ 3 ] ; //!< World space origin of lightmap. 92 float lm_vecs [ 2 ][ 3 ]; //!< World space lightmap s and t unit vectors. 93 float normal[ 3 ]; //!< Surface normal. 94 int size [ 2 ] ; //!< Patch dimensions. 95 95 } ; 96 96 97 97 typedef struct 98 98 { 99 float position[ 3 ]; //Vertex position.100 float texcoord[ 2 ][ 2 ]; // Vertex texture coordinates. 0=surface, 1=lightmap.101 float normal[ 3 ]; //Vertex normal.102 unsigned char color [ 4 ]; //Vertex color. RGBA.99 float position[ 3 ]; //!< Vertex position. 100 float texcoord[ 2 ][ 2 ]; //!< Vertex texture coordinates. [0][x]=surface, [1][x]=lightmap. 101 float normal[ 3 ]; //!< Vertex normal. 102 unsigned char color [ 4 ]; //!< Vertex color. RGBA. 103 103 } 104 104 BspVertex; … … 108 108 int offset; 109 109 } 110 meshvert; 110 meshvert; //!< Integer offset to mesh vertex 111 111 112 112 typedef struct … … 140 140 BspTreeNode* root; 141 141 char header [ 280 ]; //!< Buffer for header of BSP-File 142 char* nodes; //!< Buffer to store BSP-Tree-Nodes143 char* leaves; //!< Buffer to store BSP-Tree-Leaves144 char* planes;//!< Buffer to store planes separateing the space145 char* bspModels;//!< Buffer to store BSP-Model-List142 node* nodes; //!< Buffer to store BSP-Tree-Nodes 143 leaf* leaves; //!< Buffer to store BSP-Tree-Leaves 144 plane* planes; //!< Buffer to store planes separateing the space 145 model* bspModels; //!< Buffer to store BSP-Model-List 146 146 char* leafFaces; //!< Buffer to store leafFaces 147 char* faces; //!<147 face* faces; //!< 148 148 char* leafBrushes; //!< Buffer to store brush indice 149 149 char* brushes; //!< Buffer to store brushes … … 153 153 char* visData; //!< 154 154 char* textures; //!< 155 156 157 155 char* patchVertice; 158 156 char* patchIndexes; 159 157 char* patchTrianglesPerRow; 158 159 160 160 int** patchRowIndexes; 161 161 VertexArrayModel** VertexArrayModels; -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.cc
r7385 r7395 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2006 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: bottac@ee.ethz.ch … … 34 34 BspManager::BspManager() 35 35 { 36 37 38 39 40 41 36 // open a BSP file 37 this->bspFile = new BspFile(); 38 this->bspFile->read("/root/data/Kanti175.bsp"); 39 this->bspFile->build_tree(); 40 this->root = this->bspFile->get_root(); 41 this->alreadyVisible = new bool [this->bspFile->numFaces]; 42 42 } 43 43 44 44 void BspManager::draw() 45 45 { 46 47 48 49 50 51 // Draw Debug Terrain52 /*53 this->bspFile->Materials[0]->select();54 for(int i = 0; i < this->bspFile->numPatches ; i++)55 {56 this->bspFile->VertexArrayModels[i]->draw();57 58 }59 */60 61 62 63 64 65 66 67 this->trasparent.clear();46 47 48 49 50 51 // Draw Debug Terrain 52 /* 53 this->bspFile->Materials[0]->select(); 54 for(int i = 0; i < this->bspFile->numPatches ; i++) 55 { 56 this->bspFile->VertexArrayModels[i]->draw(); 57 58 } 59 */ 60 61 62 63 // erase alreadyVisible 64 for(int i = 0; i < this->bspFile->numFaces; i++) this->alreadyVisible[i] = false; 65 float tmp = 0; 66 this->opal.clear(); 67 this->trasparent.clear(); 68 68 // Find all visible faces... 69 69 70 this->cam = State::getCamera()->getAbsCoor() ; 71 this->ship = State::getCameraTargetNode()->getAbsCoor(); 72 73 74 75 76 this->cam = State::getCameraTargetNode()->getAbsCoor(); 77 this->viewDir= State::getCameraTarget()->getAbsCoor() - State::getCamera()->getAbsCoor() ; 78 float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z); 79 80 BspTreeNode* ActLeaf = this->getLeaf(this->bspFile->root, &ship); 81 int viscluster = -1; 82 viscluster =((leaf*)(this->bspFile->leaves))[ ActLeaf->leafIndex].cluster; // get the players cluster (viscluster) 83 84 85 86 // Test Collision Detection 87 this->checkCollision(this->root, &this->cam); 88 89 if (true)//(((int *)(this->bspFile->header))[35] == 0) || viscluster < 0) // if (sizeof(Visdata) == 0) 70 this->cam = State::getCamera()->getAbsCoor() ; 71 this->ship = State::getCameraTargetNode()->getAbsCoor(); 72 73 74 75 76 this->cam = State::getCameraTargetNode()->getAbsCoor(); 77 this->viewDir= State::getCameraTarget()->getAbsCoor() - State::getCamera()->getAbsCoor() ; 78 float d = (cam.x*viewDir.x + cam.y*viewDir.y + cam.z * viewDir.z); 79 80 BspTreeNode* ActLeaf = this->getLeaf(this->bspFile->root, &ship); 81 int viscluster = -1; 82 viscluster =((leaf*)(this->bspFile->leaves))[ ActLeaf->leafIndex].cluster; // get the players cluster (viscluster) 83 84 85 86 87 this->checkCollision(this->root, &this->cam); //!< Test Collision Detection 88 89 if ((((int *)(this->bspFile->header))[35] == 0) || viscluster < 0) //!< if (sizeof(Visdata) == 0) 90 { 91 /** Do Frustum culling and draw 'em all **/ 92 93 // Iterate through all Leafs 94 for(int i = 0; i < this->bspFile->numLeafs ; i++ ) 90 95 { 91 // Do Frustum culling and draw 'em all 92 93 // Iterate through all Leafs 94 for(int i = 0; i < this->bspFile->numLeafs ; i++ ) 95 { 96 // cluster = ((leaf *)(this->bspFile->leaves))[i].cluster; 97 leaf& curLeaf = ((leaf *)(this->bspFile->leaves))[i]; 98 99 100 // Iterate through all faces 101 for (int j = 0; j < curLeaf.n_leaffaces ; ++j) 102 { 103 const int f = ( j + ((leaf *) (this->bspFile->leaves))[i].leafface) % this->bspFile->numFaces; 104 if (f >=0 && !this->isAlreadyVisible(f)) 105 { 106 this->alreadyVisible[f] = true; 107 /* if(ActLeaf->leafIndex == i) 108 { 109 this->alreadyVisible[i] = false; 110 this->draw_debug_face(f); 111 this->alreadyVisible[i] = true; 112 } 113 else */addFace(f); // "visibleFaces.append(f)" 114 } 115 } 116 117 118 119 120 } //for 121 } 122 else 123 { 124 int cluster; 125 int seven = 7; 126 unsigned char one = 1; 127 unsigned int v; 128 unsigned char visSet; 129 130 // Iterate through all Leafs 131 132 for(int i = 0; i < this->bspFile->numLeafs ; ++i ) 133 { 134 leaf& camLeaf = ((leaf *)(this->bspFile->leaves))[ActLeaf->leafIndex] ; 135 leaf& curLeaf = ((leaf *)(this->bspFile->leaves))[i] ; 136 cluster = curLeaf.cluster; 137 if(cluster <0) continue; 138 v = ((viscluster * ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8)); 139 visSet =((unsigned char*) (this->bspFile->visData))[v+8]; 140 // PRINTF(0)("BSP Manager: visibility "); 141 142 143 if( ((visSet) & ((unsigned char)1 <<(unsigned char) (cluster & 7))) == 0 ) // < 20 || ((visSet) & ((unsigned char)1 <<(unsigned char) (cluster & 7))) >= 128) 144 { 145 // Iterate through all faces 146 for (int j = 0; j < curLeaf.n_leaffaces ; ++j) 147 { 148 const int f = (j + curLeaf.leafface) % this->bspFile->numFaces; 149 150 151 if (!this->isAlreadyVisible(f) && f>=0) 152 { 153 this->addFace(f); 154 this->alreadyVisible[f] = true; 155 } 156 157 } 158 159 }// if 160 161 }//for 162 163 }//else 164 165 while(!this->opal.empty()) 166 { 167 this->draw_face(this->opal.front()); 168 this->opal.pop_front(); 169 } 170 while(!this->trasparent.empty()) 171 { 172 this->draw_face(this->trasparent.back()); 173 this->trasparent.pop_back(); 174 } 96 // cluster = (this->bspFile->leaves)[i].cluster; 97 leaf& curLeaf = (this->bspFile->leaves)[i]; 98 99 100 // Iterate through all faces 101 for (int j = 0; j < curLeaf.n_leaffaces ; ++j) { 102 const int f = ( j + ((leaf *) (this->bspFile->leaves))[i].leafface) % this->bspFile->numFaces; 103 if (f >=0 && !this->isAlreadyVisible(f)) { 104 this->alreadyVisible[f] = true; 105 /* if(ActLeaf->leafIndex == i) 106 { 107 this->alreadyVisible[i] = false; 108 this->draw_debug_face(f); 109 this->alreadyVisible[i] = true; 110 } 111 else */ 112 addFace(f); // "visibleFaces.append(f)" 113 } 114 } 115 116 117 118 119 } //for 120 } else { 121 int cluster; 122 int seven = 7; 123 unsigned char one = 1; 124 unsigned int v; 125 unsigned char visSet; 126 127 // Iterate through all Leafs 128 129 for(int i = 0; i < this->bspFile->numLeafs ; ++i ) { 130 leaf& camLeaf = (this->bspFile->leaves)[ActLeaf->leafIndex] ; 131 leaf& curLeaf = (this->bspFile->leaves)[i] ; 132 cluster = curLeaf.cluster; 133 134 if(cluster <0) continue; 135 v = ((viscluster * ( ((int *)this->bspFile->visData)[1]) ) + (cluster / 8)); 136 visSet =((unsigned char*) (this->bspFile->visData))[v+8]; 137 138 139 if( ((visSet) & ((unsigned char)1 <<(unsigned char) (cluster & 7))) == 0 ) 140 { 141 // Iterate through all faces 142 for (int j = 0; j < curLeaf.n_leaffaces ; ++j) 143 { 144 const int f = (j + curLeaf.leafface) % this->bspFile->numFaces; 145 146 147 if (!this->isAlreadyVisible(f) && f>=0) { 148 this->addFace(f); 149 this->alreadyVisible[f] = true; 150 } 151 152 } 153 154 }// if 155 156 }//for 157 158 }//else 159 160 while(!this->opal.empty()) { 161 this->draw_face(this->opal.front()); 162 this->opal.pop_front(); 163 } 164 while(!this->trasparent.empty()) { 165 this->draw_face(this->trasparent.back()); 166 this->trasparent.pop_back(); 167 } 175 168 176 169 … … 178 171 179 172 void BspManager::draw_leaf() 180 { 181 182 } 173 {} 183 174 184 175 void BspManager::draw_face(int curface) 185 176 { 186 face& curFace = ((face *)(this->bspFile->faces))[curface];187 const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;188 int stride = 44; // sizeof(Vertex)189 int offset = curFace.vertex;190 177 face& curFace = (this->bspFile->faces)[curface]; 178 const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice; 179 int stride = sizeof(BspVertex); // sizeof(Vertex) 180 int offset = curFace.vertex; 181 191 182 // PRINTF(0)("BSP Manager: "); 192 183 // PRINTF(0)("BSP Manager: type: %i \n", curFace.texture); 193 194 // if( curFace.texture < 0 ) return; 195 if(curFace.type == 2) 196 { 197 this->draw_patch( &curFace); 198 return; 199 } 200 if(curFace.type == 3) return; 201 // if(this->bspFile->Materials[curFace.texture] != NULL) 202 if(this->lastTex != curFace.texture) 203 { 204 this->bspFile->Materials[curFace.texture].mat->select(); 205 this->lastTex = curFace.texture; 206 } 184 185 // if( curFace.texture < 0 ) return; 186 if(curFace.type == 2) { 187 this->draw_patch( &curFace); 188 return; 189 } 190 if(curFace.type == 3) return; 191 // if(this->bspFile->Materials[curFace.texture] != NULL) 192 if(this->lastTex != curFace.texture) { 193 this->bspFile->Materials[curFace.texture].mat->select(); 194 this->lastTex = curFace.texture; 195 } 207 196 glEnableClientState(GL_VERTEX_ARRAY ); 208 197 glEnableClientState(GL_TEXTURE_COORD_ARRAY ); 209 198 glEnableClientState(GL_NORMAL_ARRAY ); 210 // glEnableClientState(GL_COLOR_ARRAY); 211 // glEnableClientState(GL_VERTEX_ARRAY );212 199 // glEnableClientState(GL_COLOR_ARRAY); 200 201 213 202 glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0])); 214 203 // glClientActiveTextureARB(GL_TEXTURE0_ARB); 215 204 glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0])); 216 217 218 //glEnableClientState(GL_NORMAL_ARRAY ); 205 // glClientActiveTextureARB(GL_TEXTURE1_ARB); 206 // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1])); 207 219 208 220 209 glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0])); 221 210 // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0])); 222 211 glDrawElements(GL_TRIANGLES, curFace.n_meshverts, 223 212 GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert])); 224 213 225 214 … … 227 216 glDisableClientState(GL_TEXTURE_COORD_ARRAY ); 228 217 glDisableClientState(GL_NORMAL_ARRAY ); 229 // glDisableClientState(GL_COLOR_ARRAY);230 218 // glDisableClientState(GL_COLOR_ARRAY); 219 231 220 } 232 221 … … 234 223 void BspManager::draw_debug_face(int curface) 235 224 { 236 face& curFace = ((face *)(this->bspFile->faces))[curface];237 const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice;238 int stride = 44; // sizeof(Vertex)239 int offset = curFace.vertex;240 225 face& curFace = (this->bspFile->faces)[curface]; 226 const BspVertex* curVertex = (BspVertex *) this->bspFile->vertice; 227 int stride = 44; // sizeof(Vertex) 228 int offset = curFace.vertex; 229 241 230 // PRINTF(0)("BSP Manager: "); 242 231 // PRINTF(0)("BSP Manager: type: %i \n", curFace.texture); 243 244 // if( curFace.texture < 0 ) return; 245 if(curFace.type == 2) 246 { 247 this->draw_patch( &curFace); 248 return; 249 } 250 if(curFace.type == 3) return; 251 // if(this->bspFile->Materials[curFace.texture] != NULL) 252 253 this->bspFile->Materials[2].mat->select(); 254 this->lastTex = 2; 232 233 // if( curFace.texture < 0 ) return; 234 if(curFace.type == 2) { 235 this->draw_patch( &curFace); 236 return; 237 } 238 if(curFace.type == 3) return; 239 // if(this->bspFile->Materials[curFace.texture] != NULL) 240 241 this->bspFile->Materials[2].mat->select(); 242 this->lastTex = 2; 255 243 256 244 glEnableClientState(GL_VERTEX_ARRAY ); 257 245 glEnableClientState(GL_TEXTURE_COORD_ARRAY ); 258 246 glEnableClientState(GL_NORMAL_ARRAY ); 259 //glEnableClientState(GL_COLOR_ARRAY); 247 //glEnableClientState(GL_COLOR_ARRAY); 260 248 // glEnableClientState(GL_VERTEX_ARRAY ); 261 249 262 250 glVertexPointer(3, GL_FLOAT, stride, &(curVertex[offset].position[0])); 263 251 // glClientActiveTextureARB(GL_TEXTURE0_ARB); 264 252 glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[0])); 265 266 267 253 // glClientActiveTextureARB(GL_TEXTURE1_ARB); 254 // glTexCoordPointer(2, GL_FLOAT, stride, &(curVertex[offset].texcoord[1])); 255 //glEnableClientState(GL_NORMAL_ARRAY ); 268 256 269 257 glNormalPointer( GL_FLOAT, stride, &(curVertex[offset].normal[0])); 270 258 // glColorPointer(4, GL_BYTE, stride, &(curVertex[offset].color[0])); 271 259 glDrawElements(GL_TRIANGLES, curFace.n_meshverts, 272 273 260 GL_UNSIGNED_INT, &(((meshvert *)this->bspFile->meshverts) [curFace.meshvert])); 261 274 262 } 275 263 276 264 void BspManager::draw_patch(face* Face) 277 265 { 278 if(this->lastTex != Face->texture) 279 { 280 this->bspFile->Materials[Face->texture].mat->select(); 281 this->lastTex = Face->texture; 282 } 283 284 for(int i = 0; i < Face->n_meshverts ; i++) 285 { 286 //glFrontFace(GL_CW); 287 //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]); 288 glEnableClientState(GL_VERTEX_ARRAY ); 289 glEnableClientState(GL_TEXTURE_COORD_ARRAY ); 290 glEnableClientState(GL_NORMAL_ARRAY ); 291 292 glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0])); 293 glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0])); 294 glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) ); 295 296 // We'll need multitexture suport for lightning 297 //glClientActiveTextureARB(GL_TEXTURE0_ARB); 298 //glTexCoordPointer(2, GL_FLOAT,0, &vertex[0].textureCoord); 299 //glClientActiveTextureARB(GL_TEXTURE1_ARB); 300 //glTexCoordPointer(2, GL_FLOAT, sizeof(BSPVertex), &vertex[0].lightmapCoord); 301 302 303 for(int row=0; row<7; ++row) 304 { 305 glDrawElements(GL_TRIANGLE_STRIP, 2*(8), GL_UNSIGNED_INT, 306 & ( (((GLuint*) (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8] )) ); 307 } 308 309 //glFrontFace(GL_CCW); 310 } 311 266 if(this->lastTex != Face->texture) { 267 this->bspFile->Materials[Face->texture].mat->select(); 268 this->lastTex = Face->texture; 269 } 270 271 for(int i = 0; i < Face->n_meshverts ; i++) { 272 //glFrontFace(GL_CW); 273 //PRINTF(0)("BSP Manager: Face->size[0]: %i . \n", Face->size[0]); 274 glEnableClientState(GL_VERTEX_ARRAY ); 275 glEnableClientState(GL_TEXTURE_COORD_ARRAY ); 276 glEnableClientState(GL_NORMAL_ARRAY ); 277 278 glVertexPointer(3, GL_FLOAT,44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).position[0])); 279 glTexCoordPointer(2, GL_FLOAT, 44, &((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).texcoord[0][0])); 280 glNormalPointer( GL_FLOAT, 44,&((((BspVertex*)(this->bspFile->patchVertice))[8*8*(Face->meshvert+i)]).normal[0]) ); 281 282 // We'll need multitexture suport for lightning 283 //glClientActiveTextureARB(GL_TEXTURE0_ARB); 284 //glTexCoordPointer(2, GL_FLOAT,0, &vertex[0].textureCoord); 285 //glClientActiveTextureARB(GL_TEXTURE1_ARB); 286 //glTexCoordPointer(2, GL_FLOAT, sizeof(BSPVertex), &vertex[0].lightmapCoord); 287 288 289 for(int row=0; row<7; ++row) { 290 glDrawElements(GL_TRIANGLE_STRIP, 2*(8), GL_UNSIGNED_INT, 291 & ( (((GLuint*) (this->bspFile->patchIndexes))[7*8*2*(Face->meshvert+i)+ row*2*8] )) ); 292 } 293 294 //glFrontFace(GL_CCW); 295 } 296 312 297 } 313 298 314 299 bool BspManager::isAlreadyVisible(int Face) 315 300 { 316 301 return this->alreadyVisible[Face]; 317 302 } 318 303 … … 320 305 BspTreeNode* BspManager::getLeaf(BspTreeNode* node, Vector* cam) 321 306 { 322 float dist = 0; 323 while(!(node->isLeaf)) 324 { 325 dist = (node->plane.x * this->cam.x + node->plane.y*this->cam.y + node->plane.z*this->cam.z) - node->d; 326 if(dist >= 0.0f) 327 { 328 node = node->left; 329 } 330 else 331 { 332 node = node->right; 333 334 } 335 } 336 return node; 307 float dist = 0; 308 while(!(node->isLeaf)) { 309 dist = (node->plane.x * this->cam.x + node->plane.y*this->cam.y + node->plane.z*this->cam.z) - node->d; 310 if(dist >= 0.0f) { 311 node = node->left; 312 } else { 313 node = node->right; 314 315 } 316 } 317 return node; 337 318 } 338 319 339 320 void BspManager::checkCollision(BspTreeNode* node, Vector* cam) 340 321 { 341 float dist = 0; 342 if(!(node->isLeaf)) 343 { 344 dist = (node->plane.x * this->cam.x + node->plane.y*this->cam.y + node->plane.z*this->cam.z) - node->d; 345 if(dist > 4.0f) 346 { 347 checkCollision(node->left,cam); 348 return; 349 } 350 if(dist < -4.0f) 351 { 352 checkCollision(node->right,cam); 353 return; 354 } 355 if(dist<=4.0f && dist >= -4.0f) 356 { 357 checkCollision(node->left,cam); 358 checkCollision(node->right,cam); 359 return; 360 } 361 return; 362 } 363 else 364 { 365 366 leaf& camLeaf = ((leaf *)(this->bspFile->leaves))[(node->leafIndex ) ]; 367 368 if (camLeaf.cluster < 0) {this->drawDebugCube(&this->cam);} 369 370 371 /* 372 for(int i = 0; i < camLeaf.n_leafbrushes && i < 10; i++ ) 373 { 374 brush& curBrush = ((brush*)(this->bspFile->brushes))[(camLeaf.leafbrush_first +i)%this->bspFile->numLeafBrushes]; 375 if(curBrush.n_brushsides < 0) return; 376 for(int j = 0; j < curBrush.n_brushsides; j++) 377 { 378 float dist = -0.1; 379 brushside& curBrushSide = ((brushside*)(this->bspFile->brushSides))[(curBrush.brushside +j)%this->bspFile->numBrushSides]; 380 plane& testPlane = ((plane*)(this->bspFile->planes))[curBrushSide.plane % this->bspFile->numPlanes]; 381 dist = testPlane.x * this->cam.x + testPlane.y * this->cam.y + testPlane.z * this->cam.z -testPlane.d ; 382 383 if(dist < -0.01f) dist = -1.0f *dist; 384 if(dist < 1.0f){ 385 this->drawDebugCube(&this->cam); 386 return; 387 } 388 } 389 390 } */ 391 392 } 393 return; 322 float dist = 0; 323 if(!(node->isLeaf)) { 324 dist = (node->plane.x * this->cam.x + node->plane.y*this->cam.y + node->plane.z*this->cam.z) - node->d; 325 if(dist > 4.0f) { 326 checkCollision(node->left,cam); 327 return; 328 } 329 if(dist < -4.0f) { 330 checkCollision(node->right,cam); 331 return; 332 } 333 if(dist<=4.0f && dist >= -4.0f) { 334 checkCollision(node->left,cam); 335 checkCollision(node->right,cam); 336 return; 337 } 338 return; 339 } else { 340 341 leaf& camLeaf = ((leaf *)(this->bspFile->leaves))[(node->leafIndex ) ]; 342 343 if (camLeaf.cluster < 0) {this->drawDebugCube(&this->cam);} 344 345 346 /* 347 for(int i = 0; i < camLeaf.n_leafbrushes && i < 10; i++ ) 348 { 349 brush& curBrush = ((brush*)(this->bspFile->brushes))[(camLeaf.leafbrush_first +i)%this->bspFile->numLeafBrushes]; 350 if(curBrush.n_brushsides < 0) return; 351 for(int j = 0; j < curBrush.n_brushsides; j++) 352 { 353 float dist = -0.1; 354 brushside& curBrushSide = ((brushside*)(this->bspFile->brushSides))[(curBrush.brushside +j)%this->bspFile->numBrushSides]; 355 plane& testPlane = ((plane*)(this->bspFile->planes))[curBrushSide.plane % this->bspFile->numPlanes]; 356 dist = testPlane.x * this->cam.x + testPlane.y * this->cam.y + testPlane.z * this->cam.z -testPlane.d ; 357 358 if(dist < -0.01f) dist = -1.0f *dist; 359 if(dist < 1.0f){ 360 this->drawDebugCube(&this->cam); 361 return; 362 } 363 } 364 365 } */ 366 367 } 368 return; 394 369 } 395 370 396 371 void BspManager::drawDebugCube(Vector* cam) 397 372 { 398 glBegin(GL_QUADS); 399 400 401 402 403 404 405 glTexCoord2f(0.800f, 0.800f); glVertex3f(cam->x-1.0f, cam->y-1.0f,cam->z -1.0f);406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 glNormal3f( 0.0f, 0.0f,-1.0f); glColor4f(0.2,0.9,0.2,.5);424 425 426 427 428 429 430 431 432 433 434 435 glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x+ 1.0f,cam->y -1.0f, cam->z -1.0f);436 437 438 439 440 441 442 443 glNormal3f( 0.0f, 0.0f, 1.0f);444 445 446 447 448 449 450 glTexCoord2f( 0.995f, 0.995f); glVertex3f( cam->x+1.0f, cam->y+1.0f, cam->z +1.0f);451 452 453 454 455 456 457 glNormal3f(-1.0f, 0.0f, 0.0f);458 459 460 glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z -1.0f);461 462 463 464 465 466 467 468 373 glBegin(GL_QUADS); 374 375 // Bottom Face. Red, 75% opaque, magnified texture 376 377 glNormal3f( 0.0f, -1.0f, 0.0f); // Needed for lighting 378 glColor4f(0.9,0.2,0.2,.75); // Basic polygon color 379 380 glTexCoord2f(0.800f, 0.800f); glVertex3f(cam->x-1.0f, cam->y-1.0f,cam->z -1.0f); 381 glTexCoord2f(0.200f, 0.800f); glVertex3f(cam->x+1.0f, cam->y-1.0f,cam->z -1.0f); 382 glTexCoord2f(0.200f, 0.200f); glVertex3f(cam->x+ 1.0f,cam->y -1.0f,cam->z + 1.0f); 383 glTexCoord2f(0.800f, 0.200f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z + 1.0f); 384 385 386 // Top face; offset. White, 50% opaque. 387 388 glNormal3f( 0.0f, 1.0f, 0.0f); glColor4f(0.5,0.5,0.5,.5); 389 390 glTexCoord2f(0.005f, 1.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.0f); 391 glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z +1.0f); 392 glTexCoord2f(1.995f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y+1.0f, cam->z +1.0f); 393 glTexCoord2f(1.995f, 1.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z -1.0f); 394 395 396 // Far face. Green, 50% opaque, non-uniform texture cooridinates. 397 398 glNormal3f( 0.0f, 0.0f,-1.0f); glColor4f(0.2,0.9,0.2,.5); 399 400 glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z -1.3f); 401 glTexCoord2f(2.995f, 2.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.3f); 402 glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x+ 1.0f,cam->y+ 1.0f, cam->z -1.3f); 403 glTexCoord2f(0.005f, 0.005f); glVertex3f( cam->x+1.0f,cam->y -1.0f, cam->z -1.3f); 404 405 406 // Right face. Blue; 25% opaque 407 408 glNormal3f( 1.0f, 0.0f, 0.0f); glColor4f(0.2,0.2,0.9,.25); 409 410 glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x+ 1.0f,cam->y -1.0f, cam->z -1.0f); 411 glTexCoord2f(0.995f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z -1.0f); 412 glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x+ 1.0f, cam->y+ 1.0f, cam->z + 1.0f); 413 glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y-1.0f, cam->z +1.0f); 414 415 416 // Front face; offset. Multi-colored, 50% opaque. 417 418 glNormal3f( 0.0f, 0.0f, 1.0f); 419 420 glColor4f( 0.9f, 0.2f, 0.2f, 0.5f); 421 glTexCoord2f( 0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z +1.0f); 422 glColor4f( 0.2f, 0.9f, 0.2f, 0.5f); 423 glTexCoord2f( 0.995f, 0.005f); glVertex3f(cam->x+ 1.0f, cam->y-1.0f, cam->z +1.0f); 424 glColor4f( 0.2f, 0.2f, 0.9f, 0.5f); 425 glTexCoord2f( 0.995f, 0.995f); glVertex3f( cam->x+1.0f, cam->y+1.0f, cam->z +1.0f); 426 glColor4f( 0.1f, 0.1f, 0.1f, 0.5f); 427 glTexCoord2f( 0.005f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z +1.0f); 428 429 430 // Left Face; offset. Yellow, varying levels of opaque. 431 432 glNormal3f(-1.0f, 0.0f, 0.0f); 433 434 glColor4f(0.9,0.9,0.2,0.0); 435 glTexCoord2f(0.005f, 0.005f); glVertex3f(cam->x-1.0f, cam->y-1.0f, cam->z -1.0f); 436 glColor4f(0.9,0.9,0.2,0.66); 437 glTexCoord2f(0.995f, 0.005f); glVertex3f(cam->x-1.0f,cam->y -1.0f, cam->z +1.0f); 438 glColor4f(0.9,0.9,0.2,1.0); 439 glTexCoord2f(0.995f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z +1.0f); 440 glColor4f(0.9,0.9,0.2,0.33); 441 glTexCoord2f(0.005f, 0.995f); glVertex3f(cam->x-1.0f, cam->y+ 1.0f, cam->z -1.0f); 442 443 glEnd(); 469 444 } 470 445 471 446 void BspManager::addFace(int f) 472 447 { 473 face& curFace = ((face *)(this->bspFile->faces))[f];474 if(this->bspFile->Materials[curFace.texture].alpha) this->trasparent.push_back(f);475 else this->opal.push_back(f);476 } 448 face& curFace = ((face *)(this->bspFile->faces))[f]; 449 if(this->bspFile->Materials[curFace.texture].alpha) this->trasparent.push_back(f); 450 else this->opal.push_back(f); 451 } -
branches/bsp_model/src/lib/graphics/importer/bsp_manager.h
r7385 r7395 1 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 4 4 Copyright (C) 2006 orx 5 5 6 6 This program is free software; you can redistribute it and/or modify 7 7 it under the terms of the GNU General Public License as published by 8 8 the Free Software Foundation; either version 2, or (at your option) 9 9 any later version. 10 10 11 11 ### File Specific: 12 12 main-programmer: bottac@ee.ethz.ch … … 28 28 { 29 29 public: 30 // Constructors31 BspManager();30 // Constructors 31 BspManager(); 32 32 33 // Functions34 void draw();35 void draw_leaf();36 void draw_debug_face(int Face);37 void draw_face(int Face);38 void draw_patch(face* Face);39 33 // Functions 34 void draw(); 35 void draw_leaf(); 36 void draw_debug_face(int Face); 37 void draw_face(int Face); 38 void draw_patch(face* Face); 39 40 40 41 41 private: 42 // Functions43 BspFile* bspFile;44 BspTreeNode* root;45 const BspTreeNode* getLeaf(const BspTreeNode* node, const Vector& cam) const; // Traverses the tree46 void checkCollision(BspTreeNode* node, Vector* cam);47 void drawDebugCube(Vector* cam);48 Vector cam;49 Vector ship;50 Vector viewDir;51 bool * alreadyVisible;52 bool isAlreadyVisible(int Face);53 void addFace(int Face);54 int lastTex;42 // Functions 43 BspFile* bspFile; 44 BspTreeNode* root; 45 BspTreeNode* getLeaf(BspTreeNode* node, Vector* cam) ; //!< Traverses the tree 46 void checkCollision(BspTreeNode* node, Vector* cam); 47 void drawDebugCube(Vector* cam); 48 Vector cam; 49 Vector ship; 50 Vector viewDir; 51 bool * alreadyVisible; 52 bool isAlreadyVisible(int Face); 53 void addFace(int Face); 54 int lastTex; 55 55 56 56 57 // Vectors to store the visible faces58 ::std::deque<int> trasparent; //the ones with transparancy go here59 ::std::deque<int> opal; //the others here.57 // Deques to store the visible faces 58 ::std::deque<int> trasparent; //!< the ones with transparancy go here 59 ::std::deque<int> opal; //!< the others here. 60 60 61 61 };
Note: See TracChangeset
for help on using the changeset viewer.