Changeset 1104 for GTP/trunk/App/Demos/Geom
- Timestamp:
- 07/07/06 17:07:06 (18 years ago)
- Location:
- GTP/trunk/App/Demos/Geom
- Files:
-
- 9 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Geom/Demo_LodStrips/main.cpp
r1092 r1104 446 446 447 447 //Models 448 entity = mSceneMgr->createEntity(model_name, "../../../OgreStuff/media/GT/ dwarflod.mesh");448 entity = mSceneMgr->createEntity(model_name, "../../../OgreStuff/media/GT/bunnylod.mesh"); 449 449 450 450 ogreMesh = entity->getMesh().getPointer(); … … 452 452 // load LOD info from the object 453 453 meshloader=new Geometry::GeoMeshLoader; 454 Geometry::Mesh *themesh = meshloader->load("../../../OgreStuff/media/GT/ dwarflod.mesh");454 Geometry::Mesh *themesh = meshloader->load("../../../OgreStuff/media/GT/bunnylod.mesh"); 455 455 456 456 node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); … … 481 481 entity->setMaterialName("test_mat"); 482 482 483 484 for (int i=1; i<4; i++) // 20 485 for (int j=1; j<4; j++) // 20 486 { 487 char newObjName[16]=""; 488 sprintf(newObjName,"arbol_%d_%d",i,j); 489 Ogre::SceneNode * auxnode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); 490 auxnode->attachObject( entity->clone(newObjName) ); 491 auxnode->scale(0.8f,0.8f,0.8f); 492 float randomsepx = (float)((rand()%18)-9); 493 float randomsepy = (float)((rand()%12)-6); 494 auxnode->translate(i*100.0f+randomsepx,0.0f,-j*100.0f-randomsepx); 495 } 496 497 483 498 // show overlay 484 499 Overlay* pOver = OverlayManager::getSingleton().getByName("Demo_LodStrips/Overlay"); -
GTP/trunk/App/Demos/Geom/Demo_LodTrees/main.cpp
r1092 r1104 30 30 Ogre::Mesh *ogreMesh=NULL; 31 31 Geometry::GeoMeshLoader *meshloader=NULL; 32 SceneNode* node;33 34 MaterialPtr *mat;32 bool force_maxLODfactor = false; 33 34 Ogre::Vector3 forest_center; 35 35 36 36 ColourValue color=ColourValue::Red; … … 75 75 mRenderOp.indexData->indexBuffer = ibuf; 76 76 mRenderOp.indexData->indexStart = 0; 77 mRenderOp.indexData->indexCount = indices_to_render; 77 mRenderOp.indexData->indexCount = indices_to_render; 78 78 79 79 unsigned long* pIdx = static_cast<unsigned long*>(ibuf->lock(Ogre::HardwareBuffer::HBL_NORMAL)); … … 138 138 int i=0; 139 139 140 dist = node->getPosition()- mCamera->getPosition();140 dist = forest_center - mCamera->getPosition(); 141 141 distance =dist.length(); 142 143 DumpDataToOgreBuffers(ogreMesh,myTrees);144 142 145 143 float lodfactor = (float)(distance - dist_min) / (float)(dist_max - dist_min); 146 144 lodfactor = 1.0f - lodfactor; 147 145 148 if (lodfactor >= 0.0f && lodfactor <= 1.0f) 146 if (lodfactor<0.0f) 147 lodfactor=0.0f; 148 if (lodfactor>1.0f) 149 lodfactor=1.0f; 150 151 if (force_maxLODfactor) 152 lodfactor=1.0f; 153 154 static float lodfactorBefore = -1.0f; 155 if (fabsf(lodfactorBefore-lodfactor)>0.05f) 149 156 { 150 157 myTrees->GoToLod(lodfactor); 151 152 if (lodfactor < 0.333f) 153 { 154 color.r=0.0; 155 color.g=(lodfactor)*3.0f;//nlod*1.0/(diflods/3); 156 color.b=(1.0-lodfactor)*3.0f;//(nlod*1.0/(diflods/3)); 157 } 158 else 159 { 160 if (lodfactor<0.666f) 161 { 162 color.r=(lodfactor-0.333f)*3.0f;//(nlod-diflods/3)*1.0/(diflods/3); 163 color.g=1.0; 164 color.b=0.0; 165 } 166 else 167 { 168 color.r=1.0; 169 color.g=(1.0-lodfactor)*3.0f;//(nlod-(2*diflods/3))*1.0/(diflods/3); 170 color.b=0.0; 171 } 172 } 173 mat[0]->setDiffuse(color); 174 } 175 /* else 176 { 177 if ((distance > dist_max)) 178 { 179 // myStrips->GoToLod(1.0f); 180 181 color.r=0.0; 182 color.g=0.0; 183 color.b=1.0; 184 mat[0]->setDiffuse(color); 185 186 } 187 else 188 { 189 if ((distance < dist_min)) 190 { 191 // myStrips->GoToLod(0.0f); 192 193 color.r=1.0; 194 color.g=0.0; 195 color.b=0.0; 196 mat[0]->setDiffuse(color); 197 } 198 } 199 }*/ 158 DumpDataToOgreBuffers(ogreMesh,myTrees); 159 lodfactorBefore=lodfactor; 160 } 200 161 201 162 // Move the node … … 211 172 mCamera->yaw(mRotScale); 212 173 174 force_maxLODfactor=mInputDevice->isKeyDown(Ogre::KC_F2); 175 213 176 if(mInputDevice->isKeyDown(Ogre::KC_RIGHT)) 214 177 mCamera->yaw(-mRotScale); 215 178 216 // Move the node217 if(mInputDevice->isKeyDown(Ogre::KC_W))218 node->translate(0,mMoveScale,0);219 220 if(mInputDevice->isKeyDown(Ogre::KC_S))221 node->translate(0,-mMoveScale,0);222 223 if(mInputDevice->isKeyDown(Ogre::KC_Z))224 node->scale(1.01,1.01,1.01);225 226 if(mInputDevice->isKeyDown(Ogre::KC_X))227 node->scale(0.99,0.99,0.99);228 229 // Rotate230 if(mInputDevice->isKeyDown(Ogre::KC_A))231 node->yaw(mRotScale);232 233 if(mInputDevice->isKeyDown(Ogre::KC_D))234 node->yaw(-mRotScale);235 236 179 if(mInputDevice->isKeyDown(Ogre::KC_ESCAPE)) 237 180 { 238 delete myTrees; 239 240 delete [] mat; 241 181 //delete myTrees; 242 182 return false; 243 183 } … … 262 202 mInfo->setCaption(cadena); 263 203 264 if (lodfactor<0.0f)265 lodfactor=0.0f;266 if (lodfactor>1.0f)267 lodfactor=1.0f;268 204 sprintf(cadena,"LOD factor: %f",lodfactor); 269 205 … … 296 232 void createScene(void) 297 233 { 298 mat = new MaterialPtr[1];234 // mat = new MaterialPtr[1]; 299 235 300 236 theCam = mCamera; 301 237 theCam->setPosition(0,20,dist_max+50); 302 238 // Set ambient light 303 mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); 304 305 // Create a point light 306 Light* l = mSceneMgr->createLight("MainLight"); 307 l->setType(Light::LT_DIRECTIONAL); 308 l->setDirection(0.0,0.0,-1.0); 239 // mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3)); 240 mSceneMgr->setAmbientLight(ColourValue(1.0, 1.0, 1.0)); 241 242 // Create a directional light 243 /* Light* l = mSceneMgr->createLight("MainLight"); 244 l->setType(Light::LT_DIRECTIONAL); 245 l->setDirection(0.0,-1.0,0.0);*/ 246 // l->setAttenuation(1000000.0f, 1.0f, 1.0f, 1.0f); 309 247 310 248 // Define a floor plane mesh … … 332 270 333 271 //Models 334 entity = mSceneMgr->createEntity(model_name, "../../../OgreStuff/media/GT/ betulalod.mesh");272 entity = mSceneMgr->createEntity(model_name, "../../../OgreStuff/media/GT/ML12m.mesh"); 335 273 336 274 ogreMesh = entity->getMesh().getPointer(); … … 338 276 // load LOD info from the object 339 277 meshloader=new Geometry::GeoMeshLoader; 340 Geometry::Mesh *themesh = meshloader->load("../../../OgreStuff/media/GT/betulalod.mesh"); 341 342 node = mSceneMgr->getRootSceneNode()->createChildSceneNode(); 343 node->attachObject( entity ); 344 node->rotate(Ogre::Vector3(1,0,0),Ogre::Radian(-90.0f)); 345 346 // myStrips = new LodStripsLibrary(lod_file,entity->getMesh().getPointer()); 278 Geometry::Mesh *themesh = meshloader->load("../../../OgreStuff/media/GT/ML12m.mesh"); 279 280 myTrees = new Geometry::LodTreeLibrary(meshloader->GetLodStripsData(),meshloader->GetTreeSimpSeq(),themesh); 281 282 entity->setNormaliseNormals(true); 283 284 for (int submesh=0; submesh < ogreMesh->getNumSubMeshes(); submesh++) 285 { 286 bool istrunk = myTrees->GetLeavesSubMesh()!=submesh; 287 if (istrunk) 288 entity->getSubEntity(submesh)->setMaterialName("Examples/Populifolia/trunk"); 289 else 290 entity->getSubEntity(submesh)->setMaterialName("Examples/Populifolia/leaf"); 291 } 292 293 forest_center=Ogre::Vector3(150.0f,0.0f,0.0f); 294 for (int i=1; i<8; i++) // 20 295 for (int j=1; j<8; j++) // 20 296 { 297 char newTreeName[16]=""; 298 sprintf(newTreeName,"arbol_%d_%d",i,j); 299 Ogre::SceneNode * auxnode = mSceneMgr->getRootSceneNode()->createChildSceneNode(); 300 auxnode->attachObject( entity->clone(newTreeName) ); 301 auxnode->scale(4.0f,4.0f,4.0f); 302 auxnode->rotate(Ogre::Vector3(1,0,0),Ogre::Radian(-3.14159f*0.5f)); 303 float randomsepx = (float)((rand()%18)-9); 304 float randomsepy = (float)((rand()%12)-6); 305 auxnode->translate(i*30.0f+randomsepx,0.0f,-j*30.0f-randomsepx); 306 } 347 307 348 308 if (!meshloader->GetLodStripsData() || !meshloader->GetTreeSimpSeq()) 349 309 exit(1); 350 351 // myStrips = new Geometry::LodStripsLibrary(meshloader->GetLodStripsData(),themesh);352 myTrees = new Geometry::LodTreeLibrary(meshloader->GetLodStripsData(),meshloader->GetTreeSimpSeq(),themesh);353 354 entity->setNormaliseNormals(true);355 356 /* // Colour-coded material357 mat[0] = MaterialManager::getSingleton().create("test_mat",358 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);359 mat[0]->setCullingMode(CULL_ANTICLOCKWISE);360 mat[0]->setAmbient(ColourValue::Black);361 mat[0]->setDiffuse(color);362 mat[0]->setLightingEnabled(true);363 entity->setMaterialName("test_mat");*/364 365 366 // Colour-coded material367 mat[0] = MaterialManager::getSingleton().create("test_mat",368 ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);369 mat[0]->setCullingMode(CULL_NONE);370 mat[0]->setAmbient(ColourValue::Black);371 mat[0]->setDiffuse(color);372 mat[0]->setLightingEnabled(true);373 mat[0]->createTechnique()->createPass()->createTextureUnitState("nm_rt.png");374 //entity->setMaterialName("test_mat");375 entity->setMaterialName("Examples/GrassFloor");376 377 310 378 311 // show overlay -
GTP/trunk/App/Demos/Geom/OgreStuff/media/materials/scripts/Example.material
r1092 r1104 735 735 } 736 736 737 material Examples/Populifolia/leaf 738 { 739 technique 740 { 741 pass 742 { 743 alpha_rejection greater 150 744 scene_blend alpha_blend 745 cull_hardware none 746 cull_software none 747 texture_unit 748 { 749 texture Pinus-leaf.tif 750 } 751 } 752 } 753 } 754 755 material Examples/Populifolia/trunk 756 { 757 technique 758 { 759 pass 760 { 761 cull_hardware anticlockwise 762 texture_unit 763 { 764 texture populifolia-trunk.png 765 } 766 } 767 } 768 } 769 737 770 material Examples/Rockwall 738 771 {
Note: See TracChangeset
for help on using the changeset viewer.