mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 09:36:43 +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
|
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 =
|
const MWWorld::ESMStore &esmStore =
|
||||||
MWBase::Environment::get().getWorld()->getStore();
|
MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
@ -39,8 +39,6 @@ namespace MWRender
|
||||||
// since grid coords are at cell origin, we need to add 1 cell
|
// since grid coords are at cell origin, we need to add 1 cell
|
||||||
maxX += 1;
|
maxX += 1;
|
||||||
maxY += 1;
|
maxY += 1;
|
||||||
|
|
||||||
return Ogre::AxisAlignedBox(minX, minY, 0, maxX, maxY, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ESM::Land* TerrainStorage::getLand(int cellX, int cellY)
|
ESM::Land* TerrainStorage::getLand(int cellX, int cellY)
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace MWRender
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/// Get bounds of the whole terrain in cell units
|
/// 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.
|
/// 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.
|
/// @note Should only be called for chunks <= 1 cell, i.e. leafs of the quad tree.
|
||||||
|
|
|
@ -24,7 +24,7 @@ namespace Terrain
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Get bounds of the whole terrain in cell units
|
/// 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.
|
/// 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.
|
/// @note Should only be called for chunks <= 1 cell, i.e. leafs of the quad tree.
|
||||||
|
|
|
@ -62,6 +62,10 @@ namespace Terrain
|
||||||
, mShaders(shaders)
|
, mShaders(shaders)
|
||||||
, mVisible(true)
|
, mVisible(true)
|
||||||
, mLoadingListener(loadingListener)
|
, mLoadingListener(loadingListener)
|
||||||
|
, mMaxX(0)
|
||||||
|
, mMinX(0)
|
||||||
|
, mMaxY(0)
|
||||||
|
, mMinY(0)
|
||||||
{
|
{
|
||||||
loadingListener->setLabel("Creating terrain");
|
loadingListener->setLabel("Creating terrain");
|
||||||
loadingListener->indicateProgress();
|
loadingListener->indicateProgress();
|
||||||
|
@ -76,20 +80,21 @@ namespace Terrain
|
||||||
mCompositeMapRenderTarget->setAutoUpdated(false);
|
mCompositeMapRenderTarget->setAutoUpdated(false);
|
||||||
mCompositeMapRenderTarget->addViewport(compositeMapCam);
|
mCompositeMapRenderTarget->addViewport(compositeMapCam);
|
||||||
|
|
||||||
mBounds = storage->getBounds();
|
storage->getBounds(mMinX, mMaxX, mMinY, mMaxY);
|
||||||
|
|
||||||
int origSizeX = mBounds.getSize().x;
|
int origSizeX = mMaxX-mMinX;
|
||||||
int origSizeY = mBounds.getSize().y;
|
int origSizeY = mMaxY-mMinY;
|
||||||
|
|
||||||
// Dividing a quad tree only works well for powers of two, so round up to the nearest one
|
// 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));
|
int size = nextPowerOfTwo(std::max(origSizeX, origSizeY));
|
||||||
|
|
||||||
// Adjust the center according to the new size
|
// 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();
|
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);
|
buildQuadTree(mRootNode);
|
||||||
loadingListener->indicateProgress();
|
loadingListener->indicateProgress();
|
||||||
mRootNode->initAabb();
|
mRootNode->initAabb();
|
||||||
|
@ -122,10 +127,10 @@ namespace Terrain
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node->getCenter().x - halfSize > mBounds.getMaximum().x
|
if (node->getCenter().x - halfSize > mMaxX
|
||||||
|| node->getCenter().x + halfSize < mBounds.getMinimum().x
|
|| node->getCenter().x + halfSize < mMinX
|
||||||
|| node->getCenter().y - halfSize > mBounds.getMaximum().y
|
|| node->getCenter().y - halfSize > mMaxY
|
||||||
|| node->getCenter().y + halfSize < mBounds.getMinimum().y )
|
|| node->getCenter().y + halfSize < mMinY )
|
||||||
// Out of bounds of the actual terrain - this will happen because
|
// Out of bounds of the actual terrain - this will happen because
|
||||||
// we rounded the size up to the next power of two
|
// 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)
|
Ogre::AxisAlignedBox World::getWorldBoundingBox (const Ogre::Vector2& center)
|
||||||
{
|
{
|
||||||
if (center.x > mBounds.getMaximum().x
|
if (center.x > mMaxX
|
||||||
|| center.x < mBounds.getMinimum().x
|
|| center.x < mMinX
|
||||||
|| center.y > mBounds.getMaximum().y
|
|| center.y > mMaxY
|
||||||
|| center.y < mBounds.getMinimum().y)
|
|| center.y < mMinY)
|
||||||
return Ogre::AxisAlignedBox::BOX_NULL;
|
return Ogre::AxisAlignedBox::BOX_NULL;
|
||||||
QuadTreeNode* node = findNode(center, mRootNode);
|
QuadTreeNode* node = findNode(center, mRootNode);
|
||||||
Ogre::AxisAlignedBox box = node->getBoundingBox();
|
Ogre::AxisAlignedBox box = node->getBoundingBox();
|
||||||
|
|
|
@ -105,7 +105,7 @@ namespace Terrain
|
||||||
Ogre::SceneManager* mCompositeMapSceneMgr;
|
Ogre::SceneManager* mCompositeMapSceneMgr;
|
||||||
|
|
||||||
/// Bounds in cell units
|
/// Bounds in cell units
|
||||||
Ogre::AxisAlignedBox mBounds;
|
float mMinX, mMaxX, mMinY, mMaxY;
|
||||||
|
|
||||||
/// Minimum size of a terrain batch along one side (in cell units)
|
/// Minimum size of a terrain batch along one side (in cell units)
|
||||||
float mMinBatchSize;
|
float mMinBatchSize;
|
||||||
|
|
Loading…
Reference in a new issue