#ifndef TERRAIN_H
#define TERRAIN_H

#include "vector.h"
#include "triangle.h"
#include "constants.h"
#include <windows.h>



/* The Terrain class implements a rectangular grid of triangles to simulate a bumpy
 * terrain. See the generate() function for how the grid is created. Note that the 
 * draw() and setColor() functions serve merely to call the same functions in the
 * Triangles that the Terrain class owns.
 *
 * The member value Triangle* grid is a linear array of the triangles.
 */

class Terrain
{
public:
	Terrain();
	~Terrain();
	void draw();
	void setColor(Vector color);
	void setUpTexture(void);
	unsigned char* LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader);
	Triangle** getGrid();
	double* getMap();
	int getGridSize();

private:
	void smooth();
	void generate();
	double gridAvg(int i, int j);
	int minimum(int a, int b);
	int maximum(int a, int b);

	unsigned int hTexture;

	Triangle* grid[(TERRAIN_COLS - 1) * (TERRAIN_ROWS - 1) * 2];
	double heightmap[TERRAIN_ROWS * TERRAIN_COLS];
	int rows, cols;
	int gridSize;
};
#endif // TERRAIN_H