|
|
|
@ -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();
|
|
|
|
|