Thursday, December 4, 2014

Code excerpt for updating Ogre terrain height positions and some added notes

   Ogre::Terrain* cterrain = mTerrainGroup->getTerrain(0,0);  
   ss5<<"Terrain Size: "<< cterrain->getSize()<<"\n";  
   ss5<<"Maximum Height: "<< cterrain->getMaxHeight()<<"\n";  
   ss5<<"World Size: " << cterrain->getWorldSize()<<"\n";  
   for (int i=0; i<250; i++ ){  
      for (int j=0; j<250; j++){  
        ss5 << "Terrain position("<<i<<","<<j<<")"<<cterrain->getHeightAtPoint(i,j)<<"\n" ;  
        cterrain->setHeightAtPoint(i,j,cterrain->getHeightAtPoint(i,j)+100);  
      }  
   }  
   cterrain->update();  

The above is a code snippet for updating terrain height coordinates in Ogre 1.9x using Ogre's Terrain manager system.

Some bit of things to keep in mind with Ogre's terrain system is that like Unity and I imagine other game engine's there are two separate coordinate systems namely:  world coordinate system, and local terrain coordinates.  A given tutorial for instance through Ogre Tutorial's typically load the terrain with a world coordinate dimension ranges of 12,000 x 12000 while local terrain coordinate dimension's are 513 x 513.   As related to my previous post on the subject of extracting a terrain world coordinate position from a given ray trace query, you'd want to keep in mind converting from a world coordinate to local terrain coordinate position.   Ogre provides a function to do this

void Ogre::Terrain::getTerrainPosition ( const Vector3 WSpos,
Vector3 outTSpos 
) const


or practice example

                     Ogre::Vector3 outvec(0,0,0);  

                     Ogre::Vector3* outvecp = &outvec;
                     const Ogre::Vector3 invec = Ogre::Vector3(pos1.x,pos1.z, newpos1s[i]);
                     //const Ogre::Vector3& invecp = &invec;
                     cterrain->getTerrainPosition(invec,&outvec);

No comments:

Post a Comment

Oblivion

 Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...