Index: /branches/height_map_merge/src/lib/graphics/importer/height_map.cc
===================================================================
--- /branches/height_map_merge/src/lib/graphics/importer/height_map.cc	(revision 6726)
+++ /branches/height_map_merge/src/lib/graphics/importer/height_map.cc	(revision 6727)
@@ -37,5 +37,5 @@
 lowResModel  = new VertexArrayModel();
 
-this->load(i1,j1,i2,j2,hm,highResModel,2);
+this->load(i1,j1,i2,j2,hm,highResModel,4);
 this->load(i1,j1,i2,j2,hm,lowResModel, 8);
 }
@@ -57,9 +57,9 @@
 	 							//FIXME
     float cameraDistance = (State::getCamera()->getAbsCoor() - Vector(0.0,100.0,0.0)).len();
-    if (cameraDistance > 5000 )
+    if (cameraDistance > 10000 )
     {
     
     }
-    else if (cameraDistance > 1000 )
+    else if (cameraDistance >= 50000 )
     {
       this->drawLowRes();
@@ -98,5 +98,5 @@
 	int sampleRate = Res;
 	
-	 float height = 0;
+	float height = 0;
  	int offset = 0;
  	
@@ -128,5 +128,5 @@
 	    	model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
 		model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
-		model->addTexCoor((((w -sampleRate)/sampleRate)%4)/4.0,(((i-sampleRate)/sampleRate)%4)/4.0);
+		model->addTexCoor((float)(j1-sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
  		model->addColor(r/255.0,g/255.0,b/255.0);
 		
@@ -147,10 +147,9 @@
 		height +=  (float)(unsigned char)hm->heights[j +sampleRate+ (i+2)*(heightMap->w )];
 		height +=  (float)(unsigned char)hm->heights[j+sampleRate + (i)*(heightMap->w )];
-		
 		height=height/5.0;
 		
 		model->addVertex(scaleX*(heightMap->h -i) + shiftX ,((double)(height)*scaleY) + shiftY ,scaleZ*(j) + shiftZ); // Top Right	
 		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-		model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
+		model->addTexCoor((float)(j) /(texRate), (float)(i %heightMap->h)/(texRate));
 		
 		//PRINTF(0)("TexCoord:  %f %f \n",(float)j / 100.0, (float)(i %heightMap->h)/100.0);
@@ -163,5 +162,5 @@
 		model->addVertex(scaleX*(heightMap->h -i)+ shiftX,shiftY,scaleZ*(w)+ shiftZ); // Top Right
 		model->addNormal(normalVectorField[i][w].y,normalVectorField[i][w].z,normalVectorField[i][w].x);
-		model->addTexCoor((((w+sampleRate)/sampleRate))/4.0,(((i+ sampleRate)/sampleRate))/4.0);
+		model->addTexCoor((float)(j2+sampleRate) /(texRate), (float)(i %heightMap->h)/(texRate));
  		model->addColor(r/255.0,g/255.0,b/255.0);
 		
@@ -208,5 +207,5 @@
 		model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right	
 		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-		model->addTexCoor(((j/sampleRate))/texRatef,(((i - sampleRate)/sampleRate))/texRatef);
+		model->addTexCoor((float)j /(texRate), (float)((i - sampleRate) %heightMap->h)/(texRate));
  		model->addColor(r/255.0,g/255.0,b/255.0);		
 	
@@ -225,5 +224,5 @@
 		model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right	
 		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-		model->addTexCoor(((j/sampleRate))/texRatef,(((i)/sampleRate))/texRatef);
+		model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
  		model->addColor(r/255.0,g/255.0,b/255.0);
 	    
@@ -246,5 +245,5 @@
 		model->addVertex(scaleX*(heightMap->h -i) + shiftX , shiftY ,scaleZ*(j) + shiftZ); // Top Right	
 		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-		model->addTexCoor(((j/sampleRate)%texRate)/texRatef,(((i- sampleRate)/sampleRate)%texRate)/texRatef);
+		model->addTexCoor((float)j /(texRate), (float)((i+ sampleRate) %heightMap->h)/(texRate));
  		model->addColor(r/255.0,g/255.0,b/255.0);		
 	
@@ -255,5 +254,5 @@
 	    {
 	    	int i = i2;
-	    		height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
+	    	height = (float)(unsigned char) hm->heights[j +sampleRate+ i*(heightMap->w )];
 		height += (float)(unsigned char) hm->heights[j+ 1 + sampleRate + (i+1)*(heightMap->w )];
 		height +=  (float) (unsigned char) hm->heights[j -1+ sampleRate   + (i+1)*(heightMap->w )];
@@ -263,5 +262,5 @@
 		model->addVertex(scaleX*(heightMap->h -i) + shiftX , ((double)(height)*scaleY) +shiftY ,scaleZ*(j) + shiftZ); // Top Right	
 		model->addNormal(normalVectorField[i][j].y,normalVectorField[i][j].z,normalVectorField[i][j].x);
-		model->addTexCoor(((j/sampleRate)%texRate)/texRatef,((i/sampleRate)%texRate)/texRatef);
+		model->addTexCoor((float)j /(texRate), (float)(i %heightMap->h)/(texRate));
  		model->addColor(r/255.0,g/255.0,b/255.0);
 	    
@@ -452,5 +451,4 @@
 	for(int j = 1; j < j_max ; j++)
 	{
-	 	
 	 tiles[i][j]->draw();
 	}	
@@ -500,7 +498,4 @@
 
 
-
-
-
 void HeightMap::scale(Vector v)
 {
@@ -510,22 +505,32 @@
 }
 
-void HeightMap::shift(Vector v)
-{
- shiftX = v.x;
- shiftY = v.y;
- shiftZ = v.z;
-}
-
-
-float HeightMap::getHeight(float x, float y)
-{
+void HeightMap::setAbsCoor(Vector v)
+{
+ offsetX = v.x;
+ offsetY = v.y;
+ offsetZ  = v.z;
+}
+
+
+float HeightMap::getHeight(float x, float y) 
+{
+
+ //x -= offsetX;
+ //y -= offsetZ;
+ 
+ 
  int xInt = (int)x / scaleX;  x -= (float)xInt*scaleX; xInt = heightMap->h - xInt;
- int yInt = (int)y / scaleZ;    y -= (float)yInt*scaleZ;
- if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w  ) return 0.0f;
+ int yInt = (int)y / scaleZ;    y -= (float)yInt*scaleZ; /*yInt = heightMap->w - yInt;*/
+ 
+ if(xInt <= 0 || xInt >= heightMap->h || yInt <= 0 || yInt >= heightMap->w  ) return shiftY;
+ 
  float height = heights[yInt + (xInt)*heightMap->w]*scaleY;
+ 
  float a = normalVectorField[(xInt)][yInt].x;
  float b = normalVectorField [(xInt)][yInt].z;
  float c = normalVectorField [(xInt)][yInt].y;
-  height -= ( (a/c)*(x) + (b/c)*(y))*scaleY;
- return height;
-}
+ 
+ height -= ( (a/c)*(x) + (b/c)*(y);
+  
+ return (height );
+}
Index: /branches/height_map_merge/src/lib/graphics/importer/height_map.h
===================================================================
--- /branches/height_map_merge/src/lib/graphics/importer/height_map.h	(revision 6726)
+++ /branches/height_map_merge/src/lib/graphics/importer/height_map.h	(revision 6727)
@@ -10,5 +10,5 @@
 
    ### File Specific:
-   main-programmer:
+   main-programmer: bottac@ee.ethz.ch
 */
 
@@ -17,7 +17,7 @@
 
 
-#define texRate      64
+#define texRate      32
 #define texRatef     4.0f
-#define tileSize     64
+#define tileSize     128
 
 class SDL_Surface;
@@ -58,6 +58,7 @@
 void load(const char*, int Mode);
 void scale( Vector V); 
-void shift (Vector V);
+void setAbsCoor(Vector V);
 float getHeight(float x, float y); 
+float getNormal(float x, float y);
 HeightMap();
 HeightMap(const char*);
@@ -78,5 +79,6 @@
 Vector  **  normalVectorField ; 
 Tile    ***  tiles;
-Vector     camCoords;
+Vector    camCoords;
+Vector offsetCoords;  
 Material * tmp_mat;
 Material* red_mat;
@@ -86,7 +88,10 @@
 float scaleY ;
 float scaleZ ;
-float shiftX ;
-float shiftY ;
-float shiftZ ;
+float shiftX ; // to be removed
+float shiftY ; // to be removed
+float shiftZ ; // to be removed
+float offsetX;
+float offsetY;
+float offsetZ;
 int   cmScaleX;
 int   cmScaleY;
Index: /branches/height_map_merge/src/world_entities/terrain.cc
===================================================================
--- /branches/height_map_merge/src/world_entities/terrain.cc	(revision 6726)
+++ /branches/height_map_merge/src/world_entities/terrain.cc	(revision 6727)
@@ -30,4 +30,6 @@
 
 #include "glincl.h"
+
+#include "state.h"
 
 using namespace std;
@@ -154,6 +156,6 @@
 
   this->heightMap = new HeightMap(hmName, hmColorName);
-  heightMap->scale(Vector(23.0f,3.5f,23.0f));
-  heightMap->shift(Vector(-1000.0,-90.0,-4000.0));
+  heightMap->scale(Vector(23.0f,1.1f,23.0f));
+  heightMap->setAbsCoor(this->getAbsCoor());
   heightMap->load();
   delete[] hmName;
@@ -166,5 +168,5 @@
 {
   if (this->heightMapMaterial != NULL)
-    delete this->heightMapMaterial;
+      delete this->heightMapMaterial;
 
 
@@ -214,14 +216,18 @@
 void Terrain::draw () const
 {
+  
+   
+ 
   glMatrixMode(GL_MODELVIEW);
   glPushMatrix();
 
   /* translate */
-  glTranslatef (this->getAbsCoor ().x,
+ /* 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 );
+ // Vector tmpRot = this->getAbsDir().getSpacialAxis();
+  //glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
 
   if (this->objectList)
@@ -237,6 +243,5 @@
     	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
     	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-   
-	 glEnable(GL_LIGHTING);
+   	glEnable(GL_LIGHTING);
  	glColorMaterial ( GL_FRONT_AND_BACK, GL_EMISSION ) ;
   	glEnable (GL_COLOR_MATERIAL) ;
@@ -245,6 +250,21 @@
   glPopMatrix();
 
-
-
+ glMatrixMode(GL_MODELVIEW);
+glPushMatrix();	
+glLoadIdentity();
+ Vector camera =   State::getCamera()->getAbsCoor(); // Go on here ..........!!!
+    float height =    heightMap->getHeight(camera.x, camera.z);
+    
+  glEnable (GL_COLOR_MATERIAL) ;
+    glBegin(GL_QUADS);            // Draw The Cube Using quads
+    glColor3f(0.0f,1.0f,0.0f);  // Color Blue
+    glVertex3f(camera.x + 13.0f,height+13.0f,camera.z-13.0f);      // Top Right Of The Quad (Top)
+    glVertex3f(camera.x-13.0f, height+13.0f,camera.z-13.0f);      // Top Left Of The Quad (Top)
+    glVertex3f(camera.x-13.0f, height+13.0f, camera.z+13.0f);      // Bottom Left Of The Quad (Top)
+    glVertex3f(camera.x+ 13.0f, height+13.0f, camera.z+13.0f);      // Bottom Right Of The Quad (Top)
+   glEnd();                      // End Drawing The Plan
+   
+    
+glPopMatrix();
   /* THIS IS ONLY FOR DEBUGGING INFORMATION */
   if (this->ssp != NULL)
@@ -457,2 +477,9 @@
 {
 }
+
+float Terrain::getHeight(float x, float y)
+{
+	if(this->heightMap != NULL)
+		return (this->heightMap->getHeight(x, y));
+	return 0;
+}
Index: /branches/height_map_merge/src/world_entities/terrain.h
===================================================================
--- /branches/height_map_merge/src/world_entities/terrain.h	(revision 6726)
+++ /branches/height_map_merge/src/world_entities/terrain.h	(revision 6727)
@@ -46,4 +46,6 @@
 
   void buildDebugTerrain(DebugTerrain debugTerrain);
+  
+  float getHeight(float x, float y);
   virtual void draw() const;
 
