# HG changeset patch # User saiam # Date 1228058673 0 # Node ID ce4d8f12373a908dc6025b1f753226e7ff9fab8c # Parent d6f2b9912449cc3b04c356fe60e54e88ecf448bb Now the terrain class is basicly ready to be put in action. Not tested :) diff -r d6f2b9912449 -r ce4d8f12373a src/proto2/Terrain.cc --- 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 :) diff -r d6f2b9912449 -r ce4d8f12373a src/proto2/Terrain.hh --- 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.