Updated getNormal
authorsaiam
Sun, 30 Nov 2008 19:20:11 +0000
changeset 152 89e2d078817c
parent 151 9fc900fbfa79
child 153 73402d5b778e
Updated getNormal
src/proto2/Terrain.cc
src/proto2/Terrain.hh
--- a/src/proto2/Terrain.cc	Sun Nov 30 17:22:57 2008 +0000
+++ b/src/proto2/Terrain.cc	Sun Nov 30 19:20:11 2008 +0000
@@ -135,11 +135,23 @@
             normal += DIRECTIONS[i];
         }
     }
-    if (normal.length() == 0) normal = prevPoint - point;
+
+    // Special cases
+    Vector tmp = direction(direction(prevPoint-point) + direction(normal));
+    if (normal.length() == 0 || getType(tmp.x, tmp.y) != EMPTY) 
+        normal = prevPoint - point; // Direct hit
+
+    if (getType(tmp.x,tmp.y) != EMPTY) 
     Engine::log(DEBUG, "Terrain.getNormal") << "Normal: " << normal;
     return normal;
 }
 
+Vector direction(const Vector &v) {
+    Vector tmp(v);
+    tmp /= tmp.length();
+    return Vector(round(tmp.x), round(tmp.y));
+}
+
 // TODO: This could better :)
 // TODO: And this need some cleaning :)
 void Terrain::generateTerrain(int seed) {
@@ -196,3 +208,4 @@
 std::vector<std::vector<TerrainType> > Terrain::getTerrain() const {
     return terrain;
 }
+
--- a/src/proto2/Terrain.hh	Sun Nov 30 17:22:57 2008 +0000
+++ b/src/proto2/Terrain.hh	Sun Nov 30 19:20:11 2008 +0000
@@ -162,4 +162,6 @@
     std::vector<std::vector<TerrainType> > getTerrain() const;
 };
 
+Vector direction(const Vector &v);
+
 #endif