Now the terrain class is basicly ready to be put in action. Not tested :)
authorsaiam
Sun, 30 Nov 2008 15:24:33 +0000
changeset 149 ce4d8f12373a
parent 148 d6f2b9912449
child 150 5e032b540af3
Now the terrain class is basicly ready to be put in action. Not tested :)
src/proto2/Terrain.cc
src/proto2/Terrain.hh
--- a/src/proto2/Terrain.cc	Sun Nov 30 15:15:17 2008 +0000
+++ b/src/proto2/Terrain.cc	Sun Nov 30 15:24:33 2008 +0000
@@ -123,7 +123,17 @@
     }
 }
 
+Vector Terrain::getNormal(Vector point) const {
+    Vector p = getPixelLocation(point);
 
+    Vector normal(0,0);
+    for (int i = 0; i < 8; i++) {
+        if (getType(p.x+DIRECTIONS[i].x, p.y+DIRECTIONS[i].y) == EMPTY) {
+            normal += DIRECTIONS[i];
+        }
+    }
+    return normal;
+}
 
 // TODO: This could better :)
 // TODO: And this need some cleaning :)
--- a/src/proto2/Terrain.hh	Sun Nov 30 15:15:17 2008 +0000
+++ b/src/proto2/Terrain.hh	Sun Nov 30 15:24:33 2008 +0000
@@ -8,6 +8,17 @@
 
 enum TerrainType {EMPTY, DIRT, ROCK};
 
+const Vector DIRECTIONS[] = {
+    Vector(-1,-1),
+    Vector(-1,0),
+    Vector(-1,1),
+    Vector(0,-1),
+    Vector(0,1),
+    Vector(1,-1),
+    Vector(1,0),
+    Vector(1,1)
+};
+
 /**
  * Terrain class. Represents game terrain and contains member
  * functions to manipulate terrain and get info about it.
@@ -109,16 +120,9 @@
      * Return normal for the given point.
      *
      * @param point Point for which the normal is calculated.
-     * @param n Accuracy in pixels
+     * @return Normal vector ((0,0) if there's no terrain)
      */
-    Vector getNormal(Vector prevPoint, Vector hitPoint, int n = 1) const;
-    /**
-     * Return a normal for the given point.
-     *
-     * @param point Point for which the normal is calculated.
-     * @param a Accuracy in scaled units
-     */
-    Vector getNormal(Vector prevPoint, Vector hitPoint, float a) const;
+    Vector getNormal(Vector point) const;
 
     /**
      * Generate random terrain.