From: Mikko Rasa Date: Fri, 22 Nov 2013 11:05:30 +0000 (+0200) Subject: Improve tile axis calculation X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ab0e6fa3442459d0a299ef90618ab6886d075057;p=r2c2.git Improve tile axis calculation --- diff --git a/source/libr2c2/terrain.cpp b/source/libr2c2/terrain.cpp index 072a6e5..502a8c7 100644 --- a/source/libr2c2/terrain.cpp +++ b/source/libr2c2/terrain.cpp @@ -189,7 +189,12 @@ Terrain::Tile::Tile(): void Terrain::Tile::set_node_elevation(unsigned i, float e) { nodes[i].elevation = e; - secondary_axis = ((nodes[1].elevation+nodes[2].elevation) < (nodes[0].elevation+nodes[3].elevation)); + update_axis(); +} + +void Terrain::Tile::update_axis() +{ + secondary_axis = (abs(nodes[1].elevation-nodes[2].elevation) < abs(nodes[0].elevation-nodes[3].elevation)); } void Terrain::Tile::save(list &st) const @@ -262,6 +267,7 @@ void Terrain::Loader::tile() Tile &t = obj.tiles[next_tile]; Tile::Loader ldr(obj, t); load_sub_with(ldr); + t.update_axis(); unsigned x = next_tile%obj.width; unsigned y = next_tile/obj.width; ++next_tile; diff --git a/source/libr2c2/terrain.h b/source/libr2c2/terrain.h index fb3328e..01571cc 100644 --- a/source/libr2c2/terrain.h +++ b/source/libr2c2/terrain.h @@ -70,6 +70,7 @@ public: Tile(); void set_node_elevation(unsigned, float); + void update_axis(); void save(std::list &) const; };