2
// C++ Implementation: TerrainInfo
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2006
9
// This program is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU General Public License as published by
11
// the Free Software Foundation; either version 2 of the License, or
12
// (at your option) any later version.
14
// This program is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
// GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public License
20
// along with this program; if not, write to the Free Software
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
27
#include "TerrainInfo.h"
28
#include <Mercator/BasePoint.h>
34
TerrainInfo::TerrainInfo()
35
: mXminBasePoint(0), mXmaxBasePoint(0), mYminBasePoint(0), mYmaxBasePoint(0),
36
mXminBasePointAdjusted(0), mXmaxBasePointAdjusted(0), mYminBasePointAdjusted(0), mYmaxBasePointAdjusted(0)
42
void TerrainInfo::setBasePoint(const WFMath::Point<2>& position, const Mercator::BasePoint& basepoint)
44
mXminBasePoint = std::min<WFMath::CoordType>(position.x(), mXminBasePoint);
45
mXmaxBasePoint = std::max<WFMath::CoordType>(position.x(), mXmaxBasePoint);
46
mYminBasePoint = std::min<WFMath::CoordType>(position.y(), mYminBasePoint);
47
mYmaxBasePoint = std::max<WFMath::CoordType>(position.y(), mYmaxBasePoint);
49
adjustBasePointPositionDown(mXminBasePointAdjusted, mXminBasePoint);
50
adjustBasePointPositionUp(mXmaxBasePointAdjusted, mXmaxBasePoint);
51
adjustBasePointPositionDown(mYminBasePointAdjusted, mYminBasePoint);
52
adjustBasePointPositionUp(mYmaxBasePointAdjusted, mYmaxBasePoint);
57
void TerrainInfo::recalculateSize()
59
mCalculatedSize = WFMath::AxisBox<2>(WFMath::Point<2>(mXminBasePointAdjusted * 64, mYminBasePointAdjusted * 64), WFMath::Point<2>(mXmaxBasePointAdjusted * 64, mYmaxBasePointAdjusted * 64));
60
mCalculatedSegmentSize = WFMath::AxisBox<2>(WFMath::Point<2>(mXminBasePointAdjusted, mYminBasePointAdjusted ), WFMath::Point<2>(mXmaxBasePointAdjusted , mYmaxBasePointAdjusted ));
62
int mercatorSegmentsPerOgrePage = mPageIndicesSize / 64;
63
mCalculatedPageSize = WFMath::AxisBox<2>(WFMath::Point<2>(mXminBasePointAdjusted / mercatorSegmentsPerOgrePage, mYminBasePointAdjusted / mercatorSegmentsPerOgrePage), WFMath::Point<2>(mXmaxBasePointAdjusted / mercatorSegmentsPerOgrePage, mYmaxBasePointAdjusted / mercatorSegmentsPerOgrePage));
67
void TerrainInfo::adjustBasePointPositionUp(WFMath::CoordType& basePointPositionAdjusted, WFMath::CoordType newBasePointPosition)
69
int mercatorSegmentsPerOgrePage = mPageIndicesSize / 64;
70
int remainder = static_cast<int>(newBasePointPosition) % mercatorSegmentsPerOgrePage;
72
///adjust the position
73
basePointPositionAdjusted = newBasePointPosition + (mercatorSegmentsPerOgrePage - remainder);
77
void TerrainInfo::adjustBasePointPositionDown(WFMath::CoordType& basePointPositionAdjusted, WFMath::CoordType newBasePointPosition)
79
int mercatorSegmentsPerOgrePage = mPageIndicesSize / 64;
80
int remainder = std::abs(static_cast<int>(newBasePointPosition) % mercatorSegmentsPerOgrePage);
82
///adjust the position
83
basePointPositionAdjusted = newBasePointPosition - (mercatorSegmentsPerOgrePage - remainder);
87
const WFMath::AxisBox<2>& TerrainInfo::getWorldSizeInSegments() const
89
return mCalculatedSegmentSize;
93
const WFMath::AxisBox<2>& TerrainInfo::getWorldSizeInIndices() const
95
return mCalculatedSize;
98
const WFMath::AxisBox<2>& TerrainInfo::getWorldSizeInPages() const
100
return mCalculatedPageSize;
104
double TerrainInfo::getWorldSizeX() const
106
return mCalculatedSize.highCorner().x() - mCalculatedSize.lowCorner().x();
109
double TerrainInfo::getWorldSizeY() const
111
return mCalculatedSize.highCorner().y() - mCalculatedSize.lowCorner().y();
114
int TerrainInfo::getTotalNumberOfPagesX() const
116
return static_cast<int>(mCalculatedPageSize.highCorner().x() - mCalculatedPageSize.lowCorner().x());
118
int TerrainInfo::getTotalNumberOfPagesY() const
120
return static_cast<int>(mCalculatedPageSize.highCorner().y() - mCalculatedPageSize.lowCorner().y());
123
int TerrainInfo::getPageOffsetX() const
125
return static_cast<int>(-mCalculatedPageSize.lowCorner().x());
127
int TerrainInfo::getPageOffsetY() const
129
return static_cast<int>(-mCalculatedPageSize.lowCorner().y());
132
void TerrainInfo::setPageIndicesSize(int size)
134
mPageIndicesSize = size;