]> git.tdb.fi Git - r2c2.git/commitdiff
Improve tile axis calculation
authorMikko Rasa <tdb@tdb.fi>
Fri, 22 Nov 2013 11:05:30 +0000 (13:05 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 22 Nov 2013 11:05:30 +0000 (13:05 +0200)
source/libr2c2/terrain.cpp
source/libr2c2/terrain.h

index 072a6e5a26b322066e2818873dd6b8b026332b25..502a8c7e5a24e4b1eeba8da56ad26628245e3456 100644 (file)
@@ -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<DataFile::Statement> &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;
index fb3328e63e9d7acb93eab43e8bb08f165abcc40f..01571cc32806de9f6afb0fbfb167bf0876d828cd 100644 (file)
@@ -70,6 +70,7 @@ public:
                Tile();
 
                void set_node_elevation(unsigned, float);
+               void update_axis();
                void save(std::list<Msp::DataFile::Statement> &) const;
        };