--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/proto2/Terrain.hh Sat Nov 29 23:43:47 2008 +0000
@@ -0,0 +1,157 @@
+#ifndef TERRAIN_HH
+#define TERRAIN_HH
+
+#include <vector>
+
+#include "Vector.hh"
+#include "Config.hh"
+
+enum TerrainType {EMPTY, DIRT, ROCK};
+
+/**
+ * Terrain class. Represents game terrain and contains member
+ * functions to manipulate terrain and get info about it.
+ *
+ * Terrain resolution is a constant that is defined in
+ * configuration. Terrain has a scale (i.e. the width and height in
+ * "real" units. Scaling is needed because physics simulation uses
+ * "real" units. The idea is that this class is used with "real" units
+ * and it uses pixelcoordinates internally.
+ */
+class Terrain {
+private:
+ const Vector scale;
+ std::vector<std::vector<TerrainType> > terrain;
+
+ // Terrain graphic
+ CL_PixelBuffer pixbuf;
+
+ /**
+ * Generates pixelbuffer from terrain. Should be used only on
+ * constructors because this is expected to be slow.
+ */
+ void generatePixelBuffer();
+
+ /**
+ * Get pixel location of a point that is in "real" units.
+ *
+ * @param point Point in "real" units
+ * @return Int vector
+ */
+ Vector getPixelLocation(Vector point);
+
+public:
+ /**
+ * Constructor.
+ *
+ * @param scale The "real" width and height of the terrain.
+ */
+ Terrain(const Vector &scale);
+ /**
+ * Constructor.
+ *
+ * @param scale The "real" width and height of the terrain.
+ * @param seed Random number generator seed used to create the
+ * terrain.
+ */
+ Terrain(const Vector &scale, const int &seed);
+ /**
+ * Copy constructor.
+ *
+ * @param t Terrain to be copied.
+ */
+ Terrain(const Terrain &t);
+ /**
+ * Destructor
+ */
+ ~Terrain();
+
+ /**
+ * Check if given point has some terrain.
+ *
+ * @param point Point that is in scaled units.
+ */
+ bool collides(const Vector &point) const;
+ /**
+ * Check if given line collides with terrain.
+ *
+ * @param begin Line begin point in scaled units.
+ * @param end Line end point in scaled units.
+ */
+ bool collides(const Vector &begin, const Vector &end) const;
+
+ /**
+ * Remove a circular area from terrain.
+ *
+ * @param pos Circle center
+ * @param r Circle radius
+ */
+ void removeGround(Vector pos, float r);
+
+ /**
+ * Get tangent for the given point.
+ *
+ * @param point Point where the tangent is calculated
+ * @param n Accuracy in pixels
+ */
+ Vector getTangent(Vector point, int n = 1) const;
+ /**
+ * Get tangent for the given point.
+ *
+ * @param point Point where the tangent is calculated
+ * @param a Accuracy in scaled units.
+ */
+ Vector getTangent(Vector point, float a) const;
+
+ /**
+ * Return normal for the given point.
+ *
+ * @param point Point for which the normal is calculated.
+ * @param n Accuracy in pixels
+ */
+ Vector getNormal(Vector point, 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 point, float a) const;
+
+ /**
+ * Generate random terrain.
+ *
+ * @param seed Seed for the randomnumber generator.
+ */
+ void generateTerrain(int seed);
+
+ /**
+ * Draw the terrain for given graphicscontext.
+ *
+ * @param gc CL_GraphicContext
+ */
+ void draw(CL_GraphicContext &gc) const;
+ /**
+ * Draw part of the terrain for given graphiscontext.
+ *
+ * @param gc CL_GraphicContext
+ * @param center Center of the rectangle drawn.
+ * @param dimension Dimensions of the rectangle.
+ */
+ void draw(CL_GraphicContext &gc, Vector center, Vector dimensions);
+
+ /**
+ * Set terrain.
+ *
+ * @param terrain Terrain.
+ */
+ void setTerrain(const std::vector<std::vector<TerrainType> > &terrain);
+ /**
+ * Get terrain.
+ *
+ * @return Terrain.
+ */
+ std::vector<std::vector<TerrainType> > getTerrain() const;
+};
+
+#endif