Now getNormal might work a little better
authorsaiam
Sun, 30 Nov 2008 17:22:57 +0000
changeset 151 9fc900fbfa79
parent 150 5e032b540af3
child 152 89e2d078817c
Now getNormal might work a little better
src/proto2/Physics.cc
src/proto2/Terrain.cc
src/proto2/Terrain.hh
--- a/src/proto2/Physics.cc	Sun Nov 30 17:13:16 2008 +0000
+++ b/src/proto2/Physics.cc	Sun Nov 30 17:22:57 2008 +0000
@@ -275,7 +275,7 @@
  * Computes hitten wall's normal. Calculated from 3*3 grid
  */
 Vector PhysicsWorld::getNormal (Vector hitPoint, Vector prevPoint) {
-    return terrain.getNormal(hitPoint);
+    return terrain.getNormal(hitPoint, prevPoint);
 }
 
 /**
--- a/src/proto2/Terrain.cc	Sun Nov 30 17:13:16 2008 +0000
+++ b/src/proto2/Terrain.cc	Sun Nov 30 17:22:57 2008 +0000
@@ -2,6 +2,7 @@
 #include "Engine.hh"
 
 #include <cmath>
+#include <cassert>
 #include <algorithm>
 #include <ClanLib/display.h>
 
@@ -125,7 +126,7 @@
     }
 }
 
-Vector Terrain::getNormal(Vector point) const {
+Vector Terrain::getNormal(Vector point, Vector prevPoint) const {
     Vector p = getPixelLocation(point);
 
     Vector normal(0,0);
@@ -134,6 +135,7 @@
             normal += DIRECTIONS[i];
         }
     }
+    if (normal.length() == 0) normal = prevPoint - point;
     Engine::log(DEBUG, "Terrain.getNormal") << "Normal: " << normal;
     return normal;
 }
--- a/src/proto2/Terrain.hh	Sun Nov 30 17:13:16 2008 +0000
+++ b/src/proto2/Terrain.hh	Sun Nov 30 17:22:57 2008 +0000
@@ -124,7 +124,7 @@
      * @param point Point for which the normal is calculated.
      * @return Normal vector ((0,0) if there's no terrain)
      */
-    Vector getNormal(Vector point) const;
+    Vector getNormal(Vector point, Vector prevPoint) const;
 
     /**
      * Generate random terrain.