--- 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.