Merge of corristo's terrain rendering and fixes so that the terrain is correctly positioned and rendered
parent
51d5c7cd59
commit
18108c02a7
@ -0,0 +1,62 @@
|
||||
#include <OgreTerrain.h>
|
||||
#include <OgreTerrainGroup.h>
|
||||
|
||||
#include "terrain.hpp"
|
||||
|
||||
#include "components/esm/loadland.hpp"
|
||||
|
||||
namespace MWRender
|
||||
{
|
||||
TerrainManager::TerrainManager(Ogre::SceneManager* mgr)
|
||||
{
|
||||
mTerrainGlobals = OGRE_NEW Ogre::TerrainGlobalOptions();
|
||||
|
||||
mTerrainGlobals->setMaxPixelError(8);
|
||||
|
||||
mTerrainGroup = OGRE_NEW Ogre::TerrainGroup(mgr,
|
||||
Ogre::Terrain::ALIGN_X_Z, ESM::Land::LAND_SIZE,
|
||||
ESM::Land::REAL_SIZE);
|
||||
|
||||
mTerrainGroup->setOrigin(Ogre::Vector3(ESM::Land::REAL_SIZE/2,
|
||||
0,
|
||||
-ESM::Land::REAL_SIZE/2));
|
||||
|
||||
Ogre::Terrain::ImportData importSettings =
|
||||
mTerrainGroup->getDefaultImportSettings();
|
||||
|
||||
importSettings.terrainSize = ESM::Land::LAND_SIZE;
|
||||
importSettings.worldSize = ESM::Land::REAL_SIZE;
|
||||
importSettings.minBatchSize = 9;
|
||||
importSettings.maxBatchSize = 33;
|
||||
|
||||
importSettings.deleteInputData = false;
|
||||
}
|
||||
|
||||
TerrainManager::~TerrainManager()
|
||||
{
|
||||
OGRE_DELETE mTerrainGroup;
|
||||
OGRE_DELETE mTerrainGlobals;
|
||||
}
|
||||
|
||||
void TerrainManager::cellAdded(MWWorld::Ptr::CellStore *store)
|
||||
{
|
||||
int x = store->cell->getGridX();
|
||||
int y = store->cell->getGridY();
|
||||
|
||||
Ogre::Terrain::ImportData terrainData;
|
||||
|
||||
terrainData.inputBias = 0;
|
||||
terrainData.inputFloat = store->land->landData->heights;
|
||||
|
||||
mTerrainGroup->defineTerrain(x, y, &terrainData);
|
||||
|
||||
mTerrainGroup->loadTerrain(x, y, true);
|
||||
}
|
||||
|
||||
void TerrainManager::cellRemoved(MWWorld::Ptr::CellStore *store)
|
||||
{
|
||||
mTerrainGroup->removeTerrain(store->cell->getGridX(),
|
||||
store->cell->getGridY());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
#ifndef _GAME_RENDER_TERRAIN_H
|
||||
#define _GAME_RENDER_TERRAIN_H
|
||||
|
||||
#include "../mwworld/ptr.hpp"
|
||||
|
||||
namespace Ogre{
|
||||
class SceneManager;
|
||||
class TerrainGroup;
|
||||
class TerrainGlobalOptions;
|
||||
}
|
||||
|
||||
namespace MWRender{
|
||||
|
||||
/**
|
||||
* Implements the Morrowind terrain using the Ogre Terrain Component
|
||||
*/
|
||||
class TerrainManager{
|
||||
public:
|
||||
TerrainManager(Ogre::SceneManager*);
|
||||
virtual ~TerrainManager();
|
||||
|
||||
void cellAdded(MWWorld::Ptr::CellStore* store);
|
||||
void cellRemoved(MWWorld::Ptr::CellStore* store);
|
||||
private:
|
||||
Ogre::TerrainGlobalOptions* mTerrainGlobals;
|
||||
Ogre::TerrainGroup* mTerrainGroup;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // _GAME_RENDER_TERRAIN_H
|
Loading…
Reference in New Issue