Index: /branches/height_map/src/lib/graphics/importer/height_map.cc
===================================================================
--- /branches/height_map/src/lib/graphics/importer/height_map.cc	(revision 6328)
+++ /branches/height_map/src/lib/graphics/importer/height_map.cc	(revision 6329)
@@ -35,5 +35,5 @@
 }
 
-HeightMap::HeightMap(const char* height_map_name = NULL)
+HeightMap::HeightMap(const char* height_map_name = NULL) : VertexArrayModel()
 {
    this->setClassID(CL_HEIGHT_MAP, "HeightMap");
@@ -43,5 +43,5 @@
 		 PRINTF(0)("loading Image %s\n", height_map_name);
 		 PRINTF(0)("width : %i\n", heightMap->w);
-		 PRINTF(0)("hight : %i\n", heightMap->h);
+		 PRINTF(0)("height : %i\n", heightMap->h);
 		 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
 		 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
@@ -54,34 +54,10 @@
      else       PRINTF(4)("oops! couldn't load %s for some reason.\n", height_map_name);
 
-
-	   generateNormalVectorField();
-
-
- //Defines 2 Materials (for testing only!)
- this->tmp_mat = new Material();
-  tmp_mat->setTransparency(1.0);
-  tmp_mat->setIllum(0.3);
-  tmp_mat->setDiffuse(0.55,0.4,0.2);
-  tmp_mat->setAmbient(0.6,0.4,0.2);
-  tmp_mat->setSpecular(0.02,0.02,0.02);
-  tmp_mat->setShininess(.1);
-  tmp_mat->setTransparency(1.0);
-
-  tmp_mat->diffuseTexture = NULL;
-  tmp_mat->ambientTexture = NULL;
-  tmp_mat->specularTexture = NULL;
-
- this->red_mat = new Material();
-  red_mat->setTransparency(1.0);
-  red_mat->setIllum(0.3);
-  red_mat->setDiffuse(0.55,0.1,0.1);
-  red_mat->setAmbient(0.55,0.1,0.1);
-  red_mat->setSpecular(0.02,0.02,0.02);
-  red_mat->setShininess(.1);
-  red_mat->setTransparency(1.0);
-
-  red_mat->diffuseTexture = NULL;
-  red_mat->ambientTexture = NULL;
-  red_mat->specularTexture = NULL;
+	
+  generateNormalVectorField();
+
+  shiftX = 0;
+  shiftY = 0;
+  shiftZ = 0;
 
 }
@@ -96,5 +72,5 @@
 		 PRINTF(0)("loading Image %s\n", height_map_name);
 		 PRINTF(0)("width : %i\n", heightMap->w);
-		 PRINTF(0)("hight : %i\n", heightMap->h);
+		 PRINTF(0)("height : %i\n", heightMap->h);
 		 PRINTF(0)("%i Byte(s) per Pixel \n", heightMap->format->BytesPerPixel);
 		 PRINTF(0)("Rshift : %i\n", heightMap->format->Rshift);
@@ -108,34 +84,8 @@
 
 
-	   generateNormalVectorField();
-
-
- //Defines 2 Materials (for testing only!)
- this->tmp_mat = new Material("tmp");
-  tmp_mat->setTransparency(1.0);
-  tmp_mat->setIllum(0.3);
-  tmp_mat->setDiffuse(1.0,1.0,1.0);
- tmp_mat->setAmbient(1.0,1.0,1.0);
-
-  tmp_mat->setSpecular(0.0,0.00,0.00);
-  tmp_mat->setShininess(1.0);
-
-
-
-
- this->red_mat = new Material("red");
-  red_mat->setTransparency(1.0);
-  red_mat->setIllum(3);
-  red_mat->setDiffuse(0.55,0.1,0.1);
-  red_mat->setAmbient(0.55,0.1,0.1);
-  red_mat->setSpecular(0.0,0.0,0.0);
-  red_mat->setShininess(1.0);
-  red_mat->setTransparency(1.0);
-
- // red_mat->diffuseTexture = NULL;
- // red_mat->ambientTexture = NULL;
-  //red_mat->specularTexture = NULL;
-
-  if(false /*colour_map_name != NULL*/)
+    generateNormalVectorField();
+
+
+  if(colour_map_name != NULL)
   {
   colourMap = IMG_Load(colour_map_name);
@@ -144,5 +94,5 @@
   		 PRINTF(0)("loading Image %s\n", colour_map_name);
 		 PRINTF(0)("width : %i\n", colourMap->w);
-		 PRINTF(0)("hight : %i\n", colourMap->h);
+		 PRINTF(0)("height : %i\n", colourMap->h);
 		 PRINTF(0)("%i Byte(s) per Pixel \n", colourMap->format->BytesPerPixel);
 		 PRINTF(0)("Rshift : %i\n", colourMap->format->Rshift);
@@ -154,26 +104,19 @@
 		 else       PRINTF(4)("oops! couldn't load %s for some reason.\n", colour_map_name);
 
-  const  char* texture_name = "pictures/ground.tga";
-  tmp_mat->setDiffuseMap(texture_name);
+		 
+		   
   if(colourMap != NULL)
   {
-  //colours = (unsigned char *) colourMap->pixels;
-  hasColourMap = false;
+  colours = (unsigned char *) colourMap->pixels;
+  hasColourMap = true;
   }
-  else
-  {
-  hasColourMap = false;
-
-
+  else hasColourMap = false;
+  
+	
+  shiftX = 0;
+  shiftY = 0;
+  shiftZ = 0;
   }
 
- // tmp_mat->setAmbientMap(texture_name);
-  //tmp_mat->setSpecularMap(texture_name);
-
-  // red_mat->setDiffuseMap(texture_name);
-  // red_mat->setAmbientMap(texture_name);
-  //red_mat->setSpecularMap(texture_name);
-  }
-
 
 }
@@ -185,17 +128,13 @@
 void HeightMap::load()
 {
-
-
-
-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;
+
 
 
@@ -205,90 +144,66 @@
 	SDL_LockSurface(heightMap);
 
-
-
+     
 	for(int i = 0 ; i < heightMap->h -sampleRate ; i +=sampleRate)
 	{
-
-		tmp_mat->select();
-
-
-
 		int j = 0;
 
-
+		float r;
+		float g;
+		float b;
 	    for(int j = 0 ; j < heightMap->w -sampleRate  ;  j += sampleRate)
 	    {
-	    	if(false)
-		{
-		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();
-		}
-		}
-		
-		this->addVertex(scaleX*(heightMap->h -i),(double)((double)(height)*scaleY),scaleZ*(j+sampleRate)); // Top Right
-
-		height = heights[j+sampleRate + i*(heightMap->w )];
+	    	 // To be fixed
+		 r = (float)colours[3*j+2 + 3*i*(heightMap->w )];
+		 g = (float)colours[3*j+1 + 3*i*(heightMap->w)];
+		 b = (float)colours[3*j+0 + 3*i*(heightMap->w)];
+		
+			height =  heights[j+sampleRate + i*(heightMap->w )];
+		this->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j+sampleRate) + shiftZ); // Top Right
+
+	
+		this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x);
+		this->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
+
+ 		this->addColor(r/255.0,g/255.0,b/255.0);
+
+
+	    }
+		
+	    
+		 j = (heightMap->w/sampleRate - sampleRate);
+
+		this->addVertex(scaleX*(heightMap->h -i)+ shiftX,-1000.0,scaleZ*(j+sampleRate)+ shiftZ); // Top Right
+
 		this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x);
 		this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
-
- 		this->addColor(0.5,0.5,0.5);
-
-
+ 		this->addColor(0.1,0.1,0.9);
+					
+
+		
+
+		}
+
+	SDL_UnlockSurface(heightMap);
+
+
+	int cnt = 0;
+	for(int i = 0 ; i < heightMap->h - 2*sampleRate ; i +=sampleRate)
+	{
+		
+	    for(int j = 0 ; j < heightMap->w - sampleRate  ;  j += sampleRate)
+	    {
+		
+	    	this->addIndice(cnt);
+		this->addIndice(cnt  + (heightMap->w)/ sampleRate );
+		cnt++;
+		
 	    }
-		
-		 j = (heightMap->w/sampleRate);
-
-		this->addVertex(scaleX*(heightMap->h -i),(double)(double)(-1000),scaleZ*(j+sampleRate)); // Top Right
-
-		height = heights[j+sampleRate + i*(heightMap->w )];
-		this->addNormal(normalVectorField[i][j+sampleRate].y,normalVectorField[i][j+sampleRate].z,normalVectorField[i][j+sampleRate].x);
-		this->addTexCoor(((j/sampleRate)%4)/4.0,((i/sampleRate)%4)/4.0);
-
- 		this->addColor(0.5,0.5,0.5);
-
-					
-
-
-
-		}
-
-
-
-	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);
-		this->addIndice(cnt+1 + (heightMap->w-sampleRate)/ sampleRate );
-		cnt ++;
-	    }
-		cnt++;
-	
-	 this->newStripe();
+	    	
+	    	cnt++;
+		 this->newStripe();	
+		
 		
 	}
-
-
-
-
-		     
-
-	//this->planeModel(100,100, 100,100);
 
 	this->finalize();
@@ -317,20 +232,20 @@
 	{
 	SDL_LockSurface(heightMap);
-	for(int i = 0 ; i < heightMap->h -1  ; i ++)
-	{
-	    for(int j = 0; j < heightMap->w  -1  ;  j ++)
+	for(int i = 0 ; i < heightMap->h - 1  ; i ++)
+	{
+	    for(int j = 0; j < heightMap->w  - 1  ;  j ++)
 	    {
 
 
 		delta = (int)heights[j + (i+1)*(heightMap->w )] -  (int) heights[j + i*(heightMap->w )];
-		Vector a =  Vector(-20.0,(float)delta  ,0.0f);
+		Vector a =  Vector(-scaleX,(float)delta*scaleY  ,0.0f);
 
 		delta = (int)heights[j+1 + i*(heightMap->w )] - (int)heights[j + i*(heightMap->w )];
-		Vector b =  Vector(0.0f,(float) delta ,20.0);
+		Vector b =  Vector(0.0f,(float) delta*scaleY ,scaleZ);
 
 
 		 normalVectorField[i][j] = b.cross(a);
 		 normalVectorField[i][j].normalize();
-
+		  
 	     }
 	}
@@ -341,89 +256,7 @@
 }
 
-void HeightMap::drawRect(int xBottom, int yBottom, int xTop, int yTop )
-{
-	int height = 0;
-	if(true)
-	{
-
-		height = heights[xTop + yTop*(heightMap->w )];
-		glNormal3f(normalVectorField[yTop][xTop].y,normalVectorField[yTop][xTop].z,normalVectorField[yTop][xTop].x);
-		glTexCoord2f(((yBottom/sampleRate)%8)/8.0+0.125,((xBottom/sampleRate)%8)/8.0+0.125);
- 		glVertex3f(scaleX*(heightMap->h - yTop),(double)((double)(height)*scaleY),scaleZ*(xTop)); // Top Right
-
-                height = heights[xBottom + yTop*(heightMap->w )];
-		glNormal3f(normalVectorField[yTop][xBottom].y,normalVectorField[yTop][xBottom].z,normalVectorField[yTop][xBottom].x);
-		glTexCoord2f(((yBottom/sampleRate)%8)/8.0,((xBottom/sampleRate)%8)/8.0+0.125);
- 		glVertex3f(scaleX*(heightMap->h -(yTop)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Top Left
-
-		height = heights[xTop + (yBottom)*(heightMap->w )];
- 		glNormal3f(normalVectorField[yBottom][xTop].y,normalVectorField[yBottom][xTop].z,normalVectorField[yBottom][xTop].x);
-		glTexCoord2f(((yBottom/sampleRate)%8)/8.0+0.125,((yBottom/sampleRate)%8)/8.0);
- 		glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xTop)); // Bottom Right
-
-height = heights[xBottom + (yBottom)*(heightMap->w )];
- 		glNormal3f(normalVectorField[yBottom][xBottom].y,normalVectorField[yBottom][xBottom].z,normalVectorField[yBottom][xBottom].x);
-		glTexCoord2f(((yBottom/sampleRate)%8)/8.0,((yBottom/sampleRate)%8)/8.0);
- 		glVertex3f(scaleX*(heightMap->h -(yBottom)),(double)((double)(height)*scaleY),scaleZ*(xBottom)); // Bottom Left
-
-
-
-	}
-	else
-	{
-		// subdivide
-	}
-
-}
-
-
-void HeightMap::fixBoarder(int xBottomLeft, int yBottomLeft, int xTopRight, int yTopRight)
-{
-
-	int height = 0;
-
-	for(int i= xTopRight; i < xBottomLeft ; i+= sampleRate)
-	{
-
-	glBegin(GL_TRIANGLES);
-
-			height = heights[yBottomLeft + (i + sampleRate)*(heightMap->w )];
-			glNormal3f(0,1,0);
-			glVertex3f(scaleX*(heightMap->h -i-sampleRate),scaleY*height,scaleZ*(yBottomLeft));
-
-			height = heights[yBottomLeft + i*(heightMap->w )];
-			glNormal3f(0,1,0);
-			glVertex3f(scaleX*(heightMap->h -i),scaleY*height,scaleZ*(yBottomLeft));
-
-			height = heights[yBottomLeft + (i + sampleRate/2)*(heightMap->w )];
-			glNormal3f(0,1,0);
-			glVertex3f(scaleX*(heightMap->h -i - sampleRate/2),scaleY*height,scaleZ*(yBottomLeft));
-
-
-
-			glEnd();
-
-
-
-
-	}
-	for(int j= yBottomLeft; j < yTopRight; j+= sampleRate)
-	{
-		   glBegin(GL_TRIANGLES);
-			height = heights[j + (xBottomLeft+sampleRate)*(heightMap->w )];
-			glNormal3f(-1,0,0);
-			glVertex3f(scaleX*(heightMap->h -xBottomLeft -sampleRate),scaleY*height,scaleZ*(j));
-
-			height = heights[j + sampleRate/2  + (xBottomLeft + sampleRate)*(heightMap->w )];
-			glNormal3f(-1,0,0);
-			glVertex3f(scaleX*(heightMap->h -xBottomLeft - sampleRate),scaleY*height,scaleZ*(j+sampleRate/2));
-
-			height = heights[j + sampleRate + (xBottomLeft + sampleRate)*(heightMap->w )];
-			glNormal3f(-1,0,0);
-			glVertex3f(scaleX*(heightMap->h -xBottomLeft-sampleRate),scaleY*height,scaleZ*(j+sampleRate));
-
-			glEnd();
-	}
-}
+
+
+
 
 void HeightMap::scale(Vector v)
@@ -434,5 +267,12 @@
 }
 
-// Accepts Coordinates relative to HeightMap
+void HeightMap::shift(Vector v)
+{
+ shiftX = v.x;
+ shiftY = v.y;
+ shiftZ = v.z;
+}
+
+
 float HeightMap::getHeight(float x, float y)
 {
Index: /branches/height_map/src/lib/graphics/importer/height_map.h
===================================================================
--- /branches/height_map/src/lib/graphics/importer/height_map.h	(revision 6328)
+++ /branches/height_map/src/lib/graphics/importer/height_map.h	(revision 6329)
@@ -17,4 +17,6 @@
 
 #define sampleRate 4
+#define texRate   4
+#define texRatef   4.0f
 
 class SDL_Surface;
@@ -32,5 +34,6 @@
 void load(const char*, int Mode);
 void scale( Vector V); 
-float getHeight(float x, float y); // x,y relative to HeightMap
+void shift (Vector V);
+float getHeight(float x, float y); 
 HeightMap();
 HeightMap(const char*);
@@ -56,7 +59,11 @@
 float scaleY ;
 float scaleZ ;
+float shiftX ;
+float shiftY ;
+float shiftZ ;
 int   cmScaleX;
 int   cmScaleY;
 bool  hasColourMap;
+
 inline int abs(int val)
 {
Index: /branches/height_map/src/world_entities/terrain.cc
===================================================================
--- /branches/height_map/src/world_entities/terrain.cc	(revision 6328)
+++ /branches/height_map/src/world_entities/terrain.cc	(revision 6329)
@@ -44,5 +44,5 @@
   this->tmp_mat = new Material(); 
   tmp_mat->setTransparency(1.0);
-  tmp_mat->setIllum(0.3);
+  tmp_mat->setIllum(0.2);
 /*  tmp_mat->setDiffuse(0.55,0.4,0.2);
   tmp_mat->setAmbient(0.6,0.4,0.2);
@@ -51,11 +51,15 @@
   tmp_mat->setAmbient(1.0,1.0,1.0 );
   tmp_mat->setSpecular(1.0,1.0,1.0);
-  tmp_mat->setShininess(.1);
+  tmp_mat->setShininess(.5);
   tmp_mat->setTransparency(1.0);
 
   tmp_mat->diffuseTexture = NULL;
   tmp_mat->ambientTexture = NULL;
- // tmp_mat->specularTexture = NULL;
+  tmp_mat->specularTexture = NULL;
   
+    const  char* texture_name = "pictures/ground1.tga";
+  tmp_mat->setDiffuseMap(texture_name);
+  tmp_mat->setAmbientMap(texture_name);
+   tmp_mat->setSpecularMap(texture_name); 
   // this->loadParams(root);
 
@@ -63,5 +67,6 @@
  char* colourmapName = ResourceManager::getFullName("pictures/heightmapHelloCM.bmp");
  hm = new HeightMap(heightmapName, colourmapName);
- hm->scale(Vector(23.0f,1.7f,23.0f));
+ hm->scale(Vector(43.0f,1.10f,43.0f));
+ hm->shift(Vector(-1000.0,-1500.0,-1000.0));
  hm->load();
  this->model=hm;
@@ -217,16 +222,18 @@
   glPushMatrix();
 
+  
   /* translate */
-  glTranslatef (this->getAbsCoor ().x - 1000,
-                this->getAbsCoor ().y - 400,
-                this->getAbsCoor ().z - 1000)	;
+ glTranslatef (this->getAbsCoor ().x ,
+               this->getAbsCoor ().y ,
+               this->getAbsCoor ().z)	;
+ 
   /* rotate */
-  Vector tmpRot = this->getAbsDir().getSpacialAxis();
-  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
-	
-   //this->tmp_mat->select();
-	
-
-  hm->draw();
+ Vector tmpRot = this->getAbsDir().getSpacialAxis();
+ glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
+ 
+ 	
+ 
+ this->tmp_mat->select();
+ hm->draw();
  /* if (this->objectList)
     glCallList(this->objectList);
