// Author : Chris Tolley
// Date   : 5/18/2004
// HeightBasedTexture.h contains the class declaration for a texture that
// is generated based on a height map

#if !defined(AFX_HEIGHTBASEDTEXTURE_H__8ED7847D_341A_488F_A8E1_526BD492326F__INCLUDED_)
#define AFX_HEIGHTBASEDTEXTURE_H__8ED7847D_341A_488F_A8E1_526BD492326F__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <vector>
using std::vector;

#include "texture.h"
#include "HeightData.h"

// A struct to hold the color values and their height value
struct colorSet
{
	// The texture to use at this height value
	texture text_;
	
	// The height at which this color should be 100 percent
	float height_;
};// End colorSet struct



class HeightBasedTexture  
{
public:
	// Constructor.  numPixels is multipled by itself and then 3
	// to get the actual size of the texture.  The texture is
	// numPixels x numPixels.  numPixels must be a power of 2
	HeightBasedTexture( int numPixels );

	// Destructor
	virtual ~HeightBasedTexture();

	// Sets up the texture based on the data from the height map
	void initializeTexture( vector< colorSet > colors, HeightData& hData );

	// Points r,g,b to the RGB values of the (x,z)th pixel
	void getPixel( int x, int z, unsigned char& r, unsigned char& g,
					unsigned char& b );

	// Sets the (x,z)th pixel color values to r,g,b
	void setPixel( int x, int z, unsigned char r, unsigned char g,
					unsigned char b );

	// Selects this texture as the current texture for OpenGL to use
	void select();

	// Deselects this texture so OpenGL no longer uses it.
	void deselect();
private:
	// Calculates h2's presence relative to h1.  numColors is the number
	// of color sets there are
	float calcPresence( float h1, float h2, int numColors ) const;

	// The array of texture data
	vector< unsigned char > m_tData;

	// The number of pixels for this texture.  Must be a power of 2.
	// The actaul dimensions of the texture are m_iNumPixels x m_iNumPixels
	int m_iNumPixels;

	// The id of this texture.  OpenGL uses this and is set
	// by OpenGL in the glGenTexture function call.
	unsigned int id_;

	// The number of rows and colums
	int m_iRows;
	int m_iCols;
};

#endif // !defined(AFX_HEIGHTBASEDTEXTURE_H__8ED7847D_341A_488F_A8E1_526BD492326F__INCLUDED_)
