mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 08:15:37 +00:00
Terrain: change world bounds from AABB to 4 floats
This commit is contained in:
parent
bc376e6649
commit
1fba5d1bb9
5 changed files with 23 additions and 20 deletions
|
@ -16,9 +16,9 @@
|
|||
namespace MWRender
|
||||
{
|
||||
|
||||
Ogre::AxisAlignedBox TerrainStorage::getBounds()
|
||||
void TerrainStorage::getBounds(float& minX, float& maxX, float& minY, float& maxY)
|
||||
{
|
||||
int minX = 0, minY = 0, maxX = 0, maxY = 0;
|
||||
minX = 0, minY = 0, maxX = 0, maxY = 0;
|
||||
|
||||
const MWWorld::ESMStore &esmStore =
|
||||
MWBase::Environment::get().getWorld()->getStore();
|
||||
|
@ -39,8 +39,6 @@ namespace MWRender
|
|||
// since grid coords are at cell origin, we need to add 1 cell
|
||||
maxX += 1;
|
||||
maxY += 1;
|
||||
|
||||
return Ogre::AxisAlignedBox(minX, minY, 0, maxX, maxY, 0);
|
||||
}
|
||||
|
||||
ESM::Land* TerrainStorage::getLand(int cellX, int cellY)
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace MWRender
|
|||
public:
|
||||
|
||||
/// Get bounds of the whole terrain in cell units
|
||||
virtual Ogre::AxisAlignedBox getBounds();
|
||||
virtual void getBounds(float& minX, float& maxX, float& minY, float& maxY);
|
||||
|
||||
/// Get the minimum and maximum heights of a terrain chunk.
|
||||
/// @note Should only be called for chunks <= 1 cell, i.e. leafs of the quad tree.
|
||||
|
|
|
@ -24,7 +24,7 @@ namespace Terrain
|
|||
|
||||
public:
|
||||
/// Get bounds of the whole terrain in cell units
|
||||
virtual Ogre::AxisAlignedBox getBounds() = 0;
|
||||
virtual void getBounds(float& minX, float& maxX, float& minY, float& maxY) = 0;
|
||||
|
||||
/// Get the minimum and maximum heights of a terrain chunk.
|
||||
/// @note Should only be called for chunks <= 1 cell, i.e. leafs of the quad tree.
|
||||
|
|
|
@ -62,6 +62,10 @@ namespace Terrain
|
|||
, mShaders(shaders)
|
||||
, mVisible(true)
|
||||
, mLoadingListener(loadingListener)
|
||||
, mMaxX(0)
|
||||
, mMinX(0)
|
||||
, mMaxY(0)
|
||||
, mMinY(0)
|
||||
{
|
||||
loadingListener->setLabel("Creating terrain");
|
||||
loadingListener->indicateProgress();
|
||||
|
@ -76,20 +80,21 @@ namespace Terrain
|
|||
mCompositeMapRenderTarget->setAutoUpdated(false);
|
||||
mCompositeMapRenderTarget->addViewport(compositeMapCam);
|
||||
|
||||
mBounds = storage->getBounds();
|
||||
storage->getBounds(mMinX, mMaxX, mMinY, mMaxY);
|
||||
|
||||
int origSizeX = mBounds.getSize().x;
|
||||
int origSizeY = mBounds.getSize().y;
|
||||
int origSizeX = mMaxX-mMinX;
|
||||
int origSizeY = mMaxY-mMinY;
|
||||
|
||||
// Dividing a quad tree only works well for powers of two, so round up to the nearest one
|
||||
int size = nextPowerOfTwo(std::max(origSizeX, origSizeY));
|
||||
|
||||
// Adjust the center according to the new size
|
||||
Ogre::Vector3 center = mBounds.getCenter() + Ogre::Vector3((size-origSizeX)/2.f, (size-origSizeY)/2.f, 0);
|
||||
float centerX = (mMinX+mMaxX)/2.f + (size-origSizeX)/2.f;
|
||||
float centerY = (mMinY+mMaxY)/2.f + (size-origSizeY)/2.f;
|
||||
|
||||
mRootSceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
|
||||
|
||||
mRootNode = new QuadTreeNode(this, Root, size, Ogre::Vector2(center.x, center.y), NULL);
|
||||
mRootNode = new QuadTreeNode(this, Root, size, Ogre::Vector2(centerX, centerY), NULL);
|
||||
buildQuadTree(mRootNode);
|
||||
loadingListener->indicateProgress();
|
||||
mRootNode->initAabb();
|
||||
|
@ -122,10 +127,10 @@ namespace Terrain
|
|||
return;
|
||||
}
|
||||
|
||||
if (node->getCenter().x - halfSize > mBounds.getMaximum().x
|
||||
|| node->getCenter().x + halfSize < mBounds.getMinimum().x
|
||||
|| node->getCenter().y - halfSize > mBounds.getMaximum().y
|
||||
|| node->getCenter().y + halfSize < mBounds.getMinimum().y )
|
||||
if (node->getCenter().x - halfSize > mMaxX
|
||||
|| node->getCenter().x + halfSize < mMinX
|
||||
|| node->getCenter().y - halfSize > mMaxY
|
||||
|| node->getCenter().y + halfSize < mMinY )
|
||||
// Out of bounds of the actual terrain - this will happen because
|
||||
// we rounded the size up to the next power of two
|
||||
{
|
||||
|
@ -162,10 +167,10 @@ namespace Terrain
|
|||
|
||||
Ogre::AxisAlignedBox World::getWorldBoundingBox (const Ogre::Vector2& center)
|
||||
{
|
||||
if (center.x > mBounds.getMaximum().x
|
||||
|| center.x < mBounds.getMinimum().x
|
||||
|| center.y > mBounds.getMaximum().y
|
||||
|| center.y < mBounds.getMinimum().y)
|
||||
if (center.x > mMaxX
|
||||
|| center.x < mMinX
|
||||
|| center.y > mMaxY
|
||||
|| center.y < mMinY)
|
||||
return Ogre::AxisAlignedBox::BOX_NULL;
|
||||
QuadTreeNode* node = findNode(center, mRootNode);
|
||||
Ogre::AxisAlignedBox box = node->getBoundingBox();
|
||||
|
|
|
@ -105,7 +105,7 @@ namespace Terrain
|
|||
Ogre::SceneManager* mCompositeMapSceneMgr;
|
||||
|
||||
/// Bounds in cell units
|
||||
Ogre::AxisAlignedBox mBounds;
|
||||
float mMinX, mMaxX, mMinY, mMaxY;
|
||||
|
||||
/// Minimum size of a terrain batch along one side (in cell units)
|
||||
float mMinBatchSize;
|
||||
|
|
Loading…
Reference in a new issue