Changeset 1058 for GTP/trunk/Lib/Geom/shared
- Timestamp:
- 06/26/06 17:36:46 (19 years ago)
- Location:
- GTP/trunk/Lib/Geom/shared
- Files:
-
- 4 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Geom/shared/GTGeometry/GTGeometry.vcproj
r1057 r1058 263 263 </File> 264 264 <File 265 RelativePath=".\src\libs\leaves\Point3D.cpp">266 </File>267 <File268 265 RelativePath=".\src\libs\leaves\VertexData.cpp"> 269 266 </File> … … 405 402 </File> 406 403 <File 407 RelativePath=".\include\hoja.h">408 </File>409 <File410 404 RelativePath=".\src\libs\NPrim.h"> 411 405 </File> 412 406 <File 413 RelativePath=".\src\libs\leaves\Point3D.h">414 </File>415 <File416 407 RelativePath=".\src\libs\detail\policy.h"> 417 408 </File> … … 436 427 <File 437 428 RelativePath=".\src\libs\tri_stripper.h"> 438 </File>439 <File440 RelativePath=".\src\libs\leaves\Vector.h">441 429 </File> 442 430 <File -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodObject.h
r1056 r1058 12 12 } 13 13 uint32 GetUniqueID(void) const { return uniqueID; } 14 virtual uint32 GoToLod(uint32)=0;14 virtual void GoToLod(Real)=0; 15 15 16 16 private: -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodStripsLibrary.h
r1056 r1058 15 15 #include "GeoMesh.h" 16 16 #include <vector> 17 #include <time.h>18 17 #include "VertexData.h" 19 18 #include "GeoLodObject.h" … … 80 79 // Structures with the data read from the file 81 80 // We won't work with these structures 82 SmallIntVector 83 std::vector <LODRegisterType> 84 std::vector <SmallIntVector> 85 LongVector 81 SmallIntVector mFileVertices; 82 std::vector <LODRegisterType> mFileChangesLOD; 83 std::vector <SmallIntVector> mFileStrips; 84 LongVector mData; 86 85 87 86 // Structures with the data to work with … … 105 104 106 105 // For the efficient version. 107 SmallInt 108 SmallInt 109 SmallInt 106 SmallInt mTotalFaces; 107 SmallInt *mCurrentData; 108 SmallInt *mStripsChanges; 110 109 LODRegisterType *mCurrentRegLOD; 111 SmallInt *mVertex; 110 SmallInt *mVertex; 111 112 SmallInt minFaces, maxFaces; 112 113 113 114 // Changes of Strips in LOD file (p). … … 145 146 ~LodStripsLibrary(void); 146 147 147 /// Copy constructor148 //LodStripsLibrary(const LodStripsLibrary&);149 150 /// Assignment operator151 //LodStripsLibrary& operator =(const LodStripsLibrary&);152 153 148 /// Returns the highest LOD. 154 149 uint32 MaxLod(); … … 158 153 159 154 /// Returns de current LOD and changes to the specified LOD. 160 virtual uint32 GoToLod(uint32);155 virtual void GoToLod(Real); 161 156 162 157 /// Establishes the new LOD range. … … 175 170 /// Returns the number of vertices of the lowest LOD. 176 171 uint32 MinVertices(); 177 178 /* // (New) Get the number of strips.179 uint32 GetStripCount() const;180 uint32 GetIndexCountByStrip(uint32) const;*/181 172 }; 182 173 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/include/GeoLodTreeLibrary.h
r1056 r1058 10 10 #include "GeoLodObject.h" 11 11 12 class Arbol;13 12 class Foliage; 14 class Point3D;15 13 16 14 namespace Geometry … … 37 35 38 36 // funciones ya descritas en la API 39 uint32 GoToTrunkLod(uint32 newlod);37 /* uint32 GoToTrunkLod(uint32 newlod); 40 38 uint32 MinTrunkLod(void) const; 41 39 uint32 MaxTrunkLod(void) const; 42 40 uint32 GoToFoliageLod(uint32 newlod); 43 41 uint32 MinFoliageLod(void) const; 44 uint32 MaxFoliageLod(void) const; 42 uint32 MaxFoliageLod(void) const;*/ 43 44 void GoToTrunkLod(Real); 45 void GoToFoliageLod(Real); 45 46 46 47 // changes the lod of the entire object (trunk and leaves) 47 virtual uint32 GoToLod(uint32);48 virtual void GoToLod(Real); 48 49 49 50 // new proposed functions … … 69 70 private: 70 71 Geometry::LodStripsLibrary *trunk; 71 Arbol *arbol;72 72 Foliage *foliage; 73 73 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodStripsLibrary.cpp
r1018 r1058 35 35 // Loads the Level Of Detail file. 36 36 LodStripsLibrary::LoadStripMesh((char*)name_of_file,mGeoMesh); 37 38 GoToLod(0.0f); 39 minFaces = 0; 40 for (unsigned int strip = 0; strip < mTotalStrips; strip++) 41 minFaces += int(mStrips[strip].size() - 2); 42 43 GoToLod(1.0f); 44 maxFaces = 0; 45 for (unsigned int strip = 0; strip < mTotalStrips; strip++) 46 maxFaces += int(mStrips[strip].size() - 2); 37 47 } 38 48 … … 54 64 // Go to the level of detail. 55 65 //----------------------------------------------------------------------------- 56 uint32 LodStripsLibrary::GoToLod(uint32 newLOD)66 void LodStripsLibrary::GoToLod(float lodfactor) 57 67 { 58 68 register int j; … … 73 83 uint32 return_value; 74 84 85 uint32 newLOD = (1.0f-lodfactor) * mLods; 86 75 87 // Initialize the return value to the current LOD. 76 88 return_value = mCurrentLod; … … 225 237 226 238 UpdateDataRetrievalInterface(); 227 return return_value;239 // return return_value; 228 240 } 229 241 … … 270 282 uint32 LodStripsLibrary::MaxFaces() 271 283 { 272 uint32 number_of_faces;284 /* uint32 number_of_faces; 273 285 274 286 uint32 current_lod; … … 287 299 GoToLod(current_lod); 288 300 289 return number_of_faces; 301 return number_of_faces;*/ 302 303 return maxFaces; 290 304 } 291 305 … … 295 309 uint32 LodStripsLibrary::MinFaces() 296 310 { 297 uint32 current_lod;311 /* uint32 current_lod; 298 312 uint32 number_of_faces; 299 313 … … 311 325 GoToLod(current_lod); 312 326 313 return number_of_faces; 327 return number_of_faces;*/ 328 329 return minFaces; 314 330 } 315 331 -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/GeoLodTreeLibrary.cpp
r1057 r1058 1 //#include "defs.h"2 1 #include <assert.h> 3 2 #include "GeoLodTreeLibrary.h" … … 10 9 Geometry::Mesh *treeGeoMesh, 11 10 uint32 leafSubMeshID/* 12 std::string foliage_verts,13 std::string foliage_leafs,14 std::string foliage_simpl,15 uint32 leafSubMeshID,16 11 CREATEVERTEXDATAFUNC vdfun, 17 12 CREATEINDEXDATAFUNC idfun, … … 22 17 23 18 // Cargar la copa del árbol 24 // arbol = new Arbol(foliage_verts.c_str(),foliage_leafs.c_str(),foliage_simpl.c_str(),NULL/*vdfun*/,NULL/*idfun*/);25 19 Geometry::SubMesh * leafsSubMesh = &(treeGeoMesh->mSubMesh[leafSubMeshID]); 26 20 foliage = new Foliage(leafsSubMesh,leafSimpSeqFile.c_str()); 21 GoToFoliageLod(1.0f); 27 22 } 28 23 /* … … 77 72 */ 78 73 79 uint32 LodTreeLibrary::GoToTrunkLod(uint32 newlod) 80 { 81 return trunk->GoToLod(newlod); 82 /* uint32 previouslod = trunk->LodActual; 83 trunk->VerModeloVBO(newlod); 84 return previouslod;*/ 85 } 86 74 void LodTreeLibrary::GoToTrunkLod(float newlod) 75 { 76 trunk->GoToLod(newlod); 77 } 78 /* 87 79 uint32 LodTreeLibrary::MinTrunkLod(void) const 88 80 { 89 // return 3; // un polígono: preguntar a francisco90 // return (trunk->TOTALCAMBIOS*0.95f);91 81 return trunk->MinLod(); 92 82 } 93 83 uint32 LodTreeLibrary::MaxTrunkLod(void) const 94 84 { 95 // return (trunk->cVerts.size()*0.99);96 // return (trunk->TOTALCAMBIOS*0.95f);97 // return 0;98 85 return trunk->MaxLod(); 99 86 } 100 101 102 uint32 LodTreeLibrary::GoToFoliageLod(uint32 newlod) 103 { 104 foliage->AjusteHojas(newlod); 87 */ 88 89 void LodTreeLibrary::GoToFoliageLod(float newlod) 90 { 91 uint32 targetLeaves = (1.0f-newlod)*foliage->minLeaves + newlod*foliage->leafCount; 92 foliage->CalculateLOD(targetLeaves); 105 93 106 94 foliage->indexdata->Begin(); 107 95 foliage->vertexdata->Begin(); 108 int i = foliage-> ppio;109 int auxnum hojas = 0;96 int i = foliage->begin; 97 int auxnumleaves = 0; 110 98 while(i!=-1) 111 99 { 112 auxnum hojas++;100 auxnumleaves++; 113 101 i=foliage->Acth[i].next; 114 102 } 115 103 116 assert(auxnum hojas*6<=int(foliage->indexdata->GetNumMaxIndices()));117 foliage->indexdata->SetNumValidIndices(auxnum hojas*6);118 i = foliage-> ppio;119 int kkkk=0;104 assert(auxnumleaves*6<=int(foliage->indexdata->GetNumMaxIndices())); 105 foliage->indexdata->SetNumValidIndices(auxnumleaves*6); 106 i = foliage->begin; 107 int index=0; 120 108 while(i!=-1) 121 109 { … … 126 114 v3 = foliage->Leaves[i].vertsLeaf[3]; 127 115 128 foliage->indexdata->SetIndex( kkkk+0,v0);129 foliage->indexdata->SetIndex( kkkk+1,v1);130 foliage->indexdata->SetIndex( kkkk+2,v2);131 foliage->indexdata->SetIndex( kkkk+3,v2);132 foliage->indexdata->SetIndex( kkkk+4,v1);133 foliage->indexdata->SetIndex( kkkk+5,v3);116 foliage->indexdata->SetIndex(index+0,v0); 117 foliage->indexdata->SetIndex(index+1,v1); 118 foliage->indexdata->SetIndex(index+2,v2); 119 foliage->indexdata->SetIndex(index+3,v2); 120 foliage->indexdata->SetIndex(index+4,v1); 121 foliage->indexdata->SetIndex(index+5,v3); 134 122 135 123 foliage->vertexdata->SetVertexTexCoord(v0,0,0); … … 138 126 foliage->vertexdata->SetVertexTexCoord(v3,1,1); 139 127 140 kkkk+=6;128 index+=6; 141 129 i=foliage->Acth[i].next; 142 130 } 143 131 foliage->indexdata->End(); 144 132 foliage->vertexdata->End(); 145 146 return 0; 147 } 148 133 } 134 /* 149 135 uint32 LodTreeLibrary::MinFoliageLod(void) const 150 136 { 151 // return arbol->minHojas;152 137 return foliage->nHojas; 153 138 } 154 139 uint32 LodTreeLibrary::MaxFoliageLod(void) const 155 140 { 156 // return arbol->TotHojas;157 //return arbol->nHojas;158 141 return foliage->minHojas; 159 } 142 }*/ 160 143 161 144 /*const VertexData* LodTreeLibrary::Get_Trunk_VertexData(void) const … … 165 148 const MultiIndexData* LodTreeLibrary::CurrentLOD_Trunk_Indices(void) const 166 149 { 167 // return (uint32*)trunk->vStrips[istrip];168 // return trunk->indices_x_tira[istrip];169 150 return trunk->dataRetrievalInterface; 170 151 } … … 178 159 const IndexData* LodTreeLibrary::CurrentLOD_Foliage_Indices(void) const 179 160 { 180 // return current_foliage_indices;181 161 return foliage->indexdata; 182 162 } … … 216 196 217 197 // changes the lod of the entire object (trunk and leaves) 218 uint32 LodTreeLibrary::GoToLod(uint32 lod) 219 { 220 return 0; 221 } 198 void LodTreeLibrary::GoToLod(Real lod) 199 { 200 assert(lod<=1.0f && lod>=0.0f); 201 GoToTrunkLod(lod); 202 GoToFoliageLod(lod); 203 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.cpp
r1057 r1058 6 6 7 7 8 /****************************************** PANTALLA **************************************************/9 8 //-------------------------------------------------------------------------------------------------------------------------------- 10 9 // Void constructor … … 17 16 vertexdata(NULL), Leaves(NULL), MinDet(NULL) 18 17 { 19 cx = cy= cz= 0; 20 ppio= final = -1; 18 begin = final = -1; 21 19 22 20 ReadVertices(leavesSubMesh); 23 21 ReadLeafs(leavesSubMesh); 24 22 if (!ReadSimpSeq(simpSeq)) exit(1); 25 RellenoRaiz(); 26 CalculaTexCoordsYNorms(); 27 28 29 // esto no sé si devería haber akí 23 FillRoot(); 24 CalculateTexCoordsAndNorms(); 25 30 26 indexdata->SetNumValidIndices(0); 31 27 32 28 int h=0; 33 29 34 35 Acth = new ActiveLeafNode[nHojas*8]; 36 37 for ( h=0; h < nHojas; h++) { 30 Acth = new ActiveLeafNode[leafCount*8]; 31 32 for (h=0; h < leafCount; h++) { 38 33 39 34 Acth[h].index = h; … … 46 41 } 47 42 48 ppio = 0; 49 final = nHojas-1; 50 nhactivas = nHojas; 51 52 } 53 54 /* 55 //-------------------------------------------------------------------------------------------------------------------------------- 56 // Constructor with the name of a file cotaining the data 57 //-------------------------------------------------------------------------------------------------------------------------------- 58 Foliage::Foliage ( Arbol *Arbol1) 59 { 60 int h=0; 61 62 63 MiArbol = Arbol1; 64 65 Acth = new Activas[(MiArbol->nHojas)*8]; 66 67 for ( h=0; h < MiArbol->nHojas; h++) { 68 69 Acth[h].indice = h; 70 if ( h != 0) 71 { 72 Acth[h].prev = (h-1); 73 Acth[h-1].next = h; 74 } 75 76 } 77 78 ppio = 0; 79 final = (MiArbol->nHojas)-1; 80 nhactivas = MiArbol->nHojas; 81 82 83 84 }*/ 43 begin = 0; 44 final = leafCount-1; 45 active_leaf_count = leafCount; 46 } 85 47 86 48 //-------------------------------------------------------------------------------------------------------------------------------- … … 95 57 delete Acth; 96 58 } 97 //98 99 //--------------------------------------------------------------------------------------------------------------------------------100 // Dibuja una hoja101 //--------------------------------------------------------------------------------------------------------------------------------102 /*103 void Foliage::Dibuja_Hoja ( Hoja &aHoja)104 {105 106 float a,b,c;107 108 glBegin (GL_TRIANGLE_STRIP);109 glNormal3fv (aHoja.Normal);110 MiArbol->Vertices[aHoja.vertsLeaf[0]].GetCoordinates (a,b,c);111 glTexCoord2f ( 0.0, 0.0);112 113 glVertex3f (a,b,c);114 115 MiArbol->Vertices[aHoja.vertsLeaf[1]].GetCoordinates (a,b,c);116 glTexCoord2f ( 0.0, 1.0);117 glVertex3f (a,b,c);118 119 MiArbol->Vertices[aHoja.vertsLeaf[2]].GetCoordinates (a,b,c);120 glTexCoord2f ( 1.0, 0.0);121 glVertex3f (a,b,c);122 123 MiArbol->Vertices[aHoja.vertsLeaf[3]].GetCoordinates (a,b,c);124 glTexCoord2f ( 1.0, 1.0);125 glVertex3f (a,b,c);126 127 glEnd ();128 129 }130 131 132 //--------------------------------------------------------------------------------------------------------------------------------133 // Dibujar todas las hojas activas134 //--------------------------------------------------------------------------------------------------------------------------------135 136 int Foliage::DibujarHojas (float frustum[6][4], float zoom)137 {138 int hojactiva, i;139 140 141 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);142 143 hojactiva = 0;144 glBindTexture (GL_TEXTURE_2D,texName[0]);145 glEnable(GL_ALPHA_TEST);146 147 if ( zoom <75.0)148 //if ( false)149 {150 //calculo el culling de las hojas de minimo detalle151 Culling (frustum);152 //printf ( "--------------------------->Entro en culling\n");153 154 i= ppio;155 while ( i != -1)156 {157 if (MiArbol->Hojas[MiArbol->Hojas[i].raiz].visible == 1)158 {159 hojactiva ++;160 Dibuja_Hoja (MiArbol->Hojas[i]);161 }162 i = Acth[i].next;163 }164 }165 else166 {167 i= ppio;168 while ( i != -1)169 {170 hojactiva ++;171 Dibuja_Hoja (MiArbol->Hojas[i]);172 i=Acth[i].next;173 }174 175 }176 177 178 179 glDisable(GL_ALPHA_TEST);180 181 return ( hojactiva);182 183 }184 185 //--------------------------------------------------------------------------------------------------------------------------------186 // Dibujar media copa del arbol187 // si el char c es 'f' dibuja la parte delantera188 // si es 'b' la parte trasera189 //--------------------------------------------------------------------------------------------------------------------------------190 191 int Foliage::DibujaMediaCopa ( char c, float rva, float rvb,float rvc, float rvd, float radio)192 {193 int hojactiva, i;194 // int count, count2;195 196 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);197 198 hojactiva = 0;199 glBindTexture (GL_TEXTURE_2D,texName[0]);200 glEnable(GL_ALPHA_TEST);201 202 i= ppio;203 if ( c == 'b')204 {//count = 0;205 while ( i != -1)206 { //count ++;207 if ( Criterio (MiArbol->Hojas[i],'p', rva,rvb,rvc,rvd, radio) == false) //esta detras del plano208 {209 hojactiva ++;210 Dibuja_Hoja (MiArbol->Hojas[i]);211 }212 i = Acth[i].next;213 214 }215 // printf ( " EN LA TRASERA chequeo %i hojas \n", count);216 }217 else218 {// count2 = 0;219 220 while ( i != -1)221 { //count2++;222 if ( Criterio (MiArbol->Hojas[i],'p', rva,rvb,rvc,rvd, radio) == true) //esta detras del plano223 {224 hojactiva ++;225 Dibuja_Hoja (MiArbol->Hojas[i]);226 }227 i = Acth[i].next;228 }229 // printf ( " EN LA DELANTERA chequeo %i hojas \n", count2);230 231 }232 glDisable(GL_ALPHA_TEST);233 234 // nhactivas = hojactiva;235 236 237 return ( hojactiva);238 239 240 241 }242 243 244 245 //-------------------------------------------------------------------------------------------------------------------------246 // dibuja la esfera247 //-------------------------------------------------------------------------------------------------------------------------248 249 void Foliage::DibujaEsfera(float r)250 {251 252 glPushMatrix();253 glTranslated (0.0,MiArbol->cy, 0.0);254 glColor3f(1.0, 0.0, 0.0);255 glDisable(GL_LIGHTING);256 glLineWidth(1.2);257 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);258 glutSolidSphere ( r,20, 20);259 glEnable(GL_LIGHTING);260 glColor3f ( 1.0, 1.0, 1.0);261 glPopMatrix();262 263 }264 265 /****************************************** CULLING **************************************************/266 //-------------------------------------------------------------------------------------------------------------------------267 // culling de las hojas de menor detalle268 //-------------------------------------------------------------------------------------------------------------------------269 270 void Foliage::Culling (float frustum[6][4])271 {272 int i, j;273 274 i = 0;275 while ( MinDet[i].index != -1)276 {277 j = MinDet[i].index;278 if (LeafinFrustum ( j, frustum) == true) {279 // printf("dentro %i y el padre es %i\n", j, MiArbol->Hojas[MiArbol->MinDet[i].indice].parent);280 Leaves[j].visible = 1;281 }282 else283 {284 // printf("fuera %i\n", j);285 Leaves[j].visible = 0;286 }287 288 i++;289 }290 291 }292 293 294 //-------295 // si está en el frustrum --> true296 // sino --> false297 //------------298 299 300 bool Foliage::LeafinFrustum ( int i, float frustum[6][4])301 {302 float a,b,c, tmp;303 int j,p;304 Vector v;305 306 for (j =0; j<4; j++)307 {308 // MiArbol->Vertices[MiArbol->Hojas[i].vertsLeaf[j]].GetCoordinates (a,b,c);309 vertexdata->GetVertexCoord(Leaves[i].vertsLeaf[j],a,b,c);310 v[0]=a; v[1]=b; v[2]=c; v[3]=1;311 312 // el punto resultante será313 v = mat_aux*v;314 315 for( p = 0; p < 5; p++ )316 { tmp = float(frustum[p][0] * v[0] + frustum[p][1] * v[1] + frustum[p][2] * v[2] + frustum[p][3]);317 if ( tmp <= -2.0 ) return false;318 }319 }320 321 322 return true;323 324 }325 326 59 327 60 /****************************************** CRITERIO **************************************************/ … … 339 72 340 73 341 //-------------------------------------------------------------------------------------------------------------------------------- 342 // Colapsa dos hojas 343 //-------------------------------------------------------------------------------------------------------------------------------- 344 345 void Foliage::ColapsaHoja ( int h, int& post) 346 { 347 348 //actualizo los punteros del ppio y del final, y post 349 while (( ppio == Leaves[h].childLeft) || ( ppio == Leaves[h].childRight)) 350 ppio = Acth[ppio].next; 351 while (( final == Leaves[h].childLeft) || ( final == Leaves[h].childRight)) 352 final = Acth[final].prev; 353 354 while (( post == Leaves[h].childLeft) || ( post == Leaves[h].childRight)) 355 post = Acth[post].next; 356 357 358 359 //COLAPSAR = QUITO DOS DE ACTIVOS PONGO UNO A ACTIVO 360 361 if (Acth[Leaves[h].childLeft].next != -1) 362 Acth[Acth[Leaves[h].childLeft].next].prev = Acth[Leaves[h].childLeft].prev; 363 if (Acth[Leaves[h].childLeft].prev != -1) 364 Acth[Acth[Leaves[h].childLeft].prev].next = Acth[Leaves[h].childLeft].next; 365 366 if (Acth[Leaves[h].childRight].next != -1) 367 Acth[Acth[Leaves[h].childRight].next].prev = Acth[Leaves[h].childRight].prev; 368 if (Acth[Leaves[h].childRight].prev != -1) 369 Acth[Acth[Leaves[h].childRight].prev].next = Acth[Leaves[h].childRight].next; 370 371 372 // desconecto a los hijos 373 Acth[Leaves[h].childLeft].prev = -1; 374 Acth[Leaves[h].childLeft].next = -1; 375 Acth[Leaves[h].childRight].prev = -1; 376 Acth[Leaves[h].childRight].next = -1; 377 378 //añado al final 379 Acth[h].prev = final; 380 Acth[h].next = -1; 381 Acth[final].next = h; 382 final = h; 383 384 385 } 386 387 //-------------------------------------------------------------------------------------------------------------------------------- 388 // Splitea una hoja 389 //-------------------------------------------------------------------------------------------------------------------------------- 390 391 void Foliage::SplitHoja (int h, int &post) 392 { 393 394 // SPLITEAR: QUITO UNO, PONGO DOS 395 396 if ( ppio == h) ppio = Acth[h].next; 397 if ( final == h) final = Acth[h].prev; 398 399 // 1 enlazo los hijos 400 Acth[Leaves[h].childLeft].next = Leaves[h].childRight; 401 Acth[Leaves[h].childRight].prev = Leaves[h].childLeft; 402 Acth[Leaves[h].childRight].next = -1; 403 404 //y desconecto al padre 405 if ( Acth[h].prev != -1) 406 Acth[Acth[h].prev].next = Acth[h].next; 407 if ( Acth[h].next != -1) 408 Acth[Acth[h].next].prev = Acth[h].prev; 409 Acth[h].prev = -1; 410 Acth[h].next = -1; 411 412 //añado al final los hijos 413 Acth[Leaves[h].childLeft].prev = final; 414 Acth[final].next = Leaves[h].childLeft; 415 final = Leaves[h].childRight; 416 417 } 418 419 420 421 422 423 //------------------------------------------------------------------------------------------- 424 // fuerzo a splitear 425 // hoja -> es el nodo que cumple la condicion 426 // padre -> es el nodo que chequeaba de la lista de activos 427 // hpost -> es el nodo siguiente en la lista de activos 428 //------------------------------------------------------------------------------------------- 429 430 bool Foliage::Forzar_Split(int hoja, int padre, int &hpost) 431 { 432 433 int h; 434 lista <int> listah; 435 bool bien; 436 437 bien = false; 438 h = Leaves[hoja].parent; 439 listah.Inserta (h); // Inserta un dato en la lista 440 441 while ( h != padre) 442 { 443 h = Leaves[h].parent; 444 listah.Inserta (h); // Inserta un dato en la lista 445 } 446 447 448 while (listah.NDatos () != 0) 449 { 450 h = listah.GetCola ();//coger el padre más alto 451 SplitHoja(h, hpost); 452 listah.Borra(h); 453 454 } 455 456 if ( listah.NDatos() == 0) 457 bien = true; 458 return (bien); 459 460 } 461 462 463 464 465 /****************************************** RESOLUCIÓN CONSTANTE **************************************************/ 466 467 468 int Foliage::ResolucionC (float dist, float dmax, float dmin) 469 { 470 471 float difdist, d; 472 int difhojas, nhojas; 473 474 if (( dist > dmin) && (dist <dmax)) 475 { 476 difdist = dmax - dmin; 477 difhojas = nHojas - minHojas; 478 479 d = dist - dmin; 480 481 //regla de 3 482 483 nhojas = int(abs(d*difhojas /difdist)); 484 485 AjusteHojas ((nHojas)-nhojas); 486 487 } 488 else if (dist > dmax) { 489 AjusteHojas (minHojas); 490 } 491 else if (dist < dmin) { 492 AjusteHojas (nHojas); 493 } 494 495 return (nhactivas); 496 } 497 498 499 500 void Foliage::AjusteHojas( int nhojas) 501 { 502 if ((nhojas <= nHojas) && (nhojas >= minHojas)) 503 { 504 if ( nhojas < nhactivas) { 505 RCecol ( nhactivas - nhojas); 74 75 void Foliage::CalculateLOD(int nleaves) 76 { 77 if ((nleaves <= leafCount) && (nleaves > minLeaves)) 78 { 79 if ( nleaves < active_leaf_count) { 80 RCecol (active_leaf_count - nleaves); 506 81 } 507 82 else { 508 RCsplit (nhojas-nhactivas ); 509 } 510 511 nhactivas = nhojas; 512 // printf ( "ajusto a %i\n", nhactivas ); 513 83 RCsplit (nleaves-active_leaf_count); 84 } 85 86 active_leaf_count = nleaves; 514 87 } 515 88 … … 524 97 j = num; 525 98 h = final+1; 526 while ((h<= TotHojas) && (j>0))99 while ((h<=leafTotal) && (j>0)) 527 100 { 528 while (( ppio == Leaves[h].childLeft) || ( ppio== Leaves[h].childRight))529 ppio = Acth[ppio].next;101 while (( begin == Leaves[h].childLeft) || ( begin == Leaves[h].childRight)) 102 begin = Acth[begin].next; 530 103 531 104 while (( final == Leaves[h].childLeft) || ( final == Leaves[h].childRight)) 532 105 final = Acth[final].prev; 533 534 535 //COLAPSAR = QUITO DOS DE ACTIVOS PONGO UNO A ACTIVO536 106 537 107 if (Acth[Leaves[h].childLeft].next != -1) … … 563 133 //incremento el posible siguiente colapso 564 134 h++; 565 566 567 } 568 569 } 570 571 /* 572 void Foliage::RCsplit ( int nhojas) 573 { 574 int i, hpost; 575 576 i = ppio; 577 578 while (( i != -1) && (nhojas>0)){ 579 hpost = Acth[i].next; 580 581 if (MiArbol->Leaves[i].childLeft != -1){ 582 SplitHoja(i, hpost); 583 nhojas --; 584 585 } 586 587 i = hpost; 588 589 } 590 } 591 */ 592 593 int Foliage::AnteriorActivo (int h) 135 } 136 } 137 138 int Foliage::PrevActive(int h) 594 139 { 595 140 int i; 596 141 597 142 598 if ( ppio> h) i = -1;143 if (begin > h) i = -1; 599 144 else 600 145 { … … 608 153 } 609 154 610 int Foliage:: PosteriorActivo(int h)155 int Foliage::NextActive(int h) 611 156 { int i; 612 157 613 158 i = h++; 614 159 615 while ((IsActive(i) == false) || (i> TotHojas))160 while ((IsActive(i) == false) || (i> leafTotal)) 616 161 i++; 617 162 618 if (i > TotHojas) i=-1;163 if (i > leafTotal) i=-1; 619 164 620 165 … … 629 174 j = num; 630 175 h = final; 631 while ((h > nHojas) && (j>0)) 632 { 633 176 while (h>leafCount && j>0) 177 { 634 178 ///////////// insertar a los hijos en orden segun su indice 635 179 //hijo izquierdo 636 ant = AnteriorActivo(Leaves[h].childLeft);637 post = PosteriorActivo(Leaves[h].childLeft);180 ant = PrevActive(Leaves[h].childLeft); 181 post = NextActive(Leaves[h].childLeft); 638 182 639 183 … … 641 185 Acth[Leaves[h].childLeft].prev = ant; 642 186 if (ant != -1) Acth[ant].next = Leaves[h].childLeft; 643 else ppio= Leaves[h].childLeft;187 else begin = Leaves[h].childLeft; 644 188 if (post != -1) Acth[post].prev = Leaves[h].childLeft; 645 189 646 190 647 191 //hijo derecho 648 ant = AnteriorActivo(Leaves[h].childRight);649 post = PosteriorActivo(Leaves[h].childRight);192 ant = PrevActive(Leaves[h].childRight); 193 post = NextActive(Leaves[h].childRight); 650 194 651 195 … … 653 197 Acth[Leaves[h].childRight].prev = ant; 654 198 if (ant != -1) Acth[ant].next = Leaves[h].childRight; 655 else ppio= Leaves[h].childRight;199 else begin = Leaves[h].childRight; 656 200 if (post != -1) Acth[post].prev = Leaves[h].childRight; 657 201 … … 695 239 vertexdata->End(); 696 240 697 Tot Verts = countv;241 TotalVerts = countv; 698 242 } 699 243 … … 746 290 { 747 291 int numtris = int(submesh->mIndexCount / 3); 748 nHojas= numtris / 2;749 for (int h=0; h< nHojas; h++)292 leafCount = numtris / 2; 293 for (int h=0; h<leafCount; h++) 750 294 { 751 295 Leaves[h].vertsLeaf[0] = submesh->mIndex[h*6+0]; … … 773 317 else 774 318 { 775 tn = nHojas;319 tn = leafCount; 776 320 while (fgets (linea, 255, fp_simpli) != NULL) 777 321 { … … 779 323 continue; 780 324 781 //N 446 Ver 10176 10178 10169 10171 Tv 156 154 E 2782 783 // sscanf(linea, "%s %lu %s %lu %lu %lu %lu %s %lu %lu %s %i",784 // &str, &tn, &str, &v0, &v1, &v2, &v3, &str, &tv1, &tv2, &str, &e );785 325 long int triviej00=-1, triviej01=-1; 786 326 long int triviej10=-1, triviej11=-1; … … 812 352 fclose(fp_simpli); 813 353 814 TotHojas=tn;354 leafTotal=tn; 815 355 816 356 return true; 817 357 } 818 358 819 void Foliage:: RellenoRaiz(void)359 void Foliage::FillRoot(void) 820 360 { 821 361 int i,j, k, t, cont; … … 826 366 cont =-1; 827 367 828 MinDet = new ActiveLeafNode[ nHojas*2];829 830 while (i< TotHojas)368 MinDet = new ActiveLeafNode[leafCount*2]; 369 370 while (i<leafTotal) 831 371 { 832 372 j=i; 833 while (Leaves[j].parent > -1) j=Leaves[j].parent;373 while (Leaves[j].parent>-1) j=Leaves[j].parent; 834 374 Leaves[i].root = j; 835 375 … … 853 393 } 854 394 855 if ( esta == false) //añado al final395 if ( esta == false) 856 396 { 857 397 cont++; … … 860 400 } 861 401 862 i++;402 i++; 863 403 } 864 404 865 min Hojas = cont;866 867 } 868 869 void Foliage::Calcula TexCoordsYNorms(void)405 minLeaves = cont; 406 407 } 408 409 void Foliage::CalculateTexCoordsAndNorms(void) 870 410 { 871 411 vertexdata->Begin(); 872 for (int i=0; i< nHojas; i++)412 for (int i=0; i<leafCount; i++) 873 413 { 874 414 const float* lanormal = Leaves[i].normal; … … 884 424 vertexdata->SetVertexNormal(Leaves[i].vertsLeaf[3], lanormal[0], lanormal[1], lanormal[2]); 885 425 vertexdata->SetVertexTexCoord(Leaves[i].vertsLeaf[3], 1.0f, 0.0f); 886 887 888 /* MiArbol->Vertices[aHoja.vertsLeaf[1]].GetCoordinates (a,b,c);889 glTexCoord2f ( 0.0, 1.0);890 glVertex3f (a,b,c);891 892 MiArbol->Vertices[aHoja.vertsLeaf[2]].GetCoordinates (a,b,c);893 glTexCoord2f ( 1.0, 0.0);894 glVertex3f (a,b,c);895 896 MiArbol->Vertices[aHoja.vertsLeaf[3]].GetCoordinates (a,b,c);897 glTexCoord2f ( 1.0, 1.0);898 glVertex3f (a,b,c);*/899 426 } 900 427 vertexdata->End(); … … 903 430 Foliage::Foliage(const Foliage *ar) 904 431 { 905 nHojas=ar->nHojas;906 MinDet = new ActiveLeafNode[nHojas*2];432 leafCount = ar->leafCount; 433 MinDet = new ActiveLeafNode[leafCount*2]; 907 434 // for (unsigned int i=0; i<nHojas*2; i++) 908 435 // MinDet[i]=ar->MinDet[i]; 909 memcpy(MinDet,ar->MinDet,sizeof(ActiveLeafNode)*nHojas*2); 910 TotHojas=ar->TotHojas; 911 cx=ar->cx; 912 cy=ar->cy; 913 cz=ar->cz; 914 rad=ar->rad; 915 minHojas=ar->minHojas; 916 TotVerts=ar->TotVerts; 436 memcpy(MinDet,ar->MinDet,sizeof(ActiveLeafNode)*leafCount*2); 437 leafTotal=ar->leafTotal; 438 minLeaves=ar->minLeaves; 439 TotalVerts=ar->TotalVerts; 917 440 918 441 create_vertex_data_func=ar->create_vertex_data_func; … … 945 468 int h=0; 946 469 947 Acth = new ActiveLeafNode[ nHojas*8];948 949 for ( h=0; h < nHojas; h++) {470 Acth = new ActiveLeafNode[leafCount*8]; 471 472 for ( h=0; h < leafCount; h++) { 950 473 951 474 Acth[h].index = h; … … 958 481 } 959 482 960 ppio= 0;961 final = nHojas-1;962 nhactivas = nHojas;963 964 } 483 begin = 0; 484 final = leafCount-1; 485 active_leaf_count = leafCount; 486 487 } -
GTP/trunk/Lib/Geom/shared/GTGeometry/src/libs/leaves/foliage.h
r1057 r1058 4 4 #include "GeoSubMesh.h" 5 5 #include "tlista.h" 6 #include "TMatrix.h"7 6 #include "VertexData.h" 8 7 #include "Leaf.h" … … 24 23 25 24 ActiveLeafNode *Acth; // first active leaf 26 int ppio, final; 27 int nhactivas; 28 TMatrix mat_aux; 25 int begin, final; 26 int active_leaf_count; 29 27 30 28 Foliage (const Geometry::SubMesh *, const char *simpSeq, Geometry::CREATEVERTEXDATAFUNC vdfun=NULL, Geometry::CREATEINDEXDATAFUNC idfun=NULL); … … 32 30 virtual ~Foliage (void); // Destructor 33 31 34 //culling 35 void Culling (float frustum[6][4]); 36 bool LeafinFrustum ( int i, float frustum[6][4]); 37 38 bool IsActive( int num) const; 39 int ResolucionV ( char c, float rva, float rvb,float rvc, float rvd, float radio); 40 void ColapsaHoja (int, int&); 41 void SplitHoja (int, int&); 42 bool Forzar_Split(int, int, int&); 43 int AnteriorActivo (int h); 44 int PosteriorActivo (int h); 45 46 47 // resolucion constante 48 int ResolucionC (float dist, float dmax, float dmin); 49 void AjusteHojas( int nhojas); 50 void RCecol ( int nhojas); 51 void RCsplit ( int nhojas); 32 void CalculateLOD(int nhojas); 52 33 53 34 Geometry::VertexData *vertexdata; … … 55 36 56 37 Leaf *Leaves; 57 ActiveLeafNode *MinDet; // primera hoja activa58 int nHojas;59 int TotHojas;38 ActiveLeafNode *MinDet; // first active leaf 39 int leafCount; 40 int leafTotal; 60 41 61 float cx,cy,cz; //centro de la copa// para los impostores y resolucion variable 62 float rad; //radio de la esfera envolvente 63 int minHojas; 64 int TotVerts; 42 int minLeaves; 43 int TotalVerts; 65 44 66 45 private: … … 68 47 Geometry::CREATEINDEXDATAFUNC create_index_data_func; 69 48 49 bool IsActive( int num) const; 50 int PrevActive (int h); 51 int NextActive (int h); 52 53 void RCecol(int nhojas); 54 void RCsplit(int nhojas); 55 70 56 void ReadLeafs(const Geometry::SubMesh *); 71 57 void ReadVertices(const Geometry::SubMesh *); 72 58 bool ReadSimpSeq(const char*); /// returns true when successful 73 void RellenoRaiz(void);59 void FillRoot(void); 74 60 75 61 void GetNormalH (Leaf&); 76 // void GetNormalT(Tronco&);77 62 78 63 void CrossProduct(const float *v1, const float *v2, float *res); 79 64 void Normalize(const float *v, float *res); 80 65 // void CalculaNormalesVertice(void); 81 void Calcula TexCoordsYNorms(void);66 void CalculateTexCoordsAndNorms(void); 82 67 83 68 }; -
GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h
r998 r1058 190 190 191 191 // Change de Level of detail of the object. 192 void GoToLod_LodStrip( unsigned int lod);193 void GoToLod_LodTree( unsigned int lod);192 void GoToLod_LodStrip(float lod); 193 void GoToLod_LodTree(float lod); 194 194 195 195 // load a image file as a texture -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshView.cpp
r1051 r1058 1129 1129 // Change de Level of detail of the object. 1130 1130 //--------------------------------------------------------------------------- 1131 void GeoMeshView::GoToLod_LodStrip( unsigned int lod)1131 void GeoMeshView::GoToLod_LodStrip(float lod) 1132 1132 { 1133 1133 if (mLodStrip) … … 1141 1141 // Change de Level of detail of the object. 1142 1142 //--------------------------------------------------------------------------- 1143 void GeoMeshView::GoToLod_LodTree( unsigned int lod)1143 void GeoMeshView::GoToLod_LodTree(float lod) 1144 1144 { 1145 1145 if (mLodTree) -
GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp
r1050 r1058 1373 1373 { 1374 1374 // Change the lod. 1375 geoMeshView->GoToLod_LodStrip(( unsigned int)o->value());1375 geoMeshView->GoToLod_LodStrip((float)o->value()); 1376 1376 1377 1377 // Refresh data aplication. … … 1394 1394 { 1395 1395 // Change the lod. 1396 geoMeshView->GoToLod_LodTree(( unsigned int)o->value());1396 geoMeshView->GoToLod_LodTree((float)o->value()); 1397 1397 1398 1398 // Refresh data aplication. … … 2401 2401 2402 2402 // Sets the slider range. 2403 mLodStripSlider->range(lodStripsLib->MinLod(),lodStripsLib->MaxLod()); 2403 // mLodStripSlider->range(lodStripsLib->MinLod(),lodStripsLib->MaxLod()); 2404 mLodStripSlider->range(0.0f,1.0f); 2404 2405 2405 2406 // Pass to geomeshview the lod strips object. … … 2431 2432 2432 2433 // Sets the slider range. 2433 mLodStripSlider->range(lodTreeLib->MaxTrunkLod(), lodTreeLib->MinTrunkLod()); 2434 mLodTreeSlider->range(lodTreeLib->MaxFoliageLod(), lodTreeLib->MinFoliageLod()); 2434 // mLodStripSlider->range(lodTreeLib->MaxTrunkLod(), lodTreeLib->MinTrunkLod()); 2435 // mLodTreeSlider->range(lodTreeLib->MaxFoliageLod(), lodTreeLib->MinFoliageLod()); 2436 mLodStripSlider->range(0.0f,1.0f); 2437 mLodTreeSlider->range(0.0f,1.0f); 2435 2438 2436 2439 // Pass to geomeshview the lod strips object. … … 2438 2441 2439 2442 // Puts the slider in the max position. 2440 mLodStripSlider->value( lodTreeLib->MinTrunkLod());2441 mLodTreeSlider->value( lodTreeLib->MinFoliageLod());2443 mLodStripSlider->value(1.0f); 2444 mLodTreeSlider->value(1.0f); 2442 2445 } 2443 2446
Note: See TracChangeset
for help on using the changeset viewer.