00001 /* 00002 * QuarterGlobeTile.cpp 00003 * 00004 * Part of Fly! Legacy project 00005 * 00006 * Copyright 2003-2004 Chris Wallace 00007 * 00008 * Fly! Legacy is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * Fly! Legacy is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with Fly! Legacy; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 */ 00023 00034 #include "../Include/Globals.h" 00035 #include "../Include/Terrain.h" 00036 #include "../Include/Utility.h" 00037 #include "../Include/Ui.h" 00038 00039 00040 // 00041 // CSceneryModels 00042 // 00043 CSceneryModels::CSceneryModels (const char* sxxFilename) 00044 { 00045 // Instantiate top-level branch 00046 top = new ssgBranch; 00047 00048 // Instantiate list, assume 32 objects to start? 00049 wobjList = new ulList(32); 00050 00051 SStream *stream = new SStream; 00052 strcpy (stream->filename, sxxFilename); 00053 strcpy (stream->mode, "r"); 00054 if (OpenStream (&globals->pfs, stream)) { 00055 ReadFrom (this, stream); 00056 CloseStream (stream); 00057 } 00058 delete stream; 00059 } 00060 00061 CSceneryModels::~CSceneryModels (void) 00062 { 00063 /* 00064 int i, n; 00065 00066 top->removeAllKids(); 00067 delete top; 00068 00069 // Delete world objects 00070 n = wobjList->getNumEntities(); 00071 for (i=0; i<n; i++) { 00072 CWorldObject *wobj = (CWorldObject *)wobjList->getEntity(i); 00073 delete wobj; 00074 } 00075 delete wobjList; 00076 */ 00077 } 00078 00079 int CSceneryModels::Read (SStream *stream, Tag tag) 00080 { 00081 int rc = TAG_READ; 00082 00083 switch (tag) { 00084 case 'wobj': 00085 { 00086 // Determine the type of world object 00087 Tag type; 00088 ReadTag (&type, stream); 00089 switch (type) { 00090 case TYPE_FLY_MODELOBJECT: 00091 { 00092 // Instantiate new CModelObject 00093 CModelObject *mobj = new CModelObject (); 00094 ReadFrom (mobj, stream); 00095 wobjList->addEntity (mobj); 00096 ssgEntity *ssge = mobj->GetSSGEntity(); 00097 if (ssge != NULL) { 00098 top->addKid (ssge); 00099 } 00100 } 00101 break; 00102 00103 default: 00105 SkipObject (stream); 00106 } 00107 rc = TAG_READ; 00108 } 00109 break; 00110 } 00111 00112 return rc; 00113 } 00114 00115 ssgEntity *CSceneryModels::GetSSGEntity (void) 00116 { 00117 return top; 00118 } 00119 00120 00121 // 00122 // CQuarterGlobeTile 00123 // 00124 00125 // 00126 // The universal QGT size is 42.1875 nm square (equivalent to half of 1.40625 deg), 00127 // so if QGT center coordinate is 0,0 then the bounds are +/- 21.09375 nm. This 00128 // macro defines the QGT bound in feet. 00129 // 00130 #define QGT_FLAT_CARTESIAN_BOUND_FT (1.28165E+5) 00131 00132 // Constructor with void argument instantiates the SSG tree structure but does not 00133 // load any elevation or texturing information. This is essentially an empty "shell" 00134 // for the QGT that is populated when x,z QGT indices are assigned 00135 // 00136 CQuarterGlobeTile::CQuarterGlobeTile (void) 00137 { 00138 level = TERRAIN_SUBDIVISION_QUARTER_GLOBE_TILE; 00139 00140 // If terrain debug level indicates QGT level of debug, then create a 00141 // simple leaf child. Since the QGT may not be visible, it is still 00142 // untextured 00143 if (globals->terrainmgr->debugLevel == QUARTER_GLOBE_TILES) { 00144 00145 // Initialize state information 00146 ssgSimpleState *state = new ssgSimpleState (); 00147 state->setShadeModel (GL_SMOOTH); 00148 state->disable (GL_LIGHTING); 00149 state->enable (GL_CULL_FACE); 00150 state->enable (GL_BLEND); 00151 state->disable (GL_ALPHA_TEST); 00152 state->setColourMaterial (GL_AMBIENT_AND_DIFFUSE); 00153 state->setMaterial (GL_EMISSION, 0, 0, 0, 1); 00154 state->setMaterial (GL_SPECULAR, 0, 0, 0, 1); 00155 00156 // Assign default texture index; this will be updated when texture is created 00157 state->enable (GL_TEXTURE_2D); 00158 state->setTexture ((GLuint)0); 00159 state->disable (GL_COLOR_MATERIAL); 00160 00161 // Set vertices 00162 float d = QGT_FLAT_CARTESIAN_BOUND_FT; 00163 sgVec3 v1, v2, v3, v4; 00164 sgSetVec3 (v1, -d, d, 0); // NW 00165 sgSetVec3 (v2, -d, -d, 0); // SW 00166 sgSetVec3 (v3, d, d, 0); // NE 00167 sgSetVec3 (v4, d, -d, 0); // SE 00168 00169 // Define arrays for face data 00170 ssgVertexArray *va = new ssgVertexArray(4); 00171 va->add (v1); 00172 va->add (v2); 00173 va->add (v3); 00174 va->add (v4); 00175 00176 // Allocate texture coordinates 00177 sgVec2 t1, t2, t3, t4; 00178 sgSetVec2 (t1, 0.0, 1.0); // Upper-left NW 00179 sgSetVec2 (t2, 0.0, 0.0); // Lower-left SW 00180 sgSetVec2 (t3, 1.0, 1.0); // Upper-right NE 00181 sgSetVec2 (t4, 1.0, 0.0); // Lower-right SE 00182 00183 ssgTexCoordArray *ta = new ssgTexCoordArray(4); 00184 ta->add (t1); 00185 ta->add (t2); 00186 ta->add (t3); 00187 ta->add (t4); 00188 00189 ssgVtxTable *vtab = new ssgVtxTable (GL_TRIANGLE_STRIP, va, NULL, ta, NULL); 00190 vtab->setState (state); 00191 vtab->setName ("DebugTile"); 00192 addKid (vtab); 00193 } else { 00194 /* 00195 int i, j; 00196 00197 // Not in QGT debugging mode; allocate child super tiles 00198 stArraySize = 8; 00199 stArray = new CSuperTile**[stArraySize]; 00200 for (i=0; i<stArraySize; i++) { 00201 stArray[i] = new CSuperTile*[stArraySize]; 00202 for (j=0; j<stArraySize; j++) { 00203 CSuperTile *st = new CSuperTile; 00204 stArray[i][j] = st; 00205 top->addKid (st->GetSSGEntity()); 00206 } 00207 } 00208 */ 00209 } 00210 00211 state = QGT_UNASSIGNED; 00212 sceneryModels = NULL; 00213 00214 // Since this QQT may need to be added and removed from the scene graph, 00215 // increment the refcount so it is never automatically deleted when 00216 // removed. 00217 ref(); 00218 } 00219 00220 00221 CQuarterGlobeTile::~CQuarterGlobeTile (void) 00222 { 00223 // Clean up scenery models 00224 if (sceneryModels != NULL) delete sceneryModels; 00225 } 00226 00227 void CQuarterGlobeTile::AssignIndices (unsigned int x, unsigned int z) 00228 { 00229 if (state == QGT_UNASSIGNED) { 00230 this->x = x; 00231 this->z = z; 00232 00233 this->globe_x = x/2; 00234 this->globe_z = z/2; 00235 00236 char name[80]; 00237 sprintf (name, "QGT %d,%d (%d,%d Q%c%c)", x, z, globe_x, globe_z, 00238 '0'+(x%2), '0'+(z%2)); 00239 setName (name); 00240 } else { 00241 // Re-assigning indices is not permitted. Must Unassign() then Assign() 00242 gtfo ("CQuarterGlobeTile : Multiple assignment of indices : %d,%d to %d,%d", 00243 this->x, this->z, x, z); 00244 } 00245 00246 state = QGT_ASSIGNED; 00247 } 00248 00249 void CQuarterGlobeTile::UnassignIndices (void) 00250 { 00251 if (globals->terrainmgr->debugLevel == QUARTER_GLOBE_TILES) { 00252 // Get pointer to leaf node and its state 00253 ssgVtxTable *vtab = (ssgVtxTable*)this->getKid(0); 00254 ssgSimpleState *state = (ssgSimpleState*)vtab->getState(); 00255 00256 if (texid != 0) { 00257 state->setTexture ((GLuint)0); 00258 glDeleteTextures (1, &texid); 00259 texid = 0; 00260 } 00261 } else { 00262 // Unassign child super tiles 00263 } 00264 00265 state = QGT_UNASSIGNED; 00266 } 00267 00268 bool CQuarterGlobeTile::IsAssigned (void) 00269 { 00270 return (state == QGT_ASSIGNED); 00271 } 00272 00273 void CQuarterGlobeTile::GetIndices (unsigned int &x, unsigned int &z) 00274 { 00275 x = this->x; 00276 z = this->z; 00277 } 00278 00279 void CQuarterGlobeTile::Create (void) 00280 { 00281 globals->terrainmgr->Log ("Creating Quarter Globe Tile %d,%d(Q%1d%1d)", 00282 globe_x, globe_z, (x%2), (z%2)); 00283 00284 // Check for QGT debug mode 00285 if (globals->terrainmgr->debugLevel == QUARTER_GLOBE_TILES) { 00286 00287 // Get pointer to leaf node and its state 00288 ssgVtxTable *vtab = (ssgVtxTable*)this->getKid(0); 00289 ssgSimpleState *state = (ssgSimpleState*)vtab->getState(); 00290 00291 // Create debug texture 00292 int size = 128; 00293 SSurface *surface = CreateSurface (size, size); 00294 unsigned int bg = MakeRGB (128, 128, 128); // Medium grey 00295 unsigned int fg = MakeRGB (255, 255, 255); // White 00296 surface->xScreen = surface->yScreen = 0; 00297 EraseSurfaceRGB (surface, bg); 00298 DrawLine (surface, 0, 0, size-1, 0, fg); 00299 DrawLine (surface, size-1, 0, size-1, size-1, fg); 00300 DrawLine (surface, size-1, size-1, 0, size-1, fg); 00301 DrawLine (surface, size-1, 0, 0, 0, fg); 00302 char label[16]; 00303 sprintf (label, "%03d,%03d", globe_x, globe_z); 00304 DrawTextC (surface, &globals->fonts.ftthin24, size/2, size/4, fg, label); 00305 sprintf (label, "Q%1d%1d", x%2, z%2); 00306 DrawTextC (surface, &globals->fonts.ftthin24, size/2, 3*size/4, fg, label); 00307 texid = TextureFromSurface (surface, true); 00308 FreeSurface (surface); 00309 00310 state->setTexture (texid); 00311 00312 } else { 00313 00314 // Populate super tile textures 00315 00316 } 00317 00319 00320 CTerrainTile::Create (); 00321 } 00322 00323 void CQuarterGlobeTile::Destroy (void) 00324 { 00325 CTerrainTile::Destroy (); 00326 } 00327 00328 void CQuarterGlobeTile::UpdatePosition (SPosition pos) 00329 { 00330 /* 00331 int px, pz; 00332 lat_lon_to_qgt (pos.lat, pos.lon, px, pz); 00333 00334 int dx = px - x; 00335 int dz = pz - z; 00336 */ 00337 00338 // Find distance in QGT between center of this QGT and updated position 00339 double dx = 0; 00340 double dz = 0; 00341 delta_qgt (pos, x, z, dx, dz); 00342 00343 sgVec3 t; 00344 t[0] = (float)(dx * QGT_FLAT_CARTESIAN_BOUND_FT * 2.0); 00345 t[1] = (float)(dz * QGT_FLAT_CARTESIAN_BOUND_FT * 2.0); 00346 t[2] = 0; 00347 00348 // Set translation transform 00349 this->setTransform (t); 00350 } 00351 00352 void CQuarterGlobeTile::print (FILE *fd, char *indent, int how_much) 00353 { 00354 CTerrainTile::print (fd, indent, how_much); 00355 } 00356 00357 00358 /* 00359 00360 CDefaultQuarterGlobeTile::~CDefaultQuarterGlobeTile (void) 00361 { 00362 if (IsCreated()) Destroy(); 00363 00364 // Delete default super tiles and deallocate storage 00365 int i, j; 00366 for (i=0; i<stArraySize; i++) { 00367 for (j=0; j<stArraySize; j++) { 00368 CDefaultSuperTile *st = stArray[i][j]; 00369 delete st; 00370 } 00371 delete stArray[i]; 00372 } 00373 delete stArray; 00374 } 00375 00376 void CDefaultQuarterGlobeTile::Create (void) 00377 { 00378 globals->terrainmgr->Log ("Creating Default Quarter Globe Tile %d,%d(%1d%1d)", 00379 globe_x, globe_z, x%2, z%2); 00380 00381 // Create SSG branch as top-level entity 00382 top = new ssgBranch (); 00383 char name[64]; 00384 int n = 2; // Dimension of these tiles per globe tile 00385 sprintf (name, "QGT (%d,%d)(%1d%1d)", globe_x, globe_z, x%n, z%n); 00386 top->setName (name); 00387 00388 // Check for QGT debug mode 00389 if (globals->terrainmgr->debugLevel == QUARTER_GLOBE_TILES) { 00390 // Calculate cartesian coordinates for tile corners relative to parent globe tile 00391 SVector vsw, vnw, vse, vne; 00392 vsw = PosToFlatCartesian (sw, globe_x, globe_z); 00393 vnw = PosToFlatCartesian (nw, globe_x, globe_z); 00394 vse = PosToFlatCartesian (se, globe_x, globe_z); 00395 vne = PosToFlatCartesian (ne, globe_x, globe_z); 00396 00397 // Create debug texture 00398 SSurface *surface = CreateSurface (64, 64); 00399 unsigned int bg = MakeRGB (128, 128, 128); // Medium grey 00400 unsigned int fg = MakeRGB (255, 255, 255); // White 00401 surface->xScreen = surface->yScreen = 0; 00402 EraseSurfaceRGB (surface, bg); 00403 DrawLine (surface, 0, 0, 63, 0, fg); 00404 DrawLine (surface, 63, 0, 63, 63, fg); 00405 DrawLine (surface, 63, 63, 0, 63, fg); 00406 DrawLine (surface, 63, 0, 0, 0, fg); 00407 char label[16]; 00408 sprintf (label, "%03d,%03d", globe_x, globe_z); 00409 DrawTextC (surface, &globals->fonts.ftmono12, 32, 16, fg, label); 00410 int xmod = x % 2; 00411 int zmod = z % 2; 00412 sprintf (label, "Q%1d%1d", xmod, zmod); 00413 DrawTextC (surface, &globals->fonts.ftmono12, 32, 36, fg, label); 00414 texid = TextureFromSurface (surface, true); 00415 FreeSurface (surface); 00416 00417 // Initialize state information for the detail tile 00418 ssgSimpleState *state = new ssgSimpleState (); 00419 state->setShadeModel (GL_SMOOTH); 00420 state->disable (GL_LIGHTING); 00421 state->enable (GL_CULL_FACE); 00422 state->enable (GL_BLEND); 00423 state->disable (GL_ALPHA_TEST); 00424 state->setColourMaterial (GL_AMBIENT_AND_DIFFUSE); 00425 state->setMaterial (GL_EMISSION, 0, 0, 0, 1); 00426 state->setMaterial (GL_SPECULAR, 0, 0, 0, 1); 00427 00428 // Terrain is textured with quarter globe tile default debug texture 00429 state->enable (GL_TEXTURE_2D); 00430 state->setTexture (texid); 00431 state->disable (GL_COLOR_MATERIAL); 00432 00433 // Set vertices 00434 sgVec3 v1, v2, v3, v4; 00435 sgSetVec3 (v1, vnw.x, vnw.y, vnw.z); 00436 sgSetVec3 (v2, vsw.x, vsw.y, vsw.z); 00437 sgSetVec3 (v3, vne.x, vne.y, vne.z); 00438 sgSetVec3 (v4, vse.x, vse.y, vse.z); 00439 00440 // Define arrays for face data 00441 ssgVertexArray *va = new ssgVertexArray(4); 00442 va->add (v1); 00443 va->add (v2); 00444 va->add (v3); 00445 va->add (v4); 00446 00447 // Allocate texture coordinates 00448 sgVec2 t1, t2, t3, t4; 00449 sgSetVec2 (t1, 0.0, 1.0); // Upper-left NW 00450 sgSetVec2 (t2, 0.0, 0.0); // Lower-left SW 00451 sgSetVec2 (t3, 1.0, 1.0); // Upper-right NE 00452 sgSetVec2 (t4, 1.0, 0.0); // Lower-right SE 00453 00454 ssgTexCoordArray *ta = new ssgTexCoordArray(4); 00455 ta->add (t1); 00456 ta->add (t2); 00457 ta->add (t3); 00458 ta->add (t4); 00459 00460 ssgVtxTable *vtab = new ssgVtxTable (GL_TRIANGLE_STRIP, va, NULL, ta, NULL); 00461 vtab->setState (state); 00462 vtab->setName ("TriStrip"); 00463 00464 top->addKid (vtab); 00465 00466 } else { 00467 int i, j; 00468 00469 // Create all default super tiles 00472 for (i=0; i<8; i++) { 00473 for (j=0; j<8; j++) { 00474 CDefaultSuperTile *st = stArray[i][j]; 00475 st->Create (); 00476 top->addKid (st->GetSSGEntity()); 00477 } 00478 } 00479 } 00480 00481 // If scenery file exists for this quarter globe tile, load the objects 00482 char sceneryFile[256]; 00483 sprintf (sceneryFile, "DATA\\D%03d%03d\\SCENERYA.S%1d%1d", globe_x, globe_z, x%2, z%2); 00484 if (pexists (&globals->pfs, sceneryFile)) { 00485 // Instantiate scenery model object 00486 sceneryModels = new CSceneryModels (sceneryFile); 00487 top->addKid (sceneryModels->GetSSGEntity ()); 00488 } 00489 00490 CTerrainTile::Create (); 00491 } 00492 00493 void CDefaultQuarterGlobeTile::Destroy (void) 00494 { 00495 globals->terrainmgr->Log ("Destroying Default Quarter Globe Tile %d,%d(%1d%1d)", 00496 globe_x, globe_z, x%2, z%2); 00497 00498 // Destroy all default super tiles 00499 int i, j; 00500 for (i=0; i<stArraySize; i++) { 00501 for (j=0; j<stArraySize; j++) { 00502 CDefaultSuperTile *st = stArray[i][j]; 00503 if (st != NULL) { 00504 if (st->IsCreated()) { 00505 st->Destroy(); 00506 } 00507 } 00508 } 00509 } 00510 00511 CTerrainTile::Destroy(); 00512 } 00513 00514 void CDefaultQuarterGlobeTile::Print (FILE *f) 00515 { 00516 } 00517 00518 00519 // 00520 // CSlicedQuarterGlobeTile 00521 // 00522 00523 CSlicedQuarterGlobeTile::CSlicedQuarterGlobeTile (unsigned int x, 00524 unsigned int z, 00525 const char* folder) 00526 : CQuarterGlobeTile (x, z) 00527 { 00528 // Store local copy of data folder path 00529 strcpy (datapath, folder); 00530 00531 // Allocate 8x8 array for default super tiles instantiated in Read() 00532 int i, j; 00533 stArraySize = 8; 00534 stArray = new CSlicedSuperTile**[stArraySize]; 00535 for (i=0; i<stArraySize; i++) { 00536 stArray[i] = new CSlicedSuperTile*[stArraySize]; 00537 for (j=0; j<stArraySize; j++) { 00538 stArray[i][j] = NULL; 00539 } 00540 } 00541 00542 // Add entry to elevation database that will be populated by super tiles 00543 trnElevations = tedb->AddTRN (x, z, stArraySize); 00544 00545 // Initialize low-resolution fulltex data members 00546 fulltex = NULL; 00547 fulltexid = 0; 00548 } 00549 00550 CSlicedQuarterGlobeTile::~CSlicedQuarterGlobeTile (void) 00551 { 00552 if (IsCreated()) Destroy(); 00553 00554 // Delete and deallocate storage for super tile array 00555 int i, j; 00556 for (i=0; i<stArraySize; i++) { 00557 for (j=0; j<stArraySize; j++) { 00558 delete stArray[i][j]; 00559 } 00560 delete[] stArray[i]; 00561 } 00562 delete[] stArray; 00563 00564 // Remove TRN elevations from TEDB 00565 tedb->RemoveTRN (x, z); 00566 } 00567 00568 int CSlicedQuarterGlobeTile::Read (SStream *stream, Tag tag) 00569 { 00570 int rc = TAG_READ; 00571 00572 switch (tag) { 00573 case 'half': 00574 // Quarter globe tile indices 00575 ReadUInt (&half_x, stream); 00576 ReadUInt (&half_z, stream); 00577 rc = TAG_READ; 00578 break; 00579 00580 case 'lowr': 00581 // Detail tile indices for lower-left corner 00582 ReadUInt (&lowr_x, stream); 00583 ReadUInt (&lowr_z, stream); 00584 rc = TAG_READ; 00585 break; 00586 00587 case 'supr': 00588 // Super tile sub-object 00589 { 00590 unsigned int supr_x, supr_z; 00591 ReadUInt (&supr_x, stream); 00592 ReadUInt (&supr_z, stream); 00593 00594 int sx = (x * 8) + supr_x; 00595 int sz = (z * 8) + supr_z; 00596 00597 CSlicedSuperTile *suprtile = new CSlicedSuperTile (sx, sz, trnElevations); 00598 ReadFrom (suprtile, stream); 00599 stArray[supr_x][supr_z] = suprtile; 00600 } 00601 rc = TAG_READ; 00602 break; 00603 } 00604 00605 return rc; 00606 } 00607 00608 void CSlicedQuarterGlobeTile::Create (void) 00609 { 00610 globals->terrainmgr->Log ("Creating Sliced Quarter Globe Tile %d,%d(%1d%1d)", 00611 globe_x, globe_z, x%2, z%2); 00612 00613 // Create SSG branch as top-level entity 00614 top = new ssgBranch (); 00615 char name[64]; 00616 int n = 2; // Dimension of these tiles per globe tile 00617 sprintf (name, "QGT (%d,%d)(%1d%1d)", globe_x, globe_z, x%n, z%n); 00618 top->setName (name); 00619 00620 int i, j; 00621 00622 // Load low-detail texture 00624 char fulltexRaw[64], fulltexAct[64]; 00625 i = ((z % 2)) * 2 + (x % 2); 00626 sprintf (fulltexRaw, "%s\\FULLTEX%d.RAW", datapath, i+1); 00627 sprintf (fulltexAct, "%s\\FULLTEX%d.ACT", datapath, i+1); 00628 00629 if (pexists(&globals->pfs, fulltexRaw) && 00630 pexists(&globals->pfs, fulltexAct)) 00631 { 00632 // Create mipmapped low-res texture 00633 fulltex = new CRawImage (fulltexRaw, fulltexAct); 00634 fulltexid = fulltex->GetTexture (true); 00635 fulltexOffset = 8.0f / 512.0f; 00636 ds = dt = (1.0f - (2.0f * fulltexOffset)) / (float)stArraySize; 00637 } else { 00638 // Can't load low-resolution texture 00639 globals->logWarning->Write ("CSlicedQuarterGlobeTile : Can't open %s", fulltexRaw); 00640 } 00641 00642 // Check for QGT debug mode 00643 if (globals->terrainmgr->debugLevel == SLICED_QUARTER_GLOBE_TILES) { 00644 00645 // Calculate cartesian coordinates for subtile corners 00646 SVector vsw, vnw, vse, vne; 00647 vsw = PosToFlatCartesian (sw, globe_x, globe_z); 00648 vnw = PosToFlatCartesian (nw, globe_x, globe_z); 00649 vse = PosToFlatCartesian (se, globe_x, globe_z); 00650 vne = PosToFlatCartesian (ne, globe_x, globe_z); 00651 00652 // Initialize state information for the detail tile 00653 ssgSimpleState *state = new ssgSimpleState (); 00654 state->setShadeModel (GL_SMOOTH); 00655 state->disable (GL_LIGHTING); 00656 state->enable (GL_CULL_FACE); 00657 state->enable (GL_BLEND); 00658 state->disable (GL_ALPHA_TEST); 00659 state->setColourMaterial (GL_AMBIENT_AND_DIFFUSE); 00660 state->setMaterial (GL_EMISSION, 0, 0, 0, 1); 00661 state->setMaterial (GL_SPECULAR, 0, 0, 0, 1); 00662 00663 // Terrain is textured with quarter globe tile default debug texture 00664 state->enable (GL_TEXTURE_2D); 00665 state->setTexture (fulltexid); 00666 state->disable (GL_COLOR_MATERIAL); 00667 00668 // Set vertices for triangle strip in order NW, SW, NE, SE 00669 sgVec3 v1, v2, v3, v4; 00670 sgSetVec3 (v1, vnw.x, vnw.y, 0); 00671 sgSetVec3 (v2, vsw.x, vsw.y, 0); 00672 sgSetVec3 (v3, vne.x, vne.y, 0); 00673 sgSetVec3 (v4, vse.x, vse.y, 0); 00674 00675 // Define arrays for face data 00676 ssgVertexArray *va = new ssgVertexArray(4); 00677 va->add (v1); 00678 va->add (v2); 00679 va->add (v3); 00680 va->add (v4); 00681 00682 // Allocate texture coordinates 00683 float offset = 8.0f / 512.0f; 00684 sgVec2 t1, t2, t3, t4; 00685 sgSetVec2 (t1, 0.0 + offset, 0.0 + offset); // NW = Lower-left 00686 sgSetVec2 (t2, 0.0 + offset, 1.0 - offset); // SW = Upper-left 00687 sgSetVec2 (t3, 1.0 - offset, 0.0 + offset); // NE = Lower-right 00688 sgSetVec2 (t4, 1.0 - offset, 1.0 - offset); // SE = Upper-right 00689 00690 ssgTexCoordArray *ta = new ssgTexCoordArray(4); 00691 ta->add (t1); 00692 ta->add (t2); 00693 ta->add (t3); 00694 ta->add (t4); 00695 00696 ssgVtxTable *vtab = new ssgVtxTable (GL_TRIANGLE_STRIP, va, NULL, ta, NULL); 00697 vtab->setState (state); 00698 vtab->setName ("TriStrip"); 00699 00700 top->addKid (vtab); 00701 00702 } else { 00703 00704 // Create child sliced super tiles 00705 STileTextureInfo info; 00706 info.texid = fulltexid; 00707 for (i=0; i<stArraySize; i++) { 00708 for (j=0; j<stArraySize; j++) { 00709 CSlicedSuperTile *st = stArray[i][j]; 00710 00711 if (fulltexid != 0) { 00712 info.lls = fulltexOffset + (i * ds); 00713 info.urs = info.lls + ds; 00714 info.llt = fulltexOffset + ((stArraySize - j - 1) * dt); 00715 info.urt = info.llt + dt; 00716 st->AssignTexture (TILE_DETAIL_LOW, info); 00717 } 00718 st->Create (); 00719 top->addKid (st->GetSSGEntity()); 00720 } 00721 } 00722 } 00723 00724 // If scenery file exists for this quarter globe tile, load the objects 00725 char sceneryFile[256]; 00726 sprintf (sceneryFile, "DATA\\D%03d%03d\\SCENERYA.S%1d%1d", globe_x, globe_z, x%2, z%2); 00727 if (pexists (&globals->pfs, sceneryFile)) { 00728 // Instantiate scenery model object 00729 sceneryModels = new CSceneryModels (sceneryFile); 00730 top->addKid (sceneryModels->GetSSGEntity ()); 00731 } 00732 00733 CTerrainTile::Create(); 00734 } 00735 00736 void CSlicedQuarterGlobeTile::Destroy (void) 00737 { 00738 globals->terrainmgr->Log ("Destroying Sliced Quarter Globe Tile %d,%d(%1d%1d)", 00739 globe_x, globe_z, x%2, z%2); 00740 00741 // Destroy child sliced super tiles 00742 int i, j; 00743 for (i=0; i<stArraySize; i++) { 00744 for (j=0; j<stArraySize; j++) { 00745 CSlicedSuperTile *s = stArray[i][j]; 00746 if (s != NULL && s->IsCreated()) { 00747 s->Destroy (); 00748 } 00749 } 00750 } 00751 00752 // Delete low-resolution fulltex texture 00753 if (fulltex != NULL) delete fulltex; 00754 if (fulltexid != 0) glDeleteTextures (1, &fulltexid); 00755 00756 CTerrainTile::Destroy(); 00757 } 00758 00759 void CSlicedQuarterGlobeTile::Print (FILE *f) 00760 { 00761 } 00762 00763 00764 */
|
|
Documentation generated by
|