Index: branches/height_map/src/lib/graphics/importer/height_map.cc
===================================================================
--- branches/height_map/src/lib/graphics/importer/height_map.cc	(revision 6248)
+++ branches/height_map/src/lib/graphics/importer/height_map.cc	(revision 6249)
@@ -21,5 +21,4 @@
 #include "state.h"
 #include "resource_manager.h"
-
 #include "debug.h"
 
@@ -88,5 +87,5 @@
 }
 
-HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) 
+HeightMap::HeightMap(const char* height_map_name = NULL, const char* colour_map_name = NULL) : VertexArrayModel()
 {
 this->setClassID(CL_HEIGHT_MAP, "HeightMap");
@@ -187,39 +186,8 @@
 {
 
-}
-
-
-void HeightMap::draw() 
-{
-
 this->camera = State::getCamera();
 this->camCoords = this->camera->getAbsCoor();
 float x = this->camCoords.x + 300;
 float y = this->camCoords.z  + 100;
-
-// Draw a red rectangle to test getHeight
-
-red_mat->select();
-glBegin(GL_TRIANGLE_STRIP);
-glNormal3f(0,1,0);
-glTexCoord2d(1.0,0.0);
- glVertex3f(x-10,getHeight(x-10,y+10)+5.0f	 ,y+10); // Top Left
- 
-
-glNormal3f(0,1,0);
-glTexCoord2d(1.0,1.0);
- glVertex3f(x+10,getHeight(x+10,y+10)+5.0f ,y+10); // Top Left
- 
-
-glNormal3f(0,1,0);
-glTexCoord2d(0.0,0.0);
- glVertex3f(x-10,getHeight(x-10,y-10)+5.0f ,y-10); // Top Left
- 
-
-glNormal3f(0,1,0);
-glTexCoord2d(0.0,1.0);
- glVertex3f(x+10,getHeight(x+10,y-10)+5.0f ,y-10); // Top Left
- 
-glEnd();
 
 tmp_mat->select();
@@ -232,12 +200,148 @@
  float old_b = 0.0f;
  heights  = (unsigned char*) heightMap->pixels;
-
  bool colourChanged = true;
  
+ 
+ /*
+ if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
+	{}
+	SDL_LockSurface(heightMap);
+	
+	
+		
+	for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
+	{
+		
+		tmp_mat->select();
+
+
+		
+		int j = 0;
+	
+
+	    for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
+	    {
+	    	if(true)
+		{
+		float r = (float)colours[3*j+2  + 3*i*(heightMap->w )];
+		float g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
+		float b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
+		colourChanged = old_r != r || old_g != g || old_b != b;
+		old_r = r;
+		old_g = g;
+		old_b = b;
+		if(colourChanged)
+		{
+		tmp_mat->setAmbient(r/255.0,g/255.0,b/255.0);
+		tmp_mat->setDiffuse(r/255.0,g/255.0,b/255.0);
+		tmp_mat->select();	
+		}
+		}
+		
+		
+		height = heights[j+sampleRate + i*(heightMap->w )];
+		this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x);
+		this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
+		
+ 		this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right		
+				
+		
+		
+	    }
+		
+			
+			
+
+			
+			
+	
+
+		
+		}
+		
+	   
+	
+	SDL_UnlockSurface(heightMap);
+	
+	
+	int cnt = 0;
+	for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
+	{
+
+	    for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
+	    {
+	    	
+	    	this->addIndice(cnt);	
+		cnt ++;
+	    }
+		if(i%2 == 1)
+		{
+	   	this->newStripe();
+		}
+	}	
+	
+	
+	
+	
+		     */
+	
+	this->planeModel();
+
+	this->finalize();
+
+
+}
+
+/*
+void HeightMap::draw() 
+{
+
+this->camera = State::getCamera();
+this->camCoords = this->camera->getAbsCoor();
+float x = this->camCoords.x + 300;
+float y = this->camCoords.z  + 100;
+
+// Draw a red rectangle to test getHeight
+
+red_mat->select();
+glBegin(GL_TRIANGLE_STRIP);
+glNormal3f(0,1,0);
+glTexCoord2d(1.0,0.0);
+ glVertex3f(x-10,getHeight(x-10,y+10)+5.0f	 ,y+10); // Top Left
+ 
+
+glNormal3f(0,1,0);
+glTexCoord2d(1.0,1.0);
+ glVertex3f(x+10,getHeight(x+10,y+10)+5.0f ,y+10); // Top Left
+ 
+
+glNormal3f(0,1,0);
+glTexCoord2d(0.0,0.0);
+ glVertex3f(x-10,getHeight(x-10,y-10)+5.0f ,y-10); // Top Left
+ 
+
+glNormal3f(0,1,0);
+glTexCoord2d(0.0,1.0);
+ glVertex3f(x+10,getHeight(x+10,y-10)+5.0f ,y-10); // Top Left
+ 
+glEnd();
+
+tmp_mat->select();
+
+unsigned char height = 0; 
+ int offset = 0;
+ int g = 0;
+ float old_r = 0.0f;
+ float old_g = 0.0f;
+ float old_b = 0.0f;
+ heights  = (unsigned char*) heightMap->pixels;
+
+ bool colourChanged = true;
+ 
   if(heightMap != NULL && heightMap->format->BitsPerPixel == 8 )
 	{
 	SDL_LockSurface(heightMap);
 
-		
+		   glBegin(GL_TRIANGLE_STRIP);	
 	for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
 	{
@@ -245,5 +349,5 @@
 
 
-		   glBegin(GL_TRIANGLE_STRIP);	
+		
 		int j = 0;
 	
@@ -256,7 +360,7 @@
  		glNormal3f(normalVectorField[i+2][j].y,normalVectorField[i+2][j].z,normalVectorField[i+2][j].x);
  		glVertex3f(20*(heightMap->h -(i+2))-1000,(double)((double)(height)/1-300),20*(j)-1000); // Bottom Left
-*/
-		
-
+
+*/		
+/*
 	    for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
 	    {
@@ -277,11 +381,11 @@
 		}
 		}
-		
-		if(true/*(abs(-scaleX*i-x+5000) > 1100 || abs(scaleZ*j-y-2000)  > 1100 )*/){ //subdivide??
-		
+		*/
+		//if(true/*(abs(-scaleX*i-x+5000) > 1100 || abs(scaleZ*j-y-2000)  > 1100 )*/){ //subdivide??
+		/*
 		height = heights[j+sampleRate + i*(heightMap->w )];
 		glNormal3f(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+2].x);
 		glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
-		///glTexCoord2f(1.0,1.0);
+		
  		glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right		
 				
@@ -292,20 +396,4 @@
  		glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Bottom Right
  
-	
-
-	/*
-				height = heights[j+2 + (i+2)*(heightMap->w )];
- 		glNormal3f(normalVectorField[i+2][j+2].y,normalVectorField[i+2][j+2].z,normalVectorField[i+2][j+2].x);
- 		glVertex3f(20*(heightMap->h -(i+2)),(double)((double)(height)/1-300),20*(j+2)); // Bottom Right
-
-
-		             height = heights[j + i*(heightMap->w )];
-		glNormal3f(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
- 		glVertex3f(20*(heightMap->h -(i)),(double)((double)(height)/1-300),20*(j)); // Top Left
-
-	*/
-		g=j;
-
-
 		}
 		else
@@ -335,51 +423,40 @@
 			glEnd();
 			
-			/*glBegin(GL_TRIANGLE_STRIP);
-
-		height = heights[j+sampleRate + i*(heightMap->w )];
-		glNormal3f(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x);
- 		glVertex3f(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right		
-		
-
-		height = heights[j+sampleRate + (i+sampleRate)*(heightMap->w )];
+			
+
+			
+			
+			//subdivide
+		}
+
+		
+		}
+		j =  heightMap->w -sampleRate;
+	     	
+		
  		glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x);
- 		glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Bottom Right
- 		*/	
-
-			
-			
-			//subdivide
-		}
-
-	
-
-	     }	
-		glEnd();	
+		//glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0);
+		//glTexCoord2f(0.0,0.0);
+		glTexCoord2f(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
+		glVertex3f(scaleX*(heightMap->h -i),(double)((double)-1000.0),scaleZ*(j+sampleRate)); // Top Right
+		
+		glNormal3f(normalVectorField[i+sampleRate][j+sampleRate].y,normalVectorField[i+sampleRate][j+sampleRate].z,normalVectorField[i+sampleRate][j+sampleRate].x);
+				glTexCoord2f(((j/sampleRate)%4)/4.0,1/4.0+((i/sampleRate)%4)/4.0);
+	
+ 		glVertex3f(scaleX*(heightMap->h -(i+sampleRate)),(double)-1000.0,scaleZ*(j+sampleRate)); // Bottom Right
+
+	     	
+		
+				
+	     
+		//glEnd();	
 	   
 	}
 	SDL_UnlockSurface(heightMap);
-	
-}
-
-
-/*	int c = (heightMap->w)/4 ; // One line
-	for(int i = 0; i < (heightMap->w)/4  -4  ; i ++)
-	{
-	    for(int j = 0; j < (heightMap->h)/4 - 4; j++)
-	    {
-		
-		this->addFace (3, VERTEX_ONLY,j + (i+1)*c,j+1+i*c , j + i*c );
-		this->addFace (3, VERTEX_ONLY,j + (i+1)*c,j + (i+1)*c +1 ,j+i*c +1 );				
-			 
-		
-	    }
-				
-			
-				
-	}
-
+	glEnd();
+}
+
+}
 */
-}
-
 void HeightMap::generateNormalVectorField()
 {
Index: branches/height_map/src/lib/graphics/importer/height_map.h
===================================================================
--- branches/height_map/src/lib/graphics/importer/height_map.h	(revision 6248)
+++ branches/height_map/src/lib/graphics/importer/height_map.h	(revision 6249)
@@ -14,7 +14,7 @@
 
 
-#include "model.h"
+#include "vertex_array_model.h"
 
-#define sampleRate 2
+#define sampleRate 4
 
 class SDL_Surface;
@@ -24,8 +24,8 @@
 class Texture;
 
-class HeightMap : public Model
+class HeightMap : public VertexArrayModel
 {
 public:
-void draw();
+
 void load();
 void load(int Mode);
Index: branches/height_map/src/lib/graphics/importer/vertex_array_model.cc
===================================================================
--- branches/height_map/src/lib/graphics/importer/vertex_array_model.cc	(revision 6248)
+++ branches/height_map/src/lib/graphics/importer/vertex_array_model.cc	(revision 6249)
@@ -71,5 +71,5 @@
 		      GL_TEXTURE_COORD_ARRAY |
 		      GL_NORMAL_ARRAY);
-  //  glEnableClientState(GL_INDEX_ARRAY);
+  glEnableClientState(GL_INDEX_ARRAY);
 
   glVertexPointer(3, GL_FLOAT, 0, this->vertices.getArray());
@@ -77,5 +77,6 @@
   glTexCoordPointer(2, GL_FLOAT, 0, this->texCoords.getArray());  
 
-  for (GLuint i = 1; i < this->stripes.size(); ++i)
+      glDrawElements(GL_TRIANGLE_STRIP, this->indices.getCount(), GL_UNSIGNED_BYTE, this->indices.getArray());
+/*  for (GLuint i = 1; i < this->stripes.size(); ++i)
     {
       glDrawRangeElements(GL_TRIANGLE_STRIP,
@@ -85,5 +86,5 @@
 			  GL_UNSIGNED_BYTE,
 			  this->indices.getArray());
-    }
+    }*/
 }
 
@@ -194,5 +195,5 @@
       for (j = 0; j < 20; j++)
 	{
-	  this->addVertex(i* 50, .5, (j)*50);
+	  this->addVertex((float)i, .5, (float)(j));
 	  this->addNormal(0, 1, 0);
 	  this->addTexCoor((float)i/20.0, (float)j/20.0);
Index: branches/height_map/src/world_entities/terrain.cc
===================================================================
--- branches/height_map/src/world_entities/terrain.cc	(revision 6248)
+++ branches/height_map/src/world_entities/terrain.cc	(revision 6249)
@@ -23,5 +23,5 @@
 
 #include "resource_manager.h"
-#include "model.h"
+#include "vertex_array_model.h"
 #include "material.h"
 #include "height_map.h"
Index: branches/height_map/src/world_entities/terrain.h
===================================================================
--- branches/height_map/src/world_entities/terrain.h	(revision 6248)
+++ branches/height_map/src/world_entities/terrain.h	(revision 6249)
@@ -16,5 +16,5 @@
 class SpatialSeparation;
 class Material;
-
+class VertexArrayModel;
 //! A simple method to call a desired debug world.
 enum DebugTerrain {TERRAIN_DAVE, TERRAIN_BENSCH};
@@ -44,5 +44,5 @@
  private:
    Model*              vegetation;
-   Model*	       model;
+   VertexArrayModel*	       model;
    Material*           tmp_mat;
    int                 objectList;
