Index: /orxonox/branches/heightMap/src/lib/graphics/importer/Makefile.am
===================================================================
--- /orxonox/branches/heightMap/src/lib/graphics/importer/Makefile.am	(revision 3918)
+++ /orxonox/branches/heightMap/src/lib/graphics/importer/Makefile.am	(revision 3919)
@@ -27,5 +27,5 @@
 
 
-bin_PROGRAMS=importer
+bin_PROGRAMS=importer heightmap
 importer_SOURCES= framework.cc \
 	          windowHandler.cc \
@@ -43,4 +43,11 @@
 		  $(MAINSRCDIR)/lib/coord/p_node.cc \
 		  $(MAINSRCDIR)/lib/coord/null_parent.cc
+
+
+heightmap_SOURCES= main.cc \
+		   heightMapTerrain.cc \
+		   heightMapViewer.cc \
+		   $(MAINSRCDIR)/lib/math/vector.cc \
+		   windowHandler.cc 
 
 noinst_HEADERS= framework.h \
Index: /orxonox/branches/heightMap/src/lib/graphics/importer/Makefile.in
===================================================================
--- /orxonox/branches/heightMap/src/lib/graphics/importer/Makefile.in	(revision 3918)
+++ /orxonox/branches/heightMap/src/lib/graphics/importer/Makefile.in	(revision 3919)
@@ -16,5 +16,5 @@
 
 
-SOURCES = $(importer_SOURCES)
+SOURCES = $(heightmap_SOURCES) $(importer_SOURCES)
 
 srcdir = @srcdir@
@@ -39,5 +39,5 @@
 POST_UNINSTALL = :
 host_triplet = @host@
-bin_PROGRAMS = importer$(EXEEXT)
+bin_PROGRAMS = importer$(EXEEXT) heightmap$(EXEEXT)
 subdir = src/lib/graphics/importer
 DIST_COMMON = $(noinst_HEADERS) $(srcdir)/Makefile.am \
@@ -53,4 +53,9 @@
 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
 PROGRAMS = $(bin_PROGRAMS)
+am_heightmap_OBJECTS = main.$(OBJEXT) heightMapTerrain.$(OBJEXT) \
+	heightMapViewer.$(OBJEXT) vector.$(OBJEXT) \
+	windowHandler.$(OBJEXT)
+heightmap_OBJECTS = $(am_heightmap_OBJECTS)
+heightmap_LDADD = $(LDADD)
 am_importer_OBJECTS = framework.$(OBJEXT) windowHandler.$(OBJEXT) \
 	model.$(OBJEXT) objModel.$(OBJEXT) primitive_model.$(OBJEXT) \
@@ -68,4 +73,6 @@
 @AMDEP_TRUE@	./$(DEPDIR)/framework.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/graphics_engine.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/heightMapTerrain.Po \
+@AMDEP_TRUE@	./$(DEPDIR)/heightMapViewer.Po ./$(DEPDIR)/main.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/material.Po ./$(DEPDIR)/model.Po \
 @AMDEP_TRUE@	./$(DEPDIR)/null_parent.Po ./$(DEPDIR)/objModel.Po \
@@ -80,6 +87,6 @@
 CXXLINK = $(CXXLD) $(AM_CXXFLAGS) $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) \
 	-o $@
-SOURCES = $(importer_SOURCES)
-DIST_SOURCES = $(importer_SOURCES)
+SOURCES = $(heightmap_SOURCES) $(importer_SOURCES)
+DIST_SOURCES = $(heightmap_SOURCES) $(importer_SOURCES)
 HEADERS = $(noinst_HEADERS)
 ETAGS = etags
@@ -214,4 +221,10 @@
 		  $(MAINSRCDIR)/lib/coord/null_parent.cc
 
+heightmap_SOURCES = main.cc \
+		   heightMapTerrain.cc \
+		   heightMapViewer.cc \
+		   $(MAINSRCDIR)/lib/math/vector.cc \
+		   windowHandler.cc 
+
 noinst_HEADERS = framework.h \
 	  	windowHandler.h \
@@ -279,4 +292,7 @@
 clean-binPROGRAMS:
 	-test -z "$(bin_PROGRAMS)" || rm -f $(bin_PROGRAMS)
+heightmap$(EXEEXT): $(heightmap_OBJECTS) $(heightmap_DEPENDENCIES) 
+	@rm -f heightmap$(EXEEXT)
+	$(CXXLINK) $(heightmap_LDFLAGS) $(heightmap_OBJECTS) $(heightmap_LDADD) $(LIBS)
 importer$(EXEEXT): $(importer_OBJECTS) $(importer_DEPENDENCIES) 
 	@rm -f importer$(EXEEXT)
@@ -293,4 +309,7 @@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/framework.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/graphics_engine.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/heightMapTerrain.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/heightMapViewer.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/material.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/model.Po@am__quote@
@@ -321,4 +340,20 @@
 @am__fastdepCXX_FALSE@	$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
 
+vector.o: $(MAINSRCDIR)/lib/math/vector.cc
+@am__fastdepCXX_TRUE@	if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vector.o -MD -MP -MF "$(DEPDIR)/vector.Tpo" -c -o vector.o `test -f '$(MAINSRCDIR)/lib/math/vector.cc' || echo '$(srcdir)/'`$(MAINSRCDIR)/lib/math/vector.cc; \
+@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/vector.Tpo" "$(DEPDIR)/vector.Po"; else rm -f "$(DEPDIR)/vector.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(MAINSRCDIR)/lib/math/vector.cc' object='vector.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	depfile='$(DEPDIR)/vector.Po' tmpdepfile='$(DEPDIR)/vector.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vector.o `test -f '$(MAINSRCDIR)/lib/math/vector.cc' || echo '$(srcdir)/'`$(MAINSRCDIR)/lib/math/vector.cc
+
+vector.obj: $(MAINSRCDIR)/lib/math/vector.cc
+@am__fastdepCXX_TRUE@	if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vector.obj -MD -MP -MF "$(DEPDIR)/vector.Tpo" -c -o vector.obj `if test -f '$(MAINSRCDIR)/lib/math/vector.cc'; then $(CYGPATH_W) '$(MAINSRCDIR)/lib/math/vector.cc'; else $(CYGPATH_W) '$(srcdir)/$(MAINSRCDIR)/lib/math/vector.cc'; fi`; \
+@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/vector.Tpo" "$(DEPDIR)/vector.Po"; else rm -f "$(DEPDIR)/vector.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(MAINSRCDIR)/lib/math/vector.cc' object='vector.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	depfile='$(DEPDIR)/vector.Po' tmpdepfile='$(DEPDIR)/vector.TPo' @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vector.obj `if test -f '$(MAINSRCDIR)/lib/math/vector.cc'; then $(CYGPATH_W) '$(MAINSRCDIR)/lib/math/vector.cc'; else $(CYGPATH_W) '$(srcdir)/$(MAINSRCDIR)/lib/math/vector.cc'; fi`
+
 graphics_engine.o: $(MAINSRCDIR)/lib/graphics/graphics_engine.cc
 @am__fastdepCXX_TRUE@	if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT graphics_engine.o -MD -MP -MF "$(DEPDIR)/graphics_engine.Tpo" -c -o graphics_engine.o `test -f '$(MAINSRCDIR)/lib/graphics/graphics_engine.cc' || echo '$(srcdir)/'`$(MAINSRCDIR)/lib/graphics/graphics_engine.cc; \
@@ -352,20 +387,4 @@
 @AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o base_object.obj `if test -f '$(MAINSRCDIR)/lib/lang/base_object.cc'; then $(CYGPATH_W) '$(MAINSRCDIR)/lib/lang/base_object.cc'; else $(CYGPATH_W) '$(srcdir)/$(MAINSRCDIR)/lib/lang/base_object.cc'; fi`
-
-vector.o: $(MAINSRCDIR)/lib/math/vector.cc
-@am__fastdepCXX_TRUE@	if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vector.o -MD -MP -MF "$(DEPDIR)/vector.Tpo" -c -o vector.o `test -f '$(MAINSRCDIR)/lib/math/vector.cc' || echo '$(srcdir)/'`$(MAINSRCDIR)/lib/math/vector.cc; \
-@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/vector.Tpo" "$(DEPDIR)/vector.Po"; else rm -f "$(DEPDIR)/vector.Tpo"; exit 1; fi
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(MAINSRCDIR)/lib/math/vector.cc' object='vector.o' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@	depfile='$(DEPDIR)/vector.Po' tmpdepfile='$(DEPDIR)/vector.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vector.o `test -f '$(MAINSRCDIR)/lib/math/vector.cc' || echo '$(srcdir)/'`$(MAINSRCDIR)/lib/math/vector.cc
-
-vector.obj: $(MAINSRCDIR)/lib/math/vector.cc
-@am__fastdepCXX_TRUE@	if $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT vector.obj -MD -MP -MF "$(DEPDIR)/vector.Tpo" -c -o vector.obj `if test -f '$(MAINSRCDIR)/lib/math/vector.cc'; then $(CYGPATH_W) '$(MAINSRCDIR)/lib/math/vector.cc'; else $(CYGPATH_W) '$(srcdir)/$(MAINSRCDIR)/lib/math/vector.cc'; fi`; \
-@am__fastdepCXX_TRUE@	then mv -f "$(DEPDIR)/vector.Tpo" "$(DEPDIR)/vector.Po"; else rm -f "$(DEPDIR)/vector.Tpo"; exit 1; fi
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@	source='$(MAINSRCDIR)/lib/math/vector.cc' object='vector.obj' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@	depfile='$(DEPDIR)/vector.Po' tmpdepfile='$(DEPDIR)/vector.TPo' @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@	$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o vector.obj `if test -f '$(MAINSRCDIR)/lib/math/vector.cc'; then $(CYGPATH_W) '$(MAINSRCDIR)/lib/math/vector.cc'; else $(CYGPATH_W) '$(srcdir)/$(MAINSRCDIR)/lib/math/vector.cc'; fi`
 
 resource_manager.o: $(MAINSRCDIR)/util/resource_manager.cc
Index: /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapTerrain.cc
===================================================================
--- /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapTerrain.cc	(revision 3919)
+++ /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapTerrain.cc	(revision 3919)
@@ -0,0 +1,237 @@
+/*
+ *  ldrawparser.cpp
+ *  legotown3d
+ *
+ *  Created by Nico Bernold on 08.01.05.
+ *  Copyright 2005 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "heightMapTerrain.h"
+#include "vector.h"
+#ifdef HAVE_SDL_SDL_IMAGE_H
+#include <SDL/SDL_image.h>
+#endif /* HAVE_SDL_SDL_IMAGE_H */
+
+HeightMapTerrain::HeightMapTerrain()
+{	
+}
+
+HeightMapTerrain::~HeightMapTerrain()
+{
+}
+
+bool HeightMapTerrain::loadBitmap(char* fileName)
+{
+#ifdef HAVE_SDL_SDL_IMAGE_H
+  cout << "Using SDL-image for reading in the File " << fileName <<endl;
+  return this->bitmap = IMG_Load(fileName);
+#else
+  return this->bitmap = SDL_LoadBMP(fileName);	
+#endif /* HAVE_SDL_SDL_IMAGE_H */
+}
+
+bool HeightMapTerrain::createDisplayLists(int width, int height, int levelOfDetail)
+{
+	if (bitmap == NULL) return false;
+	
+	cout << "bitmap-dimensions:             " << bitmap->w << " x " << bitmap->h << endl;
+	cout << "bitmap-pitch:                  " << bitmap->pitch << endl;
+	cout << "bitmap->format->BytesPerPixel: " << (int)bitmap->format->BytesPerPixel << endl;
+	cout << "bitmap->format->BitsPerPixel:  " << (int)bitmap->format->BitsPerPixel << endl;
+	 
+	if (bitmap->w % width != 0) return false;
+	if (bitmap->h % height != 0) return false;
+	
+	if (levelOfDetail < 1 || levelOfDetail > 10) return false;
+	
+	int howManyListsWide = bitmap->w / width;
+	int howManyListsHigh = bitmap->h / height;
+	
+	// calculate how many displayLists we'll create
+	displayListCount = howManyListsWide * howManyListsHigh; 
+
+	cout << "lists-information: " << howManyListsWide << " * " << howManyListsHigh << " = " << displayListCount << " display lists." << endl;
+	
+	displayListStart = glGenLists(displayListCount);
+	if (displayListStart == 0)
+	{
+		cout << "could not generate " << displayListCount << " display lists. exiting. " << endl;
+		return false;
+	}
+	
+	cout << displayListCount << " display lists generated. starting at: " << displayListStart << endl;
+
+
+	int i,j;
+	
+	for (i=0; i<howManyListsHigh; i++)
+	{
+		for (j=0; j<howManyListsWide; j++)
+		{
+			if (readIntoList(j*width,i*height,width,height,levelOfDetail,i*howManyListsHigh + j) == false)
+			{
+				cout << "error while generating display lists. exiting. " << endl;
+				return false;
+			}
+
+		}
+	}
+	
+	return true;
+}
+
+bool HeightMapTerrain::readIntoList(int left, int top, int width, int height, int levelOfDetail, GLuint displayListNr)
+{
+	cout << "creating list Nr " << displayListNr << endl;
+	cout << "left, top, width, height: " << left << ", " << top << ", " << width << ", " << height << endl; 
+	
+	// y is the height value in OpenGL convention
+	int x,y,z;
+	GLfloat col;
+
+	// used for normal calculations
+	Vector O; // origin: the vertex where i'm standing
+	Vector N,E,S,W,NE,SE,SW,NW; // vectors pointing to north, east, ...
+
+	bool eightTriangles = false;
+	
+	
+	// contains a normal vector for every vertex
+	normals = new Vector[width*height];
+
+	// precalculate all vertex normals for later use in display list generation
+	// many superflous calculations i know...
+	for (z=top; z<top+height; z++)
+	{
+		for (x=left; x<left+width; x++)
+		{
+			O = Vector(x,getHeightValue(x,z),z);
+
+			N = Vector(x,getHeightValue(x,z-1),z-1) - O;
+			E = Vector(x+1,getHeightValue(x+1,z),z) - O;
+			S = Vector(x,getHeightValue(x,z+1),z+1) - O;
+			W = Vector(x-1,getHeightValue(x-1,z),z) - O;
+
+			if (eightTriangles == false)
+				// calculate the average normal vector by adding up all 4 adjacent triangle normal vectors
+				normals[(z-top) * height + (x-left)] = N.cross(W) + W.cross(S) + S.cross(E);
+
+			else
+			{
+				NE = Vector(x+1,getHeightValue(x+1,z-1),z-1) - O;
+				SE = Vector(x+1,getHeightValue(x+1,z+1),z+1) - O;
+				SW = Vector(x-1,getHeightValue(x-1,z+1),z+1) - O;
+				NW = Vector(x-1,getHeightValue(x-1,z-1),z-1) - O;
+				// calculate the average normal vector by adding up all 8 adjacent triangle normal vectors
+				normals[(z-top) * height + (x-left)] = N.cross(NW) + NW.cross(W) + W.cross(SW) + SW.cross(S) + S.cross(SE) + SE.cross(E) + E.cross(NE) + NE.cross(N);
+			}
+
+			// every second vertex is the edge of eightTriangles (the others have only four triangles)
+			eightTriangles = !eightTriangles;
+		}
+	}
+	
+	cout << "normals precalculated for list " << displayListNr << endl;
+	
+	glNewList(displayListStart + displayListNr,GL_COMPILE);
+	{
+		glBegin(GL_TRIANGLES);
+		{
+			// don't go through last col and row, because they are already done by second last col&row
+			for (z = top; z < (top + height) - 1; z++)
+			{
+				for (x = left; x < (left + width) - 1; x++)
+				{
+					// draw 2 triangles per (x,z) pair
+					
+					if (eightTriangles)
+					{
+						call_glNormal_and_glVertex(x,z,top,left,height);
+						call_glNormal_and_glVertex(x,z+1,top,left,height);
+						call_glNormal_and_glVertex(x+1,z,top,left,height);
+					
+						call_glNormal_and_glVertex(x+1,z,top,left,height);
+						call_glNormal_and_glVertex(x,z+1,top,left,height);
+						call_glNormal_and_glVertex(x+1,z+1,top,left,height);
+					}
+					
+					else
+					{
+						call_glNormal_and_glVertex(x,z,top,left,height);
+						call_glNormal_and_glVertex(x,z+1,top,left,height);
+						call_glNormal_and_glVertex(x+1,z+1,top,left,height);
+						
+						call_glNormal_and_glVertex(x+1,z,top,left,height);
+						call_glNormal_and_glVertex(x,z,top,left,height);
+						call_glNormal_and_glVertex(x+1,z+1,top,left,height);
+					}
+					
+					
+					// use the same trick to change the triangles everytime. once |/| and once |\|
+					eightTriangles = !eightTriangles;
+
+				}
+			}
+		}
+		glEnd();
+
+	}
+	glEndList();
+
+	
+	delete[] normals;
+	
+	return true;
+}
+
+
+void HeightMapTerrain::call_glNormal_and_glVertex(int x,int z,int top,int left,int height)
+{
+/*
+	GLfloat color[4];           // color parameter for glMaterial
+	
+	int heightVal = getHeightValue(x,z);
+
+	color[0] = 1.0 / 256.0 * heightVal;
+	color[1] = 1.0 / 256.0 * heightVal;
+	color[2] = 1.0 / 256.0 * heightVal;
+	color[3] = 1;  // alpha channel (1 = solid)
+
+	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
+*/
+	glNormal3f(normals[(z-top) * height + (x-left)].x,normals[(z-top) * height + (x-left)].y,normals[(z-top) * height + (x-left)].z);
+	glVertex3i(x,getHeightValue(x,z),z);
+}
+
+
+GLint HeightMapTerrain::getHeightValue(int x, int z)
+{
+	if (bitmap == NULL) return 0;
+
+	// catch out of image access
+	int X = x % bitmap->w;
+	int Z = z % bitmap->h;
+	
+	/*
+	if (X != x) cout << "x lies outside of image (" << x << "," << z << ")" << endl;
+	if (Z != z) cout << "z lies outside of image (" << x << "," << z << ")" << endl;
+	*/
+	
+	// if x or z exeed the image size, return 0 as height value
+	if (X != x || Z != z) return 0;
+	
+	
+	Uint8 index;
+	SDL_Color color;
+	
+	SDL_LockSurface(bitmap);
+
+	index = *((Uint8*)bitmap->pixels + Z * bitmap->pitch + X * bitmap->format->BytesPerPixel);
+	color = bitmap->format->palette->colors[index];
+
+	SDL_UnlockSurface(bitmap);
+	
+	// return the red component, because in a grayscale pic, r,g and b are all the same value
+	return (GLint)color.r;
+}
Index: /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapTerrain.h
===================================================================
--- /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapTerrain.h	(revision 3919)
+++ /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapTerrain.h	(revision 3919)
@@ -0,0 +1,51 @@
+/*
+ *  ldrawparser.h
+ *  legotown3d
+ *
+ *  Created by Nico Bernold on 08.01.05.
+ *  Copyright 2005 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include <iostream>
+using namespace std;
+
+#include "stdincl.h"
+class Vector;
+
+class HeightMapTerrain
+{
+public:
+	HeightMapTerrain();
+	~HeightMapTerrain();	
+
+	bool loadBitmap(char* fileName);
+	
+	bool createDisplayLists(int width, int height, int levelOfDetail);
+	
+	bool readIntoList(int left, int top, int width, int height, int levelOfDetail, GLuint displayListNr);
+
+	// how many display lists are there
+	int displayListCount;
+	
+	// tells from which integer our display lists start
+	GLuint displayListStart;
+	
+	// array of display lists
+	//GLuint* displayLists;
+
+private:
+	// returns the height value between 0 and 256 for a point (x,z) in the picture
+	GLint getHeightValue(int x, int z);
+	
+	// makes a call to glNormal and glVertex for supplied x and z
+	void call_glNormal_and_glVertex(int x,int z,int top,int left,int height);
+
+	// holds the loaded pixels
+	SDL_Surface* bitmap;
+	
+	// holds normal vector for every vertex
+	Vector* normals;
+};
+
+
Index: /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapViewer.cc
===================================================================
--- /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapViewer.cc	(revision 3919)
+++ /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapViewer.cc	(revision 3919)
@@ -0,0 +1,338 @@
+/*
+ *  legotown.cpp
+ *  legotown3d
+ *
+ *  Created by Nico Bernold on 08.01.05.
+ *  Copyright 2005 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "heightMapViewer.h"
+
+// constructor
+HeightMapViewer::HeightMapViewer()
+{
+	cout << "HeightMapViewer::HeightMapViewer()" << endl;
+	
+	cameraPos = Vector(0,0,40);
+	sightDirection = Vector(0,0,-1);
+
+	lookAt = cameraPos + sightDirection;
+
+	upVector = Vector(0,1,0);
+	
+	wireframe = false;
+	mousedown = false;
+	smoothShading = false;
+	
+}
+
+// destructor
+HeightMapViewer::~HeightMapViewer()
+{
+	cout << "HeightMapViewer::~HeightMapViewer()" << endl;
+}
+
+// main loop
+bool HeightMapViewer::init(char* fileName)
+{
+        cout << "HeightMapViewer init()" << endl;
+	
+#ifdef FULLSCREEN
+	if (!windowhandler.CreateGLWindow("height map viewer", WIDTH, HEIGHT, 32, true))
+#else
+	if (!windowhandler.CreateGLWindow("height map viewer", WIDTH, HEIGHT, 32, false))
+#endif
+	{
+		cout << "could not create OpenGL-Window." << endl;
+		return false;
+	}
+
+	if (terrain.loadBitmap(fileName) == false)
+	{
+		cout << "could not load bitmap." << endl;
+		return false;
+	}
+	
+	terrain.createDisplayLists(128, 128, 1);
+	
+	this->initLighting();
+	SDL_EnableKeyRepeat(50,10);
+	return true;
+}
+
+bool HeightMapViewer::initLighting(void)
+{
+  /*  glEnable(GL_LIGHTING);
+  glEnable(GL_DEPTH_TEST);
+
+  GLfloat whiteLight[] = {.2, .2, .2, 1.0};
+  GLfloat light0Position[] = {10.0, 10.0, 10.0, 0.0};
+  GLfloat lmodelAmbient[] = {.1, .1, .1, 1.0};
+
+  glEnable(GL_LIGHT0);
+  glLightfv(GL_LIGHT0, GL_POSITION, light0Position);
+  glLightfv(GL_LIGHT0, GL_DIFFUSE, whiteLight);
+  glLightfv(GL_LIGHT0, GL_SPECULAR, whiteLight);
+  
+	GLfloat klotz_Ka[]  = {0.2,0.2,0.2,1.0};
+	GLfloat klotz_Kd[]  = {0.3,1.0,0.3,1.0};
+	GLfloat klotz_Ks[]  = {0.8,0.8,0.8,1.0};
+	GLfloat klotz_Ke[]  = {0.0,0.0,0.0,1.0};
+	GLfloat klotz_Se    = 20;
+	glMaterialfv(GL_FRONT,GL_AMBIENT,klotz_Ka);
+	glMaterialfv(GL_FRONT,GL_DIFFUSE,klotz_Kd);
+  */
+
+	glShadeModel(GL_FLAT); // Enable Smooth Shading
+	
+	glClearColor(0.445f, 0.726f, 1.00f, 0.0f); // Blue Background
+	
+	glClearDepth(1.0f);  // Depth Buffer Setup
+	glEnable(GL_DEPTH_TEST); // Enables Depth Testing
+	glDepthFunc(GL_LEQUAL);	// The Type Of Depth Testing To Do
+
+	glEnable(GL_CULL_FACE); // don't draw back faces
+	
+	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);  // Really Nice Perspective Calculations
+
+
+	// fog behaves strange
+	//glEnable(GL_FOG);
+	GLfloat fog_color[4] = {0.7,0.7,0.7,1.0};
+	glFogfv(GL_FOG_COLOR,fog_color);
+	glFogf(GL_FOG_START, 0.0);
+	glFogf(GL_FOG_END, 100.0);
+	glFogi(GL_FOG_MODE,GL_LINEAR);
+
+
+	glEnable(GL_NORMALIZE);
+	
+	// LIGHT SETTINGS
+	glEnable(GL_LIGHTING);
+	glEnable(GL_LIGHT0);
+	
+	// global parameters
+	GLfloat global_Ka[]  = {0.25,0.25,0.25,1.0};
+	
+	// light0 parameters
+	GLfloat light0_pos[] = {0.0,100.0,0.0,0.0};
+	GLfloat light0_Ka[]  = {0.0,0.0,0.0,1.0};
+	GLfloat light0_Kd[]  = {0.6,0.6,0.6,1.0};
+	GLfloat light0_Ks[]  = {0.8,0.8,0.8,1.0};
+	
+	// klotz default parameters
+	GLfloat klotz_Ka[]  = {0.2,0.2,0.2,1.0};
+	GLfloat klotz_Kd[]  = {0.3,1.0,0.3,1.0};
+	GLfloat klotz_Ks[]  = {0.8,0.8,0.8,1.0};
+	GLfloat klotz_Ke[]  = {0.0,0.0,0.0,1.0};
+	GLfloat klotz_Se    = 20;
+	
+	// set light0 options
+	glLightfv(GL_LIGHT0,GL_POSITION,light0_pos);
+	glLightfv(GL_LIGHT0,GL_AMBIENT,light0_Ka);
+	glLightfv(GL_LIGHT0,GL_DIFFUSE,light0_Kd);
+	glLightfv(GL_LIGHT0,GL_SPECULAR,light0_Ks);
+
+	// MATERIAL SETTINGS
+	glMaterialfv(GL_FRONT,GL_AMBIENT,klotz_Ka);
+	glMaterialfv(GL_FRONT,GL_DIFFUSE,klotz_Kd);
+	//glMaterialfv(GL_FRONT,GL_SPECULAR,klotz_Ks);
+	//glMaterialfv(GL_FRONT,GL_EMISSION,klotz_Ke);
+	//glMaterialf(GL_FRONT,GL_SHININESS,klotz_Se);
+
+
+}
+
+
+bool HeightMapViewer::run()
+{
+	cout << "HeightMapViewer run()" << endl;
+
+	bool done = false;
+	SDL_Event event;
+
+	float angleX;
+	float angleY;
+	
+	while(!done)
+	{
+		/* Check for events */
+		while (SDL_PollEvent(&event))
+		{
+			switch (event.type)
+			{
+				case SDL_MOUSEMOTION:
+					if (mousedown==true)
+					{
+						angleX = PI / 180 * event.motion.xrel * 0.2;
+						angleY = PI / 180 * event.motion.yrel * 0.2;
+
+						// Quaternion(angle,axis)
+						rotator = Quaternion(-angleX,Vector(0,1,0));
+						sightDirection = rotator.apply(sightDirection);
+
+						rotator = Quaternion(angleY,perpendicular(sightDirection));
+						
+						sightDirection = rotator.apply(sightDirection);
+						
+						updateView();						
+					}
+					break;
+				case SDL_MOUSEBUTTONDOWN:
+					mousedown = true;
+					break;
+				case SDL_MOUSEBUTTONUP:
+					mousedown = false;
+					break;
+					
+				case SDL_KEYDOWN:
+
+					switch(event.key.keysym.sym)
+					{
+						case SDLK_UP:
+							// move in direction of sight
+							cameraPos = cameraPos + sightDirection * 0.7;							
+							updateView();
+							break;
+
+						case SDLK_DOWN:
+							// move in direction of sight
+							cameraPos = cameraPos - sightDirection * 0.7;
+							updateView();
+							break;
+							
+						case SDLK_LEFT:
+							cameraPos = cameraPos + perpendicular(sightDirection) * 0.7;
+							updateView();
+							break;
+							
+						case SDLK_RIGHT:
+							cameraPos = cameraPos - perpendicular(sightDirection) * 0.7;
+							updateView();
+							break;
+							
+						case SDLK_s:
+							smoothShading = !smoothShading;
+							if (smoothShading) 	glShadeModel(GL_SMOOTH);
+							else glShadeModel(GL_FLAT);
+							break;
+							
+						case SDLK_w:
+							wireframe = !wireframe;
+							if (wireframe) glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
+							else glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
+							break;
+							
+						case SDLK_r:
+							// reset view vectors
+							//cameraPos = Vector(0,0,40);
+							//sightDirection = Vector(0,0,-1);							
+							cameraPos = Vector(73.9871,172.496,286.137);
+							sightDirection = Vector(0.23429,-0.736527,-0.625574);
+
+							updateView();
+							break;
+
+						case SDLK_h:
+							cout << "HELP\n"
+							<< "display list count:    " << terrain.displayListCount << endl
+							<< "first display list at: " << terrain.displayListStart << endl
+							<< "camera position:       " << "(" << cameraPos.x << "," << cameraPos.y << "," << cameraPos.z << ")" << endl
+							<< "sightDirection:        " << "(" << sightDirection.x << "," << sightDirection.y << "," << sightDirection.z << ")" << endl
+							<< endl;
+							
+							break;
+							
+						case SDLK_ESCAPE:
+						case SDLK_q:
+							done = 1;
+							break;
+							
+						default:
+							break;
+					}	
+					break;
+					
+				case SDL_QUIT:
+					done = 1;
+					break;
+					
+				default:
+					break;
+			}
+		}
+		
+		drawScene();
+
+		SDL_GL_SwapBuffers();	
+
+		SDL_Delay(1);
+	}
+	
+	return true;
+}
+
+void HeightMapViewer::updateView()
+{
+	// be sure to use up to date lookAt-vector
+	lookAt = cameraPos + sightDirection;
+	upVector = sightDirection.cross(perpendicular(sightDirection));
+	
+	glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
+	glLoadIdentity();
+	
+	// Calculate The Aspect Ratio Of The Window
+	gluPerspective(45.0f,(GLfloat)WIDTH/(GLfloat)HEIGHT,0.5f,300.0f);
+	gluLookAt (cameraPos.x,cameraPos.y,cameraPos.z,
+			   lookAt.x,lookAt.y,lookAt.z,
+			   upVector.x,upVector.y,upVector.z);
+	
+	glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
+	glLoadIdentity(); // Reset The Modelview Matrix
+}
+
+void HeightMapViewer::drawScene()
+{	
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	glPushMatrix();
+	{
+		//glTranslatef(0.0,1.0,0.0);
+		glScalef(1,0.2,1);
+	
+		for (int i=0; i<terrain.displayListCount; i++)
+		{
+			glCallList(terrain.displayListStart + i);
+		}
+	}
+	glPopMatrix();
+	
+	glColor3f(0.0,1.0,0.0);
+	//	glutWireCube(1.0);
+	
+	glColor3f(0.0,0.0,1.0);
+	glBegin(GL_POINTS);
+	for (float z=0;z<10;z++)
+		for (float x=0;x<10;x++)
+			glVertex3f(x,0,z);
+	glEnd();
+	
+}
+
+
+
+/**
+   \brief returns a vector that is perpendicular and lies in the xz-plane
+ */
+Vector perpendicular (Vector perpendic)
+{
+	Vector r;
+	
+	r.x =  perpendic.z;
+	r.z = -perpendic.x;
+	
+	r.normalize();
+	
+	return r;	
+}
Index: /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapViewer.h
===================================================================
--- /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapViewer.h	(revision 3919)
+++ /orxonox/branches/heightMap/src/lib/graphics/importer/heightMapViewer.h	(revision 3919)
@@ -0,0 +1,60 @@
+/*
+ *  legotown.h
+ *  legotown3d
+ *
+ *  Created by Nico Bernold on 08.01.05.
+ *  Copyright 2005 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include <iostream>
+using namespace std;
+
+#include "heightMapTerrain.h"
+
+#include "windowHandler.h"
+#include "vector.h"
+
+#include "stdincl.h"
+
+
+#define WIDTH        640
+#define HEIGHT       480
+
+//#define WIDTH        1280
+//#define HEIGHT       854
+//#define FULLSCREEN
+
+
+class HeightMapViewer
+{
+ public:
+	HeightMapViewer();
+	~HeightMapViewer();
+	
+	bool init(char* fileName);
+	bool initLighting(void);
+	bool run();
+
+ private:		
+	void drawScene();
+	void updateView();
+	
+	WindowHandler windowhandler;
+	HeightMapTerrain terrain;	
+
+	bool wireframe;
+	bool mousedown;
+	bool smoothShading;
+
+	Vector cameraPos;
+	Vector sightDirection;
+	Vector lookAt;
+	Vector upVector;
+	
+	// used for some movement calculations
+	Vector perpendicularToSight;
+	Quaternion rotator;
+};
+
+Vector perpendicular (Vector perpendic);
Index: /orxonox/branches/heightMap/src/lib/graphics/importer/main.cc
===================================================================
--- /orxonox/branches/heightMap/src/lib/graphics/importer/main.cc	(revision 3919)
+++ /orxonox/branches/heightMap/src/lib/graphics/importer/main.cc	(revision 3919)
@@ -0,0 +1,28 @@
+#include <iostream>
+using namespace std;
+
+#include "heightMapViewer.h"
+
+int verbose = 3;
+
+int main(int argc, char *argv[])
+{
+	HeightMapViewer viewer;
+
+	if (argc <= 1)
+	{
+		cout << "specify a 8-bit greyscale bmp-file to load as argument!" << endl;
+		return -1;
+	}
+
+	// initialize
+	if (viewer.init(argv[1]) == false)
+	{
+		cout << "could not init. exiting." << endl;
+		return -1;
+	}
+	
+	viewer.run();
+	
+    return 0;
+}
