Index: branches/terrain/acinclude.m4
===================================================================
--- branches/terrain/acinclude.m4	(revision 8697)
+++ branches/terrain/acinclude.m4	(revision 8715)
@@ -105,4 +105,5 @@
       `ls -dr /usr/local/qt*/include   2>/dev/null`
       `ls -dr /opt/qt*/include         2>/dev/null`
+      `ls -dr /opt/local/include       2>/dev/null`
       `ls -dr /Developer/qt*/include   2>/dev/null`
       `ls -dr /c/Qt/*/include          2>/dev/null`
@@ -115,4 +116,5 @@
       `ls -dr /usr/local/qt*/lib       2>/dev/null`
       `ls -dr /opt/qt*/lib             2>/dev/null`
+      `ls -dr /opt/local/lib  		   2>/dev/null`
       `ls -dr /Developer/qt*/lib       2>/dev/null`
       `ls -dr /c/Qt/*/lib              2>/dev/null`
@@ -125,4 +127,5 @@
       `ls -dr /usr/local/qt*/bin       2>/dev/null`
       `ls -dr /opt/qt*/bin             2>/dev/null`
+      `ls -dr /opt/local/bin		      2>/dev/null`
       `ls -dr /Developer/qt*/bin       2>/dev/null`
       `ls -dr /c/Qt/*/bin              2>/dev/null`
@@ -175,6 +178,9 @@
     QT_LIBS=""
     QT_CXXFLAGS="-I${QT_INCLUDE_DIRECTORY}"
-    LDFLAGS="${LDFLAGS} -L${QT_LIB_DIRECTORY} -Wl,-rpath -Wl,${QT_LIB_DIRECTORY}"
-
+	 if test x$osX = xyes ; then
+		LDFLAGS="${LDFLAGS} -L${QT_LIB_DIRECTORY}"
+	 else
+    	LDFLAGS="${LDFLAGS} -L${QT_LIB_DIRECTORY} -Wl,-rpath -Wl,${QT_LIB_DIRECTORY}"
+	 fi
     CACHED_CPPFLAG=${CPPFLAGS}
     CACHED_LDFLAGS=${LDFLAGS}
@@ -190,11 +196,17 @@
     done
 
-    if [test "x$_lib_check" = "xyes"] ; then
-         QT_LIBS="${QT_LIBS} -l$_found_lib"
-         AX_CHECK_REQUIRED_LIB([QtCore QtCore4], [main],,,[http://www.trolltech.com] )
-         AX_CHECK_REQUIRED_LIB([QtGui QtGui4], [main],,,[http://www.trolltech.com] )
-         AX_CHECK_REQUIRED_LIB([QtOpenGL QtOpenGL4], [main],,,[http://www.trolltech.com] )
-
-         $3
+    if [test "x$_lib_check" = "xyes" || test "x$osX" = "xyes"] ; then
+			if [test x$osX = xyes] ; then
+# kraus: Need to add a check here. For the moment this just works fine...
+				QT_LIBS="${QT_LIBS} -framework QtCore -framework QtGui -framework QtOpenGL"
+				QT_LD_FLAGS="${QT_LD_FLAGS} -L${QT_LIB_DIRECTORY}"
+			else
+         	QT_LIBS="${QT_LIBS} -l$_found_lib"
+         	AX_CHECK_REQUIRED_LIB([QtCore QtCore4], [main],,,[http://www.trolltech.com] )
+         	AX_CHECK_REQUIRED_LIB([QtGui QtGui4], [main],,,[http://www.trolltech.com] )
+         	AX_CHECK_REQUIRED_LIB([QtOpenGL QtOpenGL4], [main],,,[http://www.trolltech.com] )
+
+         	$3
+			fi
     else
          echo "------------------"
@@ -205,5 +217,5 @@
          exit -1
     fi
-
+	 echo "configuration for qt: "
     echo "QT_LIBS          = ${QT_LIBS}"
     echo "QT_CXXFLAGS      = ${QT_CXXFLAGS}"
@@ -251,5 +263,5 @@
 dnl Check for Lua.
 
-LUA_INCLUDE_DIRECTORY="/usr/include"
+LUA_INCLUDE_DIRECTORY="/$prefix/include"
 LUA_COMMON_INCLUDE_DIRECTORIES="
       `ls -dr $1                       2>/dev/null`
@@ -259,4 +271,5 @@
       `ls -dr /usr/local/include/lua   2>/dev/null`
       `ls -dr /opt/lua*/include        2>/dev/null`
+      `ls -dr /opt/local/include       2>/dev/null`
       `ls -dr /Developer/lua*/include  2>/dev/null`
     "
@@ -276,5 +289,23 @@
     fi
 
-
+if [ test x$osX = xyes ] ; then
+	LUA_COMMON_LIB_DIRECTORIES="
+     	`ls -dr $1                    2>/dev/null`
+      /usr/lib
+      `ls -dr /usr/lib/lua*        2>/dev/null`
+      `ls -dr /usr/local/lib/lua   2>/dev/null`
+      `ls -dr /opt/lua*/lib        2>/dev/null`
+      `ls -dr /opt/local/lib       2>/dev/null`
+      `ls -dr /Developer/lua*/lib  2>/dev/null`
+	 "
+  for _lua_lib_directory in ${LUA_COMMON_LIB_DIRECTORIES}
+    do
+      if test -e ${_lua_lib_directory}/liblua.a  || test -e ${_lua_lib_directory}/liblua.dylib ; then
+        LUA_LIB_DIRECTORY=${_lua_lib_directory}
+        LDFLAGS="${LDFLAGS} -L${LUA_LIB_DIRECTORY} -llua"
+        break
+      fi
+  done	
+else
 AC_CHECK_LIB([dl], [dlopen])
 AX_CHECK_REQUIRED_HEADER_LIB([lua.h], [lua lua50], [lua_open],,,)
@@ -288,5 +319,5 @@
 #       [AX_GET_INSTALL_NECESSARY_LIB([http://www.lua.org/ftp], [lua-5.0.tar.gz], [lua-5.0], [extern_libs/], [include/*.h lib/*.a])
 #       LUA_LIBS="-llualib -llua"  LUA_INCLUDES="-I$(top_build_dir)/extern_libs" ], [http://www.lua.org])
-
+fi
 AC_SUBST([LUA_LIBS])
 AC_SUBST([LUA_INCLUDES])
Index: branches/terrain/configure.ac
===================================================================
--- branches/terrain/configure.ac	(revision 8697)
+++ branches/terrain/configure.ac	(revision 8715)
@@ -564,24 +564,24 @@
 #	QT_INCLUDE_DIR=`$PKG_CONFIG --variable=includedir QtOpenGL QtCore QtGui`
 #----------#
-	    AC_PATH_PROG([QT_MOC], [moc], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
-	      if test x${QT_MOC} = xno ; then
-	        AC_MSG_ERROR([QT MOC not found])
-	      fi
-	AC_SUBST([QT_MOC])
-
-	AC_PATH_PROG([QT_UIC], [uic], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
-	AC_SUBST([QT_UIC])
-
-	AC_PATH_PROG([QT_RCC], [rcc], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
-
-	AC_SUBST([QT_RCC])
-	AC_SUBST( QT_INCLUDE_DIR )
-	AC_SUBST( QT_CFLAGS )
-	AC_SUBST( QT_LDFLAGS )
-	AC_SUBST( QT_LIBS )
-	echo "QT_LIBS 			= $QT_LIBS"
-	echo "QT_CFLAGS 		= $QT_CFLAGS"
-	echo "QT_INCLUDE_DIR 	= $QT_INCLUDE_DIR"
-else
+#	    AC_PATH_PROG([QT_MOC], [moc], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
+#	      if test x${QT_MOC} = xno ; then
+#	        AC_MSG_ERROR([QT MOC not found])
+#	      fi
+#	AC_SUBST([QT_MOC])
+
+#	AC_PATH_PROG([QT_UIC], [uic], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
+#	AC_SUBST([QT_UIC])
+
+#	AC_PATH_PROG([QT_RCC], [rcc], [no], ["${QT_BIN_DIRECTORY}:${PATH}"])
+
+#	AC_SUBST([QT_RCC])
+#	AC_SUBST( QT_INCLUDE_DIR )
+#	AC_SUBST( QT_CFLAGS )
+#	AC_SUBST( QT_LDFLAGS )
+#	AC_SUBST( QT_LIBS )
+#	echo "QT_LIBS 			= $QT_LIBS"
+#	echo "QT_CFLAGS 		= $QT_CFLAGS"
+#	echo "QT_INCLUDE_DIR 	= $QT_INCLUDE_DIR"
+#else
 	AX_CHECK_QT([${QT_PREFIX}], [QtCore QtCore4],, [http://www.trolltech.com])
 	if test x$have_qt = xno ; then
@@ -622,6 +622,9 @@
 # FIXME: Replace `main' with a function in `-lm':
  AC_CHECK_LIB([m], [main])
- AX_CHECK_REQUIRED_HEADER_LIB([zlib.h], [z], [zlibVersion],,, [http://www.zlib.net])
-
+if test x$osX = xyes ; then
+	AC_CHECK_LIB( [z], [main], [LIBS="$LIBS -lz"] )
+else
+	AX_CHECK_REQUIRED_HEADER_LIB([zlib.h], [z], [zlibVersion],,, [http://www.zlib.net])
+fi
 # Checks for header files.
 AC_HEADER_STDC
@@ -632,7 +635,8 @@
 
 # Checks for library functions.
-AC_FUNC_MALLOC
-AC_CHECK_FUNCS([bzero sqrt])
-
+if test x$osX != xyes ; then 
+	AC_FUNC_MALLOC
+	AC_CHECK_FUNCS([bzero sqrt])
+fi
 ######################
 ## OUTPUT CONFIGURE ##
Index: branches/terrain/src/lib/collision_detection/cd_engine.cc
===================================================================
--- branches/terrain/src/lib/collision_detection/cd_engine.cc	(revision 8697)
+++ branches/terrain/src/lib/collision_detection/cd_engine.cc	(revision 8715)
@@ -24,5 +24,5 @@
 #include "model.h"
 #include "world_entity.h"
-#include "terrain.h"
+#include "terrain_entity.h"
 // #include "player.h"
 
@@ -104,15 +104,32 @@
   std::list<WorldEntity*>::iterator entityIterator;
   const std::list<BaseObject*>* bspList = ClassList::getList(CL_BSP_ENTITY);
-  if( bspList == NULL)
-    return;
+  if( bspList != NULL) {
 
-  // for all bsp managers check all entities
-  for( bspIterator = bspList->begin(); bspIterator != bspList->end(); bspIterator++) {
-      for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++)
-      {
-//         PRINTF(0)("Checking: %s a %s\n", (*entityIterator)->getName(), (*entityIterator)->getClassName());
-        (dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollision(*entityIterator);
+  	// for all bsp managers check all entities
+  	for( bspIterator = bspList->begin(); bspIterator != bspList->end(); bspIterator++) {
+      	for(entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++)
+      	{
+//        	 PRINTF(0)("Checking: %s a %s\n", (*entityIterator)->getName(), (*entityIterator)->getClassName());
+        	(dynamic_cast<BspEntity*>(*bspIterator)->getBspManager())->checkCollision(*entityIterator);
+      	}
+  	}
+	}
+	const std::list<BaseObject*>* tl = ClassList::getList( CL_TERRAIN );
+  std::list<BaseObject*>::const_iterator ti;	
+	if ( tl == NULL )
+		return;
+	for ( ti = tl->begin(); ti != tl->end(); ++ti ) {
+			TerrainEntity* terrain = dynamic_cast<TerrainEntity*>( *ti );
+      for( entityIterator = list1.begin(); entityIterator != list1.end(); entityIterator++ )
+   		{
+				const Vector& pos = (*entityIterator)->getAbsCoor();
+				
+				float height = terrain->getHeight( pos.x, pos.z );
+				printf( "pos.y-height: %f\n", pos.y-height );
+				if ( height > pos.y ) {
+					(*entityIterator)->setAbsCoor( pos.x, height, pos.z );
+				}
       }
-  }
+	}
 }
 
Index: branches/terrain/src/lib/graphics/effects/volfog_effect.cc
===================================================================
--- branches/terrain/src/lib/graphics/effects/volfog_effect.cc	(revision 8697)
+++ branches/terrain/src/lib/graphics/effects/volfog_effect.cc	(revision 8715)
@@ -30,5 +30,5 @@
 //#include <GL/glext.h> //OpenGL Extensions
 //#include <GL/glxext.h> // GLX Extensions
-
+#ifndef __APPLE__
 #ifndef GL_EXT_fog_coord
 #define GL_EXT_fog_coord 1
@@ -45,5 +45,5 @@
 PFNGLFOGCOORDDVEXTPROC glFogCoorddvEXT = 0;
 PFNGLFOGCOORDPOINTEREXTPROC glFogCoordPointerEXT = 0;
-
+#endif
 
 using namespace std;
Index: branches/terrain/src/lib/graphics/graphics_engine.cc
===================================================================
--- branches/terrain/src/lib/graphics/graphics_engine.cc	(revision 8697)
+++ branches/terrain/src/lib/graphics/graphics_engine.cc	(revision 8715)
@@ -298,6 +298,5 @@
   }
 
-  glEnable(GL_CULL_FACE);
-  glCullFace(GL_FRONT);
+
 }
 
Index: branches/terrain/src/lib/graphics/importer/Makefile.am
===================================================================
--- branches/terrain/src/lib/graphics/importer/Makefile.am	(revision 8697)
+++ branches/terrain/src/lib/graphics/importer/Makefile.am	(revision 8715)
@@ -38,5 +38,5 @@
                            md3/md3_data.cc \
                            md3/md3_tag.cc \
-			   \ 
+			   \
                            terrain/terrain.cc \
                            terrain/terrain_quad.cc \
Index: branches/terrain/src/lib/graphics/importer/md2/md2Model.cc
===================================================================
--- branches/terrain/src/lib/graphics/importer/md2/md2Model.cc	(revision 8697)
+++ branches/terrain/src/lib/graphics/importer/md2/md2Model.cc	(revision 8715)
@@ -17,5 +17,12 @@
 #include "md2Model.h"
 #include "material.h"
-
+#include "config.h"
+#ifdef HAVE_SDL_SDL_H
+#include <SDL/SDL.h>
+#include <SDL/SDL_endian.h>
+#else
+#include <SDL.h>
+#include <SDL_endian.h>
+#endif
 #include "debug.h"
 #include "util/loading/resource_manager.h"
@@ -66,5 +73,21 @@
   };
 
-
+#ifdef SDL_LIL_ENDIAN
+#define BULK_CONV( _ptr, _num ) do { \
+	int  _cnt = _num;\
+	int* _iptr = (int*)_ptr;\
+	for( int _l = 0; _l<_cnt; ++_l )\
+		_iptr[_l] = SDL_SwapLE32( _iptr[_l] );\
+} while( 0 )
+#define BULK_CONV16( _ptr, _num ) do { \
+	short  _cnt = _num;\
+	short* _iptr = (short*)_ptr;\
+	for( int _l = 0; _l<_cnt; ++_l )\
+		_iptr[_l] = SDL_SwapLE16( _iptr[_l] );\
+} while( 0 )
+#else
+#define BULK_CONV( _ptr, _num )
+#define BULK_CONV16( _ptr, _num )
+#endif
 
 /********************************************************************************
@@ -442,6 +465,7 @@
   this->header = new MD2Header;
   fread(this->header, 1, sizeof(MD2Header), pFile);
+	BULK_CONV( this->header, sizeof(MD2Header)/4 );
   /* check for the header version: make sure its a md2 file :) */
-  if( unlikely(this->header->version != MD2_VERSION) && unlikely(this->header->ident != MD2_IDENT))
+  if( unlikely( this->header->version != MD2_VERSION) && unlikely( this->header->ident != MD2_IDENT))
     {
       PRINTF(1)("Couldn't load file %s: invalid file format: stop loading\n", fileName.c_str());
@@ -449,5 +473,5 @@
     }
 
-  this->fileName =fileName;
+  this->fileName = fileName;
   /* got the data: map it to locals */
   this->numFrames = this->header->numFrames;
@@ -468,18 +492,26 @@
   fseek(pFile, this->header->offsetFrames, SEEK_SET);
   fread(buffer, this->header->frameSize, this->numFrames, pFile);
+	//BULK_CONV( buffer, this->header->frameSize*this->numFrames*sizeof(char)/4 );
   /* read opengl commands */
   fseek(pFile, this->header->offsetGlCommands, SEEK_SET);
+
   fread(this->pGLCommands, sizeof(int), this->numGLCommands, pFile);
+	BULK_CONV( this->pGLCommands, this->numGLCommands );
   /* triangle list */
   fseek(pFile, this->header->offsetTriangles, SEEK_SET);
-  fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);
+  fread(this->pTriangles, sizeof(sTriangle), this->numTriangles, pFile);	
+	BULK_CONV16( this->pTriangles, this->numTriangles*sizeof(sTriangle)/2 );
+
   /*  read in texture coordinates */
   fseek(pFile, this->header->offsetTexCoords, SEEK_SET);
   fread(this->pTexCoor, sizeof(sTexCoor), this->numTexCoor, pFile);
-
+	BULK_CONV16( this->pTexCoor, this->numTexCoor*sizeof(sTexCoor)/2 );
 
   for(int i = 0; i < this->numFrames; ++i)
     {
       frame = (sFrame*)(buffer + this->header->frameSize * i);
+			//Convert the translate and scale Vec3D if needed.
+			BULK_CONV( frame, 6 );
+			BULK_CONV( frame->pVertices, 3 );
       pVertex = this->pVertices + this->numVertices  * i;
       pNormals = this->pLightNormals + this->numVertices * i;
