Add and use TileIndex positionRelativeParent

This commit is contained in:
Erik Broberg
2016-11-28 18:19:04 +01:00
parent e6d758a418
commit f7957255f8
3 changed files with 13 additions and 12 deletions
+6
View File
@@ -79,6 +79,12 @@ namespace globebrowsing {
return *this;
}
glm::vec2 TileIndex::positionRelativeParent() const{
// In OpenGL, positive y direction is up
return glm::vec2(isEastChild() ? 0.5 : 0, isNorthChild() ? 0.5 : 0);
}
/**
Gets the tile at a specified offset from this tile.
Accepts delta indices ranging from [-2^level, Infinity[
+6 -4
View File
@@ -72,24 +72,26 @@ struct TileIndex {
TileIndex& operator-=(unsigned int levels);
bool isWestChild() const {
inline bool isWestChild() const {
return x % 2 == 0;
}
bool isEastChild() const {
inline bool isEastChild() const {
return x % 2 == 1;
}
bool isNorthChild() const {
inline bool isNorthChild() const {
return y % 2 == 0;
}
bool isSouthChild() const {
inline bool isSouthChild() const {
return y % 2 == 1;
}
TileIndex child(Quad q) const;
glm::vec2 positionRelativeParent() const;
std::string toString() const;
+1 -8
View File
@@ -80,14 +80,7 @@ namespace globebrowsing {
uv.uvOffset *= 0.5;
uv.uvScale *= 0.5;
if (tileIndex.isEastChild()) {
uv.uvOffset.x += 0.5;
}
// In OpenGL, positive y direction is up
if (tileIndex.isNorthChild()) {
uv.uvOffset.y += 0.5;
}
uv.uvOffset += tileIndex.positionRelativeParent();
--tileIndex;
}