From: Mikko Rasa Date: Thu, 21 Nov 2013 23:33:30 +0000 (+0200) Subject: Automatically adjust the secondary_axis flag when elevations are changed X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=fa5708850ec8b4d7d9795501d1bba7b83aa5a30b;p=r2c2.git Automatically adjust the secondary_axis flag when elevations are changed --- diff --git a/source/libr2c2/terrain.cpp b/source/libr2c2/terrain.cpp index 5a31774..072a6e5 100644 --- a/source/libr2c2/terrain.cpp +++ b/source/libr2c2/terrain.cpp @@ -97,7 +97,7 @@ void Terrain::set_node_elevation(const NodeCoordinates &c, float elev, bool join Tile &tile = tiles[x+y*width]; if(tile.nodes[i].elevation==ref) { - tile.nodes[i].elevation = elev; + tile.set_node_elevation(i, elev); signal_tile_changed.emit(x, y); } } @@ -105,7 +105,7 @@ void Terrain::set_node_elevation(const NodeCoordinates &c, float elev, bool join } else { - tiles[c.x+c.y*width].nodes[c.i].elevation = elev; + tiles[c.x+c.y*width].set_node_elevation(c.i, elev); signal_tile_changed.emit(c.x, c.y); } } @@ -186,6 +186,12 @@ Terrain::Tile::Tile(): secondary_axis(false) { } +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)); +} + void Terrain::Tile::save(list &st) const { bool flat = true; diff --git a/source/libr2c2/terrain.h b/source/libr2c2/terrain.h index 837119e..fb3328e 100644 --- a/source/libr2c2/terrain.h +++ b/source/libr2c2/terrain.h @@ -69,6 +69,7 @@ public: Tile(); + void set_node_elevation(unsigned, float); void save(std::list &) const; };