Index: orxonox/branches/nico/src/heightMap/heightMapTerrain.cpp
===================================================================
--- orxonox/branches/nico/src/heightMap/heightMapTerrain.cpp	(revision 3381)
+++ orxonox/branches/nico/src/heightMap/heightMapTerrain.cpp	(revision 3381)
@@ -0,0 +1,126 @@
+/*
+ *  ldrawparser.cpp
+ *  legotown3d
+ *
+ *  Created by Nico Bernold on 08.01.05.
+ *  Copyright 2005 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "heightMapTerrain.h"
+
+HeightMapTerrain::HeightMapTerrain()
+{	
+}
+
+HeightMapTerrain::~HeightMapTerrain()
+{
+}
+
+bool HeightMapTerrain::loadBitmap(char* fileName)
+{
+	return bitmap = SDL_LoadBMP(fileName);	
+}
+
+bool HeightMapTerrain::createDisplayLists(int width, int height, int levelOfDetail)
+{
+	if (bitmap == NULL) return false;
+	
+	cout << "bitmap-dimensions: " << bitmap->w << "x" << bitmap->h << 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;
+	}
+
+	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)
+{
+	// y is the height value in OpenGL convention
+	GLuint x,y,z;
+	GLfloat col;
+	
+	cout << "creating list Nr " << displayListNr << endl;
+	cout << "left, top, width, height: " << left << ", " << top << ", " << width << ", " << height << endl; 
+	
+	glNewList(displayListNr,GL_COMPILE);
+	{
+		for (z=top; z<top+height; z++)
+		{
+			glBegin(GL_QUAD_STRIP);
+			{
+				for (x=left; x<left+width; x++)
+				{
+					y = heightValue(x,z+1);
+					col = y / 256.0;
+					glColor3f(1.0,0.0,0.0);
+					glVertex3i(x,y,z+1);
+					
+					y = heightValue(x,z);
+					col = y / 256.0;
+					glColor3f(1.0,0.0,0.0);
+					glVertex3i(x,y,z);
+				}
+			}
+			glEnd();
+		}
+		
+	}
+	glEndList();
+	
+	return true;
+}
+
+GLint HeightMapTerrain::heightValue(Uint8 x, Uint8 z)
+{
+	return 100;
+	
+	/*
+	if (bitmap == NULL) return 0;
+	
+	Uint8 index;
+	SDL_Color* color = NULL;
+	
+	
+	SDL_LockSurface(bitmap);
+	
+	index = *((Uint8*)bitmap->pixels[z * bitmap->h + x]);
+	color = &bitmap->format->palette->colors[index];
+	
+	SDL_UnlockSurface(bitmap);
+
+	return color->r;
+	 */
+}
Index: orxonox/branches/nico/src/heightMap/heightMapTerrain.h
===================================================================
--- orxonox/branches/nico/src/heightMap/heightMapTerrain.h	(revision 3381)
+++ orxonox/branches/nico/src/heightMap/heightMapTerrain.h	(revision 3381)
@@ -0,0 +1,49 @@
+/*
+ *  ldrawparser.h
+ *  legotown3d
+ *
+ *  Created by Nico Bernold on 08.01.05.
+ *  Copyright 2005 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include <iostream>
+using namespace std;
+
+#include "SDL.h"
+#include <GLUT/glut.h>
+
+#include "vector.h"
+
+
+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 heightValue(Uint8 x, Uint8 z);
+		
+	// holds the loaded pixels
+	SDL_Surface* bitmap;
+	
+
+	
+};
Index: orxonox/branches/nico/src/heightMap/heightMapViewer.cpp
===================================================================
--- orxonox/branches/nico/src/heightMap/heightMapViewer.cpp	(revision 3381)
+++ orxonox/branches/nico/src/heightMap/heightMapViewer.cpp	(revision 3381)
@@ -0,0 +1,204 @@
+/*
+ *  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;
+	
+}
+
+// destructor
+HeightMapViewer::~HeightMapViewer()
+{
+	cout << "HeightMapViewer::~HeightMapViewer()" << endl;
+}
+
+// main loop
+bool HeightMapViewer::init(char* fileName)
+{
+	cout << "HeightMapViewer init()" << endl;
+	
+	if (windowhandler.createOpenGLWindow(WIDTH,HEIGHT,FULLSCREEN) == false)
+	{
+		cout << "could not create OpenGL-Window." << endl;
+		return false;
+	}
+
+	if (terrain.loadBitmap(fileName) == false)
+	{
+		cout << "could not create OpenGL-Window." << endl;
+		return false;
+	}
+	
+	terrain.createDisplayLists(64, 64, 1);
+	
+	return true;
+}
+
+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)
+					{
+						angleX = PI / 180 * event.motion.xrel * 0.1;
+						angleY = PI / 180 * event.motion.yrel * 0.1;
+
+						// Quaternion(angle,axis)
+						rotator = Quaternion(angleX,Vector(0,1,0));
+						sightDirection = rotator.apply(sightDirection);
+						
+						rotator = Quaternion(-angleY,sightDirection.perpendicular());
+						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_w:
+							wireframe = !wireframe;
+							if (wireframe) glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
+							else glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
+							break;
+							
+						case SDLK_UP:
+							// move in direction of sight
+							cameraPos = cameraPos + sightDirection;
+							updateView();
+							break;
+
+						case SDLK_DOWN:
+							// move in direction of sight
+							cameraPos = cameraPos - sightDirection;
+							updateView();
+							break;
+							
+						case SDLK_LEFT:
+							cameraPos = cameraPos - sightDirection.perpendicular();
+							updateView();
+							break;
+							
+						case SDLK_RIGHT:
+							cameraPos = cameraPos + sightDirection.perpendicular();
+							updateView();
+							break;
+							
+						case SDLK_r:
+							// restore original view vectors
+							cameraPos = Vector(0,0,40);
+							sightDirection = Vector(0,0,-1);
+							updateView();
+							break;
+
+						case SDLK_h:
+							cout << "HELP\n"
+							<< "display list count:    " << terrain.displayListCount << endl
+							<< "first display list at: " << terrain.displayListStart << 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(100);
+	}
+	
+	return true;
+}
+
+void HeightMapViewer::updateView()
+{
+	// be sure to use up to date lookAt-vector
+	lookAt = cameraPos + sightDirection;
+	upVector = sightDirection.cross(sightDirection.perpendicular()) * -1;
+	
+	glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
+	glLoadIdentity();
+	
+	// Calculate The Aspect Ratio Of The Window
+	gluPerspective(45.0f,(GLfloat)WIDTH/(GLfloat)HEIGHT,0.1f,100.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);
+
+	glutWireCube(1.0);
+	
+	int i;
+	
+	for (i=0; i<terrain.displayListCount; i++)
+	{
+		glCallList(terrain.displayListStart + i);
+	}
+}
Index: orxonox/branches/nico/src/heightMap/heightMapViewer.h
===================================================================
--- orxonox/branches/nico/src/heightMap/heightMapViewer.h	(revision 3381)
+++ orxonox/branches/nico/src/heightMap/heightMapViewer.h	(revision 3381)
@@ -0,0 +1,59 @@
+/*
+ *  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 "SDL.h"
+#include <GLUT/glut.h>
+
+
+#define WIDTH        640
+#define HEIGHT       480
+#define FULLSCREEN   false
+
+/*
+#define WIDTH        1280
+#define HEIGHT       854
+#define FULLSCREEN   true
+*/
+
+class HeightMapViewer
+{
+public:
+	HeightMapViewer();
+	~HeightMapViewer();
+	
+	bool init(char* fileName);
+	bool run();
+
+private:		
+	void drawScene();
+	void updateView();
+	
+	WindowHandler windowhandler;
+	HeightMapTerrain terrain;	
+
+	bool wireframe;
+	bool mousedown;
+
+	Vector cameraPos;
+	Vector sightDirection;
+	Vector lookAt;
+	Vector upVector;
+	
+	// used for some movement calculations
+	Vector perpendicularToSight;
+	Quaternion rotator;
+};
Index: orxonox/branches/nico/src/heightMap/main.cpp
===================================================================
--- orxonox/branches/nico/src/heightMap/main.cpp	(revision 3381)
+++ orxonox/branches/nico/src/heightMap/main.cpp	(revision 3381)
@@ -0,0 +1,29 @@
+#include <iostream>
+using namespace std;
+
+#include "heightMapViewer.h"
+
+#include "SDL.h"
+
+
+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;
+}
