Index: branches/terrain/src/lib/graphics/importer/md3/md3_data.h
===================================================================
--- branches/terrain/src/lib/graphics/importer/md3/md3_data.h	(revision 8775)
+++ branches/terrain/src/lib/graphics/importer/md3/md3_data.h	(revision 8929)
@@ -70,5 +70,4 @@
 
 
-
 //! class to store the md2 data in
 class MD3Data : public BaseObject
Index: branches/terrain/src/lib/graphics/importer/terrain/terrain.cc
===================================================================
--- branches/terrain/src/lib/graphics/importer/terrain/terrain.cc	(revision 8775)
+++ branches/terrain/src/lib/graphics/importer/terrain/terrain.cc	(revision 8929)
@@ -171,9 +171,84 @@
 }
 
+void Terrain::tick( float _dt )
+{
+	for ( unsigned int i = 0; i < buffers.size(); ++i )
+		broker->release( buffers[i].vbIdentifier, buffers[i].ibIdentifier );
+	buffers.clear();	
+	pTerrainPage page = NULL;
+	//Extract the frustum planes out of the modelview matrix.
+	frustum->extractPlanes();	
+	// Lets see which pages are visible.
+	determineVisiblePages( root );
+	int wantedLeft, wantedRight, wantedBottom, wantedTop, minLOD;
+	pTerrainPage neighbor = NULL;
+	page = activePages;
+	bool dirty;
+	current = 0;
+	BufferInfo bi;
+	broker->acquire( bi.vbIdentifier, bi.ibIdentifier );
+	buffers.push_back( bi );
+	int dirtyRounds = 0;
+	do {
+		dirtyRounds++;
+		dirty = false;
+		page = activePages;
+		while ( page ) {
+			if ( !page->isActive() ) {
+				pTerrainPage tmp = page;
+				page = tmp->getNext();
+				tmp->setVisibility( false );
+				continue;
+			}
+			wantedLeft = wantedRight = wantedBottom = wantedTop = page->getWantedLOD();
+			if ( ( neighbor = page->getLeft() ) && ( neighbor->isActive() ) ) 
+				wantedLeft = neighbor->getWantedLOD();
+			if ( ( neighbor = page->getRight() ) && ( neighbor->isActive() ) ) 
+				wantedRight = neighbor->getWantedLOD();
+			if ( ( neighbor = page->getTop() ) && ( neighbor->isActive() ) ) 
+				wantedTop = neighbor->getWantedLOD();
+			if ( ( neighbor = page->getBottom() ) && ( neighbor->isActive() ) ) 
+				wantedBottom = neighbor->getWantedLOD();			
+		
+			minLOD = std::min( std::min( wantedBottom, wantedTop ), 
+				std::min( wantedLeft, wantedRight ) );	
+			if ( minLOD < page->getWantedLOD()-1 ) {
+				page->setWantedLOD( minLOD+1 );
+				dirty = true;
+			}	
+			page = page->getNext();
+		}
+	} while ( dirty );
+	
+	page = activePages;
+	while ( page ) {
+		assert( page->isActive() );
+		page->updateTesselation();
+		page = page->getNext();
+	}
+	//If there is some data in the buffer, we need to upload the data
+	//into the vram...
+	if ( buffers[current].numIndices != 0 ) {
+		BufferInfo bi = buffers[current];	
+		glBindBufferARB( GL_ARRAY_BUFFER_ARB, bi.vbIdentifier );
+		glBufferDataARB( GL_ARRAY_BUFFER_ARB, MAX_VERTICES*sizeof( Vertex ), 
+			vertices, GL_DYNAMIC_DRAW_ARB );
+		glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, bi.ibIdentifier );
+		glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ), 
+			indices, GL_DYNAMIC_DRAW_ARB );
+	}	
+}
 void Terrain::draw( )
 {
+	pTerrainPage page = NULL;
 	glGetError();
-	pTerrainPage page = NULL;
-	frustum->extractPlanes();
+	/*pTerrainPage page = NULL;
+	frustum->extractPlanes();*/
+	Plane far = frustum->getPlane( Frustum::FAR );
+	//Due to some reason, the OpenGL implementors chose the plane equation
+	//to an array of doubles. So we will make them happy.
+	double farPlane[] = { far.n.x, far.n.y, far.n.z, far.d };
+	glEnable( GL_CLIP_PLANE0 );
+	glClipPlane( GL_CLIP_PLANE0, farPlane );
 	glPushAttrib( GL_ALL_ATTRIB_BITS );
 	glPushClientAttrib( GL_CLIENT_VERTEX_ARRAY_BIT );
@@ -198,5 +273,5 @@
 	cullCount = 0;
 	
-	// Lets see which pages are visible.
+	/*// Lets see which pages are visible.
 	determineVisiblePages( root );
 	int wantedLeft, wantedRight, wantedBottom, wantedTop, minLOD;
@@ -256,5 +331,5 @@
 		glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, MAX_INDICES*sizeof( short ), 
 			indices, GL_DYNAMIC_DRAW_ARB );
-	}
+	}*/
 	glEnable( GL_BLEND );
 	glDepthFunc( GL_LEQUAL );
@@ -312,12 +387,6 @@
 			page = page->getNext();
 		}
-		activatedCount = 0; deactivatedCount = 0;
-	}
-	
-	for ( unsigned int i = 0; i < buffers.size(); ++i )
-		broker->release( buffers[i].vbIdentifier, buffers[i].ibIdentifier );
-		
-	buffers.clear();
-		
+	}
+			
 	glClientActiveTextureARB( GL_TEXTURE1_ARB );	
 	glActiveTextureARB( GL_TEXTURE1_ARB );
@@ -329,4 +398,5 @@
 	glPopAttrib();
 	glPopClientAttrib();
+	glDisable( GL_CLIP_PLANE0 );
 }
 
@@ -429,7 +499,7 @@
 		//not the whole cross products needs to be calculated. Grab yourself
 		//pen and paper :)
-		_normal.x = -dZ*( alt[0] - alt[1] );				
-		_normal.y = -dZ*dX;
-		_normal.z =  dX*( alt[2] - alt[1] );
+		_normal.x =  dZ*( alt[0] - alt[1] );				
+		_normal.y =  dZ*dX;
+		_normal.z = -dX*( alt[2] - alt[1] );
 	}
 	else {
@@ -442,7 +512,7 @@
 		//not the whole cross products needs to be calculated. Grab yourself
 		//pen and paper :)
-		_normal.x =  dZ*( alt[2] - alt[1] );				
-		_normal.y = -dZ*dX;
-		_normal.z = -dX*( alt[0] - alt[1] );
+		_normal.x = -dZ*( alt[2] - alt[1] );				
+		_normal.y =  dZ*dX;
+		_normal.z =  dX*( alt[0] - alt[1] );
 	}
 }
Index: branches/terrain/src/lib/graphics/importer/terrain/terrain.h
===================================================================
--- branches/terrain/src/lib/graphics/importer/terrain/terrain.h	(revision 8775)
+++ branches/terrain/src/lib/graphics/importer/terrain/terrain.h	(revision 8929)
@@ -117,5 +117,5 @@
 		
 		void build();
-		
+		void tick( float _dt );
 		inline void setActiveList( pTerrainPage _page )
 		{
Index: branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc
===================================================================
--- branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc	(revision 8775)
+++ branches/terrain/src/lib/graphics/importer/terrain/terrain_page.cc	(revision 8929)
@@ -138,5 +138,4 @@
 		float d = distance.length();
 		
-		assert( d > 0.000001f );
 		float err =  errors[i].diff / d ;
 		
