Index: trunk/VUT/work/IVReader/include/ivmanualmeshloader.h
===================================================================
--- trunk/VUT/work/IVReader/include/ivmanualmeshloader.h	(revision 183)
+++ trunk/VUT/work/IVReader/include/ivmanualmeshloader.h	(revision 183)
@@ -0,0 +1,24 @@
+#ifndef __IVManualMeshLoader_H__
+#define __IVManualMeshLoader_H__
+
+
+#include "ogre.h"
+#include "ivmeshdata.h"
+
+
+class __declspec(dllexport) IVManualMeshLoader: public Ogre::ManualResourceLoader
+{
+	public:
+		IVManualMeshLoader();
+		IVManualMeshLoader(IVMeshData *mData);
+		~IVManualMeshLoader(); 
+
+		void loadResource(Ogre::Resource *resource);
+
+		Ogre::AxisAlignedBox *getBoundingBox();
+	private:
+		IVMeshData *data;
+
+};
+
+#endif
Index: trunk/VUT/work/IVReader/include/ivreader.h
===================================================================
--- trunk/VUT/work/IVReader/include/ivreader.h	(revision 183)
+++ trunk/VUT/work/IVReader/include/ivreader.h	(revision 183)
@@ -0,0 +1,130 @@
+#ifndef __IVReader_H__
+#define __IVReader_H__
+
+
+#include "ivnode.h"
+#include "ivmeshdata.h"
+#include "ivmanualmeshloader.h"
+#include "ogre.h"
+
+#define COMMENTCHAR '#'
+#define BLOCKSIZE 150
+#define BUFFERSIZE 256
+
+
+static const int validIVHeaderCnt = 2;
+
+static const char *validIVHeader[2] = {
+    { "#Inventor V2.1 ascii\n" },
+	{ "#VRML V1.0 ascii\n" },
+};
+
+
+enum IVTokenType
+{
+	IV_TOKEN_INVALID = -1,
+	IV_TOKEN_STRING = 0,
+	IV_TOKEN_INT = 1,
+	IV_TOKEN_REAL = 2,
+	IV_TOKEN_BRACEOPEN = 3,				// {
+	IV_TOKEN_BRACECLOSE = 4,			// }
+	IV_TOKEN_BRACKETOPEN = 5,			// [
+	IV_TOKEN_BRACKETCLOSE = 6,			// ]
+	IV_TOKEN_PARENTHESISOPEN = 7,		// (
+	IV_TOKEN_PARENTHESISCLOSE = 8,		// )
+	IV_TOKEN_DEF = 9,					// DEF
+	IV_TOKEN_USE = 10,					// USE
+};
+
+class __declspec(dllexport) IVMeshListNode
+{
+	public:
+		IVMeshListNode(std::string name, IVManualMeshLoader *loader);
+		~IVMeshListNode();
+
+		void attachNewNode(std::string name, IVManualMeshLoader *loader);
+
+		IVManualMeshLoader *getManualMeshLoader(std::string name);
+
+		IVMeshListNode *next;
+
+	private:
+		std::string name;
+		IVManualMeshLoader *loader;
+};
+
+class __declspec(dllexport) IVDefListNode
+{
+	public:
+		IVDefListNode(std::string name, IVNode *node);
+		~IVDefListNode();
+
+		void attachNewNode(std::string name, IVNode *node);
+
+		IVNode *getDef(std::string name);
+
+		IVDefListNode *next;
+
+	private:
+		std::string name;
+		IVNode *node;
+
+};
+
+class __declspec(dllexport) IVReader
+{
+	public:
+		IVReader();
+		~IVReader();
+
+		void setLog(Ogre::Log *IVLog = NULL);
+
+		bool loadFile(const char* filename);
+		void print();
+//		IVNode *getNode(const char* name);
+
+
+		void buildTree(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *sceneNodeRoot);
+
+		void collapse();
+
+		static std::string intToStr(int num);
+		static std::string realToStr(Ogre::Real num);
+		
+		static Ogre::Log *IVLog;
+
+	private:
+		bool checkHeader(const char *string);
+		char buf[BUFFERSIZE];
+		int bufOffset;
+		bool getNextElement(char *token, IVTokenType *type);
+		void classify(char *token, IVTokenType *type);
+
+		bool isSpace(char c);
+		bool isNewline(char c);
+		bool eof;
+		bool isDigit(char c);
+		bool isHexDigit(char c);
+
+		IVNode *root;
+		FILE* infile;
+
+		static IVMeshListNode *meshList;
+		static void addMeshToList(std::string name, IVManualMeshLoader *loader);
+		
+		static int instanceCnt;
+
+		int treeCnt, nodeCnt, matCnt;
+		char *fileName;
+
+		Ogre::Entity *createEntity(Ogre::SceneManager* sceneMgr, std::string name, IVMeshData *mData, Ogre::Vector3 *translation = NULL);
+
+		void buildTree(Ogre::SceneManager *sceneMgr, Ogre::SceneNode *sceneNodeRoot, IVNode *ivRoot, IVMeshData *mData = NULL, Ogre::Material *material = NULL);
+
+		IVDefListNode *defList;
+		void addDefToList(std::string name, IVNode *node);
+
+};
+
+
+#endif
Index: trunk/VUT/work/IVReader/include/ivnode.h
===================================================================
--- trunk/VUT/work/IVReader/include/ivnode.h	(revision 183)
+++ trunk/VUT/work/IVReader/include/ivnode.h	(revision 183)
@@ -0,0 +1,59 @@
+#ifndef __IVNode_H__
+#define __IVNode_H__
+
+
+#include <string.h>
+#include <Ogre.h>
+
+enum IVType
+{
+	IV_INVALID = -1,
+	IV_STRING = 0,
+	IV_INT = 1,
+	IV_REAL = 2
+};
+
+
+class IVField
+{
+public:
+	IVField();
+	~IVField();
+
+	char *name;
+	void *value;
+	IVType typ;
+	int cnt;
+	IVField *next;
+};
+
+class __declspec(dllexport) IVNode
+{
+	public:
+		IVNode();
+		IVNode(const char *s);
+		~IVNode();
+
+		void print(int ident=0);
+		void attachNode(IVNode *child);
+		void addField(const char *name, char *value);
+		void addField(const char *name, void *value, int cnt, IVType typ);
+
+		IVNode *getParent() { return parent; }
+		char *getName() { return name; }
+		IVNode *getNodeRecursive(const char *name);
+		IVNode *getNextChildNode(bool reset = false);
+		IVField *getField(const char *name);
+		void *getField(const char *name, IVType *typ, int *cnt);
+
+	private:
+		char *name;
+		IVField *fields;
+		IVNode *parent;
+		IVNode *children;
+		IVNode *next;
+
+		IVNode *actual;
+};
+
+#endif
Index: trunk/VUT/work/IVReader/include/ivmeshdata.h
===================================================================
--- trunk/VUT/work/IVReader/include/ivmeshdata.h	(revision 183)
+++ trunk/VUT/work/IVReader/include/ivmeshdata.h	(revision 183)
@@ -0,0 +1,43 @@
+#ifndef __IVMeshData_H__
+#define __IVMeshData_H__
+
+
+#include <Ogre.h>
+
+enum IVRenderOperationType
+{
+	IV_ROT_INVALID = -1,
+	IV_ROT_TRIANGLE_STRIP = 1,
+	IV_ROT_TRIANGLE_LIST = 3,
+	IV_ROT_FACE_SET = 4,
+};
+
+class __declspec(dllexport) IVMeshData
+{
+	public:	
+		IVMeshData();
+		~IVMeshData();
+
+		IVMeshData *expand();
+
+		void collapse();
+		
+		Ogre::Real *vertices, *normals, *texCoords, *indices, *normalIndices, *texCoordIndices;
+		int vcnt, ncnt, tcnt, icnt, nicnt, ticnt;
+		IVRenderOperationType roType;
+		Ogre::AxisAlignedBox *boundingBox;
+
+	private:
+		int getSeparatorCnt(Ogre::Real *data, int end);
+
+		Ogre::Real *expandTriangleStripIndices(Ogre::Real *indices, int icnt, int *icntOut);
+		Ogre::Real *expandFaceSetIndices(Ogre::Real *indices, int icnt, int *icntOut);
+
+		int getNextFaceSize(int start);
+
+		Ogre::AxisAlignedBox *calcBoundingBox();
+
+
+};
+
+#endif
Index: trunk/VUT/work/IVReader/scripts/IVReader.vcproj
===================================================================
--- trunk/VUT/work/IVReader/scripts/IVReader.vcproj	(revision 183)
+++ trunk/VUT/work/IVReader/scripts/IVReader.vcproj	(revision 183)
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="IVReader"
+	ProjectGUID="{7319E499-473D-4CE5-9983-725D6E68A55D}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="Debug"
+			IntermediateDirectory="Debug"
+			ConfigurationType="2"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;IVREADER_EXPORTS"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="1"
+				UsePrecompiledHeader="3"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				OutputFile="$(OutDir)/IVReader.dll"
+				LinkIncremental="2"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/IVReader.pdb"
+				SubSystem="2"
+				ImportLibrary="$(OutDir)/IVReader.lib"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="..\lib\$(ConfigurationName)"
+			IntermediateDirectory="..\obj\$(ConfigurationName)"
+			ConfigurationType="2"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories="&quot;$(OGRE_PATH)\Dependencies\include\CEGUI&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;&quot;$(OGRE_PATH)\Dependencies\include&quot;;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;..\include"
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;IVREADER_EXPORTS;GTP_VISIBILITY_MODIFIED_OGRE"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="OgreMain.lib CEGUIBase.lib OgreGUIRenderer.lib"
+				OutputFile="$(OutDir)/IVReader.dll"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib&quot;;&quot;..\..\GtpVisibility\lib\$(ConfigurationName)&quot;;&quot;..\..\lib\$(ConfigurationName)&quot;;&quot;..\lib\$(ConfigurationName)&quot;;&quot;$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)&quot;"
+				GenerateDebugInformation="TRUE"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				ImportLibrary="$(OutDir)/IVReader.lib"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"
+				CommandLine="copy $(OutDir)\$(TargetFileName) $(OGRE_PATH)\Samples\Common\bin\$(ConfigurationName)"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+			UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+			<File
+				RelativePath="..\src\ivmanualmeshloader.cpp">
+			</File>
+			<File
+				RelativePath="..\src\ivmeshdata.cpp">
+			</File>
+			<File
+				RelativePath="..\src\ivnode.cpp">
+			</File>
+			<File
+				RelativePath="..\src\ivreader.cpp">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl;inc;xsd"
+			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+			<File
+				RelativePath="..\include\ivmanualmeshloader.h">
+			</File>
+			<File
+				RelativePath="..\include\ivmeshdata.h">
+			</File>
+			<File
+				RelativePath="..\include\ivnode.h">
+			</File>
+			<File
+				RelativePath="..\include\ivreader.h">
+			</File>
+		</Filter>
+		<File
+			RelativePath=".\ReadMe.txt">
+		</File>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
Index: trunk/VUT/work/IVReader/src/ivmanualmeshloader.cpp
===================================================================
--- trunk/VUT/work/IVReader/src/ivmanualmeshloader.cpp	(revision 183)
+++ trunk/VUT/work/IVReader/src/ivmanualmeshloader.cpp	(revision 183)
@@ -0,0 +1,154 @@
+#include "ivmanualmeshloader.h"
+#include "IVReader.h"
+
+IVManualMeshLoader::IVManualMeshLoader()
+{
+	data = NULL;
+}
+
+
+IVManualMeshLoader::IVManualMeshLoader(IVMeshData *mData)
+{
+	data = mData;
+/*	data = new IVMeshData();
+	if ((mData->indices != NULL) && (mData->icnt > 0))
+	{
+		data->icnt = mData->icnt;
+		data->indices = new Ogre::Real[mData->icnt];
+		memcpy(data->indices, mData->indices, mData->icnt*sizeof(Ogre::Real));
+	}
+	if ((mData->vertices != NULL) && (mData->vcnt > 0))
+	{
+		data->vcnt = mData->vcnt;
+		data->vertices = new Ogre::Real[mData->vcnt];
+		memcpy(data->vertices, mData->vertices, mData->vcnt*sizeof(Ogre::Real));
+	}
+	if ((mData->normals != NULL) && (mData->vcnt > 0))
+	{
+		data->ncnt = mData->ncnt;
+		data->normals = new Ogre::Real[mData->ncnt];
+		memcpy(data->normals, mData->normals, mData->ncnt*sizeof(Ogre::Real));
+	}
+	if ((mData->texCoords != NULL) && (mData->tcnt > 0))
+	{
+		data->tcnt = mData->tcnt;
+		data->texCoords = new Ogre::Real[mData->tcnt];
+		memcpy(data->texCoords, mData->texCoords, mData->tcnt*sizeof(Ogre::Real));
+	}
+	*/
+}
+
+IVManualMeshLoader::~IVManualMeshLoader()
+{
+/*	if (data != NULL)
+	{
+		if (data->vertices != NULL)		delete [] data->vertices;
+		if (data->normals != NULL)		delete [] data->normals;
+		if (data->texCoords != NULL)	delete [] data->texCoords;
+		if (data->indices != NULL)		delete [] data->indices;
+		delete data;
+	}
+	*/
+	if (data != NULL)
+	{
+		data->collapse();
+		delete data;
+	}
+}
+
+
+Ogre::AxisAlignedBox *IVManualMeshLoader::getBoundingBox()
+{
+	return data->boundingBox;
+}
+
+void IVManualMeshLoader::loadResource(Ogre::Resource *resource)
+{
+	using namespace Ogre;
+	Mesh *pMesh = (Mesh *) resource;
+
+
+	Vector3 translation = data->boundingBox->getCenter();
+
+	bool nOk = ((data->normals != NULL) && (data->ncnt > 0));
+	bool tOk = ((data->texCoords != NULL) && (data->tcnt > 0));
+	
+	pMesh->sharedVertexData = new VertexData(); 
+
+	VertexDeclaration* vertexDecl = pMesh->sharedVertexData->vertexDeclaration; 
+
+	size_t currOffset = 0; 
+	vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_POSITION); 
+	currOffset += VertexElement::getTypeSize(VET_FLOAT3); 
+	if (nOk)
+	{
+		vertexDecl->addElement(0, currOffset, VET_FLOAT3, VES_NORMAL); 
+		currOffset += VertexElement::getTypeSize(VET_FLOAT3); 
+	}
+    if (tOk)
+	{
+		vertexDecl->addElement(0, currOffset, VET_FLOAT2, VES_TEXTURE_COORDINATES); 
+		currOffset += VertexElement::getTypeSize(VET_FLOAT2); 
+	}
+
+	pMesh->sharedVertexData->vertexCount = data->vcnt/3; 
+	HardwareVertexBufferSharedPtr vbuf = 
+		HardwareBufferManager::getSingleton(). 
+		createVertexBuffer(vertexDecl->getVertexSize(0), pMesh->sharedVertexData->vertexCount, 
+			HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); 
+
+	VertexBufferBinding* binding = pMesh->sharedVertexData->vertexBufferBinding; 
+	binding->setBinding(0, vbuf); 
+
+	Real* pVertices = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); 
+
+	int offset = 0, size = 3;
+	if (nOk) size += 3;
+	if (tOk) size += 2;
+	for (int i=0; i<data->vcnt/3; i++) 
+	{
+		pVertices[i*size]   = data->vertices[i*3]   - translation.x;
+		pVertices[i*size+1] = data->vertices[i*3+1] - translation.y;
+		pVertices[i*size+2] = data->vertices[i*3+2] - translation.z;
+
+		offset = 3;
+		if (nOk)
+		{
+			pVertices[i*size+offset] = data->normals[i*3];	 offset++;
+			pVertices[i*size+offset] = data->normals[i*3+1]; offset++;
+			pVertices[i*size+offset] = data->normals[i*3+2]; offset++;
+		}
+		if (tOk)
+		{
+			pVertices[i*size+offset] = data->texCoords[i*2];   offset++;
+			pVertices[i*size+offset] = -data->texCoords[i*2+1]; offset++;
+		}
+	}
+
+	vbuf->unlock(); 
+
+
+	SubMesh *pSub = pMesh->createSubMesh(); 
+	pSub->operationType = RenderOperation::OT_TRIANGLE_LIST; //;data->roType;
+	pSub->useSharedVertices = true; 
+
+	pSub->indexData->indexCount = data->icnt; 
+	pSub->indexData->indexBuffer = HardwareBufferManager::getSingleton(). 
+		createIndexBuffer(HardwareIndexBuffer::IT_16BIT, 
+			pSub->indexData->indexCount, HardwareBuffer::HBU_STATIC_WRITE_ONLY, false); 
+
+	HardwareIndexBufferSharedPtr ibuf = pSub->indexData->indexBuffer; 
+	unsigned short* pIndices = static_cast<unsigned short*>(ibuf->lock(HardwareBuffer::HBL_DISCARD)); 
+
+	for (i = 0; i < data->icnt; i++) pIndices[i] = data->indices[i];
+	
+	ibuf->unlock(); 
+		
+	AxisAlignedBox bb(data->boundingBox->getMinimum() - translation, data->boundingBox->getMaximum() - translation);
+	pMesh->_setBounds(bb); 
+	Real radius = data->boundingBox->getMinimum().length();
+	if (data->boundingBox->getMaximum().length() > radius) radius = data->boundingBox->getMaximum().length();
+	pMesh->_setBoundingSphereRadius(radius); 
+
+}
+
Index: trunk/VUT/work/IVReader/src/ivreader.cpp
===================================================================
--- trunk/VUT/work/IVReader/src/ivreader.cpp	(revision 183)
+++ trunk/VUT/work/IVReader/src/ivreader.cpp	(revision 183)
@@ -0,0 +1,772 @@
+#include "ivreader.h"
+#include <string>
+#include <stdlib.h>
+#include <sstream>
+
+IVMeshListNode *IVReader::meshList = NULL;
+int IVReader::instanceCnt = 0;
+Ogre::Log *IVReader::IVLog = NULL;
+
+
+
+IVMeshListNode::IVMeshListNode(std::string name, IVManualMeshLoader *loader)
+{
+	this->name = name;
+	this->loader = loader;
+	next = NULL;
+}
+
+IVMeshListNode::~IVMeshListNode()
+{
+	if (loader != NULL) delete loader;
+}
+
+void IVMeshListNode::attachNewNode(std::string name, IVManualMeshLoader *loader)
+{
+	IVMeshListNode *help = this;
+
+	while (help->next != NULL) help = help->next;
+	help->next = new IVMeshListNode(name, loader);
+}
+
+IVManualMeshLoader *IVMeshListNode::getManualMeshLoader(std::string name)
+{
+	IVMeshListNode *help = this;
+	if (help->name == name) return help->loader;
+	while (help->next != NULL) 
+	{
+		help = help->next;
+		if (help->name == name) return help->loader;
+	}
+	return NULL;
+}
+
+IVDefListNode::IVDefListNode(std::string name, IVNode *node)
+{
+	this->name = name;
+	this->node = node;
+	next = NULL;
+}
+
+IVDefListNode::~IVDefListNode()
+{
+}
+
+void IVDefListNode::attachNewNode(std::string name, IVNode *node)
+{
+	IVDefListNode *help = this;
+
+	while (help->next != NULL) help = help->next;
+	help->next = new IVDefListNode(name, node);
+}
+
+IVNode *IVDefListNode::getDef(std::string name)
+{
+	IVDefListNode *help = this;
+	if (help->name == name) return help->node;
+	while (help->next != NULL) 
+	{
+		help = help->next;
+		if (help->name == name) return help->node;
+	}
+	return NULL;
+}
+
+IVReader::IVReader()
+{	
+	root = NULL; meshList = NULL; defList = NULL; fileName = NULL;
+	instanceCnt++;
+	IVLog = NULL;
+}
+
+IVReader::~IVReader()
+{
+	collapse();
+
+	instanceCnt--;
+	if (instanceCnt == 0) if (meshList != NULL) 
+	{	
+		IVMeshListNode *help = meshList, *delme = NULL;
+		while (help->next != NULL)
+		{
+			delme = help; help = help->next; delete delme;
+		}
+		delete help;
+	}
+}
+
+void IVReader::collapse()
+{
+	if (root != NULL) {	delete root; root = NULL; }
+	if (defList != NULL)
+	{	
+		IVDefListNode *help = defList, *delme = NULL;
+		while (help->next != NULL)
+		{
+			delme = help; help = help->next; delete delme;
+		}
+		delete help;
+		defList = NULL;
+	}
+	if (this->fileName != NULL) { delete [] this->fileName; this->fileName = NULL; }
+
+}
+
+void IVReader::setLog(Ogre::Log *IVLog)
+{
+	this->IVLog = IVLog;
+}
+
+std::string IVReader::intToStr(int num)
+{
+	std::ostringstream myStream; 
+	myStream << num;
+	myStream.flush();
+	
+	return(myStream.str());
+}
+
+std::string IVReader::realToStr(Ogre::Real num)
+{
+	std::ostringstream myStream; 
+	myStream << num;
+	myStream.flush();
+	
+	return(myStream.str());
+}
+
+bool IVReader::loadFile(const char* fileName)
+{
+	std::string message = "trying to load "; message = message + fileName + "...";
+	
+	if (IVLog != NULL) 
+		IVLog->logMessage(message);
+	
+	collapse();
+	this->fileName = new char[strlen(fileName)+1]; strcpy(this->fileName, fileName);
+	treeCnt = 0;
+
+    infile = fopen(fileName, "r"); root = NULL;
+
+	if (infile == NULL)
+	{
+		message = "! Error loading File "; message = message + fileName + " !";
+		if (IVLog != NULL) IVLog->logMessage(message);
+		return false;
+	}
+
+	if ((fgets(buf, BUFFERSIZE, infile) == NULL) && !feof(infile)) 
+	{
+		message = "! Error loading File "; message = message + fileName + " !";
+		if (IVLog != NULL) IVLog->logMessage(message);
+		fclose(infile);
+		return false;
+	}
+
+	if (!checkHeader(buf)) 
+	{
+		message = "! Invalid Header !";
+		if (IVLog != NULL) IVLog->logMessage(message);
+		fclose(infile);
+		return false;
+	}
+
+	IVTokenType tmptyp = IV_TOKEN_INVALID;
+	eof = false;	
+
+	bufOffset = 0;
+	char token[BUFFERSIZE] = "\0", oldtoken[BUFFERSIZE] = "\0", fieldtoken[BUFFERSIZE] = "\0";
+	int level = 0; 
+
+	while (getNextElement(token, &tmptyp)) 
+	{
+		if (tmptyp == IV_TOKEN_BRACEOPEN) 
+		{
+			root = new IVNode(oldtoken);
+			level++;
+			break;
+		}
+
+		strcpy(oldtoken, token);
+	}
+
+	IVNode *actualNode = root, *parent = root, *fieldNode = root, *newNode = NULL;
+	IVTokenType oldtmptyp = tmptyp;
+	bool textfield = false, realfield = false; IVType fieldtyp = IV_INVALID;
+	bool def = false; std::string defLabel;
+	Ogre::Real rblock[BLOCKSIZE]; 
+	float *rvalues;
+	int cnt = 0; int blockcnt = 0;
+	while (getNextElement(token, &tmptyp))
+	{
+		if ((tmptyp == IV_TOKEN_BRACKETOPEN)) 
+			if (!getNextElement(token, &tmptyp)) break;
+		if ((tmptyp == IV_TOKEN_INVALID)) 
+			if (!getNextElement(token, &tmptyp)) break;
+		if (tmptyp == IV_TOKEN_BRACEOPEN) 
+		{
+			actualNode = new IVNode(oldtoken); 
+			if (parent == NULL)
+			{
+				message = "Error loading file "; message = message + fileName + "! Invalid tree structure.";
+				if (IVLog != NULL) IVLog->logMessage(message);
+				fclose(infile);
+				return false;
+			}
+			parent->attachNode(actualNode);
+			parent = actualNode;
+			level++;
+
+			if (def)
+			{
+				addDefToList(defLabel, actualNode);
+				def = false;
+			}
+
+		} else
+		if (tmptyp == IV_TOKEN_BRACECLOSE) 
+		{
+			if (realfield)
+			{
+				if (blockcnt == 0) rvalues = (Ogre::Real *)malloc((cnt)*sizeof(Ogre::Real));
+				else rvalues = (Ogre::Real *)realloc(rvalues, (BLOCKSIZE*(blockcnt) + cnt)*sizeof(Ogre::Real));						
+				memcpy((void *)&rvalues[BLOCKSIZE*blockcnt], rblock, cnt*sizeof(Ogre::Real));
+				fieldNode->addField(fieldtoken, rvalues, BLOCKSIZE*blockcnt+cnt, fieldtyp);
+				realfield = false;
+//				free(rvalues);
+			}
+
+			if (level > 0)
+			{
+				actualNode = parent = actualNode->getParent();
+				level--;
+			}
+		} else
+		{
+			if (oldtmptyp == IV_TOKEN_DEF)
+			{
+				def = true; defLabel = ""; defLabel = defLabel + token;
+			} else
+			if (oldtmptyp == IV_TOKEN_USE)
+			{
+					newNode = new IVNode("USE"); 
+					if (parent == NULL)
+					{
+						message = "Error loading file "; message = message + fileName + "! Invalid tree structure.";
+						if (IVLog != NULL) IVLog->logMessage(message);
+						fclose(infile);
+						return false;
+					}
+					char *s = (char *)malloc(sizeof(char)*(strlen(token)+1));
+					memcpy(s, token, strlen(token));
+					s[strlen(token)] = '\0';
+					newNode->addField("label", s);
+					actualNode->attachNode(newNode);
+			} else
+			if (!def)
+			if (oldtmptyp == IV_TOKEN_STRING)
+			{
+				if (!textfield)
+				{
+					if (tmptyp == IV_TOKEN_STRING)
+					{
+/*						char *s = new char[strlen(token)+1];
+						strcpy(s, token);
+*/						
+						char *s = (char *)malloc(sizeof(char)*(strlen(token)+1));
+						memcpy(s, token, strlen(token));
+						s[strlen(token)] = '\0';
+						actualNode->addField(oldtoken, s);
+//						delete [] s;
+					}
+				}
+				if (!realfield)
+				{
+					if ((tmptyp == IV_TOKEN_REAL) || (tmptyp == IV_TOKEN_INT))
+					{	
+						cnt = 0; blockcnt = 0;
+						char *stopstring;						
+						rblock[0] = strtod(token, &stopstring);
+						cnt++;
+						strcpy(fieldtoken, oldtoken);
+						fieldNode = actualNode;
+					    if (tmptyp == IV_TOKEN_REAL) fieldtyp = IV_REAL;
+						if (tmptyp == IV_TOKEN_INT)	fieldtyp = IV_INT;
+						realfield = true;
+					}
+				}
+				textfield = !textfield;
+			}
+			else 
+			{
+				if (realfield)	
+				{
+					if ((tmptyp == IV_TOKEN_REAL) || (tmptyp == IV_TOKEN_INT))
+					{		
+						char *stopstring;
+						if (cnt >= BLOCKSIZE) 
+						{
+							if (blockcnt == 0) rvalues = (Ogre::Real *)malloc((BLOCKSIZE)*sizeof(Ogre::Real));
+							else rvalues = (Ogre::Real *)realloc(rvalues, (BLOCKSIZE*(blockcnt+1))*sizeof(Ogre::Real));
+							memcpy((void *)&rvalues[BLOCKSIZE*blockcnt], rblock, BLOCKSIZE*sizeof(Ogre::Real));
+							cnt = 0;
+							blockcnt++;
+							
+						}
+						rblock[cnt] = strtod(token, &stopstring);
+						cnt++;
+					    if (tmptyp == IV_TOKEN_REAL) fieldtyp = IV_REAL;
+					}
+					else
+					{
+						if (blockcnt == 0) rvalues = (Ogre::Real *)malloc((cnt)*sizeof(Ogre::Real));
+						else rvalues = (Ogre::Real *)realloc(rvalues, (BLOCKSIZE*(blockcnt) + cnt)*sizeof(Ogre::Real));						
+						memcpy((void *)&rvalues[BLOCKSIZE*blockcnt], rblock, cnt*sizeof(Ogre::Real));
+						fieldNode->addField(fieldtoken, rvalues, BLOCKSIZE*blockcnt+cnt, fieldtyp);
+						realfield = false;
+//						free(rvalues);
+					}
+				}
+				
+				textfield = false;
+			}
+		}
+
+
+		strcpy(oldtoken, token);
+		oldtmptyp = tmptyp;
+	}
+	message = ""; ; message = message + fileName + " loaded.";
+	if (IVLog != NULL) IVLog->logMessage(message);
+	fclose(infile);
+
+	return true;
+}
+
+void IVReader::print()
+{
+	if (root != NULL) root->print();
+}
+
+bool IVReader::checkHeader(const char *string)
+{
+	for (int i=0; i < validIVHeaderCnt; i++)
+		if (strcmp(validIVHeader[i], string) == 0) return true;
+	return false;
+}
+bool IVReader::isSpace(char c)
+{
+	if ((c==' ') || (c=='\t')) return true;
+	return false;
+}
+bool IVReader::isNewline(char c)
+{
+	if (c=='\n') return true;
+	return false;
+}
+bool IVReader::isDigit(char c)
+{
+	if ((c>=48) && (c<=57)) return true;
+	return false;
+}
+bool IVReader::isHexDigit(char c)
+{
+	if ( ((c>=48) && (c<=57)) || ((c>=65) && (c<=70)) || ((c>=97) && (c<=102)) ) return true;
+	return false;
+}
+
+
+bool IVReader::getNextElement(char *token, IVTokenType *type)
+{
+	if (eof) return false;
+	bool quoted = false;
+	while (isSpace(buf[bufOffset])) bufOffset++;
+	int i=0;
+	while ((!isSpace(buf[bufOffset])) || (quoted))
+	{
+		if (!quoted)
+		{
+			if (isNewline(buf[bufOffset]) || (buf[bufOffset] == COMMENTCHAR))
+			{
+				token[i] = '\0'; 
+				classify(token, type);
+				bufOffset = 0;
+				if (fgets(buf, BUFFERSIZE, infile) == NULL) 
+				{			
+					eof = true;
+				}
+				if (i==0) return getNextElement(token, type);
+				return true;
+			}
+			if ((buf[bufOffset] == ',') || (buf[bufOffset] == ']'))
+			{
+				token[i] = '\0';
+				bufOffset++;
+				classify(token, type);
+				return true;
+			}
+		
+			
+
+		} else if (isNewline(buf[bufOffset])) {	eof = true;	}
+
+		
+		token[i] = buf[bufOffset]; 
+		i++;
+		if (buf[bufOffset] == '"') 
+		{
+			quoted = !quoted; i--;
+		}
+		bufOffset++;
+
+		
+	}
+	token[i] = '\0';
+	classify(token, type);
+	return true;
+}
+
+void IVReader::classify(char *token, IVTokenType *type)
+{
+	bool isInt = true, isReal = true;
+	if (!isDigit(token[0]) && (token[0] != '-') && (token[0] != '+')) 
+	{
+		isInt = false; 
+		if (token[0] != '.') isReal = false; 
+	}
+	int i = 1;
+	while ((token[i] != '\0') && isReal)
+	{
+		if (isInt && (i!=2) && !isHexDigit(token[i])) 
+		{
+			isInt = false;
+		}
+		if (isInt && (i==2) && !isHexDigit(token[i]) && (token[i] != 'x') && (token[i] != 'X')) isInt = false;
+		if (isReal && (!isDigit(token[i])) && (token[i] != '.') && (token[i] != 'e') && (token[i] != 'E') && (token[i] != 'd') && (token[i] != 'D') && (token[i] != '-') && (token[i] != '+')) isReal = false;
+		i++;
+	}
+	if (isInt) *type = IV_TOKEN_INT; 
+	else if (isReal) *type = IV_TOKEN_REAL;
+	else *type = IV_TOKEN_STRING;
+
+	if (strcmp(token, "DEF") == 0) *type = IV_TOKEN_DEF;
+	if (strcmp(token, "USE") == 0) *type = IV_TOKEN_USE;
+
+	if (token[1] == '\0')
+	{
+		if (token[0] == '{') *type = IV_TOKEN_BRACEOPEN;
+		if (token[0] == '}') *type = IV_TOKEN_BRACECLOSE;
+		if (token[0] == '[') *type = IV_TOKEN_BRACKETOPEN;
+		if (token[0] == ']') *type = IV_TOKEN_BRACKETCLOSE;
+		if (token[0] == '(') *type = IV_TOKEN_PARENTHESISOPEN;
+		if (token[0] == ')') *type = IV_TOKEN_PARENTHESISCLOSE;
+	}
+	if (token[0] == '\0')
+	{
+		*type = IV_TOKEN_INVALID;
+	}
+
+}
+
+/*
+IVNode *IVReader::getNode(const char* name)
+{
+	return root->getNodeRecursive(name);
+}
+*/
+void IVReader::addMeshToList(std::string name, IVManualMeshLoader *loader)
+{	
+	if (meshList == NULL) 
+	{
+		meshList = new IVMeshListNode(name, loader);
+	}
+	else
+	{
+		meshList->attachNewNode(name, loader);
+	}
+}
+
+void IVReader::addDefToList(std::string name, IVNode *node)
+{	
+	if (defList == NULL) 
+	{
+		defList = new IVDefListNode(name, node);
+	}
+	else
+	{
+		defList->attachNewNode(name, node);
+	}
+}
+
+Ogre::Entity *IVReader::createEntity(Ogre::SceneManager* sceneMgr, std::string name, IVMeshData *mData, Ogre::Vector3 *translation)
+{
+	using namespace Ogre;
+
+	std::string meshName = name.substr(name.find('/',0), name.length()) + "/Mesh";
+	std::string entityName = name + "/Entity";
+
+	Mesh* pMesh = NULL;
+	if ((pMesh = (Mesh *) MeshManager::getSingleton().getByName(meshName).getPointer()) == NULL)
+	{
+
+		IVMeshData *data = mData->expand();
+
+		IVManualMeshLoader *loader	= new IVManualMeshLoader(data);
+
+		if (translation != NULL) *translation = data->boundingBox->getCenter();
+
+//		data->collapse();
+//		delete data;
+
+
+		addMeshToList(meshName, loader);
+
+		Mesh* pMesh = MeshManager::getSingleton().createManual(meshName, "IVGroup", loader).getPointer(); 
+
+		pMesh->load(); 
+		pMesh->touch();
+	}
+	else
+	{
+		if (translation != NULL)
+		{
+			*translation = meshList->getManualMeshLoader(meshName)->getBoundingBox()->getCenter();
+		}
+	}
+
+	Entity *pEntity = sceneMgr->createEntity(entityName, meshName);
+
+
+	return pEntity;
+}
+
+
+
+void IVReader::buildTree(Ogre::SceneManager* sceneMgr,  Ogre::SceneNode *sceneNodeRoot)
+{
+	using namespace Ogre;
+	if (root == NULL) return;
+
+	std::string s = intToStr(treeCnt) + "/" + fileName + "/Root";
+	SceneNode *actualSceneNode = sceneNodeRoot->createChildSceneNode(s);
+	s = "/"; s = s + fileName + "/RootMaterial";
+	
+	Material* pMaterial = NULL;
+	if ((pMaterial = (Material *) MaterialManager::getSingleton().getByName(s).getPointer()) == NULL)
+	{
+		pMaterial = (Material *)MaterialManager::getSingleton().create(s, "General").getPointer();
+	}
+	pMaterial->load();
+
+	nodeCnt = 1; matCnt = 1;
+	
+
+	buildTree(sceneMgr, actualSceneNode, root, NULL, pMaterial);	
+	treeCnt++; 
+
+
+	std::string message = "Tree of "; message = message + fileName + " built (" + intToStr(nodeCnt) + " Nodes)";
+	if (IVLog != NULL) IVLog->logMessage(message);
+
+}
+
+void IVReader::buildTree(Ogre::SceneManager* sceneMgr,  Ogre::SceneNode *sceneNodeRoot, IVNode *ivRoot, IVMeshData *mData, Ogre::Material *material)
+{
+	using namespace Ogre;
+
+	Material *newMaterial = NULL;
+
+	bool meshDataCreated = false;
+	if (mData == NULL)
+	{
+		mData = new IVMeshData();
+		meshDataCreated = true;
+	}
+
+	IVType t; int i;
+	
+	IVNode *help = ivRoot->getNextChildNode(true);
+	while (help != NULL)
+	{	
+		if (strcmp(help->getName(), "USE") == 0)
+		{
+			char *defLabel = (char *) help->getField("label", &t, &i);
+			if (t == IV_STRING) 
+			{
+				help = defList->getDef(defLabel);
+			}
+		}
+		if ((strcmp(help->getName(), "Separator") == 0) || (strcmp(help->getName(), "TransformSeparator") == 0)) 
+		{
+/*			std::string s = sceneNodeRoot->getName() + "/Sep" + intToStr(nodeCnt);
+			nodeCnt++;
+			SceneNode *actualSceneNode = sceneNodeRoot->createChildSceneNode(s);
+			buildTree(sceneMgr, actualSceneNode, help, mData, actualMaterial);
+*/
+			if (newMaterial == NULL) newMaterial = material;
+			buildTree(sceneMgr, sceneNodeRoot, help, mData, newMaterial);
+		}
+
+		if (strcmp(help->getName(), "Texture2") == 0)
+		{
+			char *textureFileName = (char *) help->getField("filename", &t, &i);
+			if (t == IV_STRING) 
+			{  
+				std::string s = sceneNodeRoot->getName().substr(sceneNodeRoot->getName().find('/',0), sceneNodeRoot->getName().length()) + "/Material" + intToStr(matCnt);
+				matCnt++;
+				if ((newMaterial = (Material *) MaterialManager::getSingleton().getByName(s).getPointer()) == NULL)
+				{
+					newMaterial = (Material *)MaterialManager::getSingleton().create(s, "General").getPointer();
+					newMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(textureFileName);
+				}
+				newMaterial->load();
+				newMaterial->reload();
+			}
+		}
+// can be included
+		if (strcmp(help->getName(), "Material") == 0)
+		{
+			Real *ambientColor = (Real *) help->getField("ambientColor", &t, &i);
+			if ((i != 3) || (t != IV_REAL)) ambientColor = NULL;
+			Real *diffuseColor = (Real *) help->getField("diffuseColor", &t, &i);
+			if ((i != 3) || (t != IV_REAL)) diffuseColor = NULL;
+			Real *specularColor = (Real *) help->getField("specularColor", &t, &i);
+			if ((i != 3) || (t != IV_REAL)) specularColor = NULL;
+			Real *emissiveColor = (Real *) help->getField("emissiveColor", &t, &i);
+			if ((i != 3) || (t != IV_REAL)) emissiveColor = NULL;
+			Real *shininess = (Real *) help->getField("shininess", &t, &i);
+			if ((i != 1) || (t != IV_REAL)) shininess = NULL;
+			Real *transparency = (Real *) help->getField("transparency", &t, &i);
+			if ((i != 1) || (t != IV_REAL)) transparency = NULL;
+
+			if (newMaterial == NULL)
+			{
+				std::string s = sceneNodeRoot->getName().substr(sceneNodeRoot->getName().find('/',0), sceneNodeRoot->getName().length()) + "/Material" + intToStr(matCnt);
+				matCnt++;
+				if ((newMaterial = (Material *) MaterialManager::getSingleton().getByName(s).getPointer()) == NULL)
+				{
+					if (material == NULL) newMaterial = (Material *)MaterialManager::getSingleton().create(s, "General").getPointer();
+					else newMaterial = material->clone(s).getPointer();
+
+					Real alpha = 1.f;
+					if (transparency != NULL) alpha = 1.f - transparency[0];
+					if (ambientColor != NULL) newMaterial->setAmbient(ambientColor[0], ambientColor[1], ambientColor[2]);
+					if (diffuseColor != NULL) newMaterial->setDiffuse(diffuseColor[0], diffuseColor[1], diffuseColor[2], alpha);
+					if (specularColor != NULL) newMaterial->setSpecular(specularColor[0], specularColor[1], specularColor[2], alpha);
+					if (emissiveColor != NULL) newMaterial->setSelfIllumination(emissiveColor[0], emissiveColor[1], emissiveColor[2]);
+					if (shininess != NULL) newMaterial->setShininess(shininess[0]);
+					
+//					if (material->getTechnique(0)->getPass(0)->getNumTextureUnitStates() > 0)							
+//					{
+//						newMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(material->getTechnique(0)->getPass(0)->getTextureUnitState(0)->getTextureName());
+//					}
+				}
+				newMaterial->load();
+				newMaterial->reload();
+			}
+			else
+			{
+				Real alpha = 1.f;
+				if (transparency != NULL) alpha = 1.f - transparency[0];
+				if (ambientColor != NULL) newMaterial->setAmbient(ambientColor[0], ambientColor[1], ambientColor[2]);
+				if (diffuseColor != NULL) newMaterial->setDiffuse(diffuseColor[0], diffuseColor[1], diffuseColor[2], alpha);
+				if (specularColor != NULL) newMaterial->setSpecular(specularColor[0], specularColor[1], specularColor[2], alpha);
+				if (emissiveColor != NULL) newMaterial->setSelfIllumination(emissiveColor[0], emissiveColor[1], emissiveColor[2]);
+				if (shininess != NULL) newMaterial->setShininess(shininess[0]);
+				newMaterial->load();
+			}
+		}
+
+		if (strcmp(help->getName(), "Coordinate3") == 0)
+		{
+			mData->vertices = (Real *) help->getField("point", &t, &mData->vcnt);
+			if ((t != IV_REAL) && (t != IV_INT)) mData->vertices = NULL;
+		}
+		if (strcmp(help->getName(), "Normal") == 0)
+		{
+			mData->normals = (Real *) help->getField("vector", &t, &mData->ncnt);
+			if ((t != IV_REAL) && (t != IV_INT)) mData->normals = NULL;
+		}
+		if (strcmp(help->getName(), "TextureCoordinate2") == 0)
+		{
+			mData->texCoords = (Real *) help->getField("point", &t, &mData->tcnt);
+			if ((t != IV_REAL) && (t != IV_INT)) mData->texCoords = NULL;
+		}
+
+		if (strcmp(help->getName(), "IndexedFaceSet") == 0)
+		{
+			std::string s = sceneNodeRoot->getName() + "/IFS" + intToStr(nodeCnt);
+			nodeCnt++;
+			SceneNode *triangleStripSceneNode = sceneNodeRoot->createChildSceneNode(s);
+
+			mData->indices = (Real *) help->getField("coordIndex", &t, &mData->icnt);
+			if (t != IV_INT) mData->indices = NULL;
+
+			mData->normalIndices = (Real *) help->getField("normalIndex", &t, &mData->nicnt);
+			if (t != IV_INT) mData->normalIndices = NULL;
+		
+			mData->texCoordIndices = (Real *) help->getField("textureCoordIndex", &t, &mData->ticnt);
+			if (t != IV_INT) mData->texCoordIndices = NULL;
+		
+
+			mData->roType = IV_ROT_FACE_SET;		
+	
+			Vector3 translation = Vector3(0,0,0);
+			Entity *pEntity = createEntity(sceneMgr, s, mData, &translation);
+			if (newMaterial == NULL) newMaterial = material;
+			if (newMaterial != NULL) pEntity->setMaterialName(newMaterial->getName());
+				
+			triangleStripSceneNode->attachObject(pEntity);
+			triangleStripSceneNode->translate(translation);		
+
+		}
+
+
+		if (strcmp(help->getName(), "IndexedTriangleStripSet") == 0)
+		{
+			std::string s = sceneNodeRoot->getName() + "/ITS" + intToStr(nodeCnt);
+			nodeCnt++;
+			SceneNode *triangleStripSceneNode = sceneNodeRoot->createChildSceneNode(s);
+		
+			mData->indices = (Real *) help->getField("coordIndex", &t, &mData->icnt);
+			if (t != IV_INT) mData->indices = NULL;
+
+			mData->normalIndices = (Real *) help->getField("normalIndex", &t, &mData->nicnt);
+			if (t != IV_INT) mData->normalIndices = NULL;
+
+			mData->texCoordIndices = (Real *) help->getField("textureCoordIndex", &t, &mData->ticnt);
+			if (t != IV_INT) mData->texCoordIndices = NULL;
+
+			IVNode *n = help->getNextChildNode(true);
+			while ((n != NULL) && (strcmp(help->getName(), "VertexProperty") == 0))
+			{
+				n = help->getNextChildNode();
+			}
+			if (n != NULL)
+			{
+				mData->vertices = (Real *) n->getField("vertex", &t, &mData->vcnt);
+				if ((t != IV_REAL) && (t != IV_INT)) mData->vertices = NULL;
+
+				mData->normals = (Real *) n->getField("normal", &t, &mData->ncnt);
+				if ((t != IV_REAL) && (t != IV_INT)) mData->normals = NULL;
+				mData->texCoords = (Real *) n->getField("texCoord", &t, &mData->tcnt);
+				if ((t != IV_REAL) && (t != IV_INT)) mData->texCoords = NULL;
+			}
+
+			mData->roType = IV_ROT_TRIANGLE_STRIP;		
+
+			Vector3 translation = Vector3(0,0,0);
+			Entity *pEntity = createEntity(sceneMgr, s, mData, &translation);
+			if (newMaterial == NULL) newMaterial = material;
+			if (newMaterial != NULL) pEntity->setMaterialName(newMaterial->getName());
+				
+			triangleStripSceneNode->attachObject(pEntity);
+			triangleStripSceneNode->translate(translation);		
+
+		}
+
+		help = ivRoot->getNextChildNode();
+	}
+	if (meshDataCreated) if (mData != NULL) delete mData;
+}
+
Index: trunk/VUT/work/IVReader/src/ivnode.cpp
===================================================================
--- trunk/VUT/work/IVReader/src/ivnode.cpp	(revision 183)
+++ trunk/VUT/work/IVReader/src/ivnode.cpp	(revision 183)
@@ -0,0 +1,211 @@
+#include "ivnode.h"
+#include "IVReader.h"
+
+IVField::IVField()
+{
+	next = NULL;
+	typ = IV_STRING;
+}
+IVField::~IVField()
+{
+	if (value != NULL) free(value);
+	if (name != NULL) delete [] name;
+//	if (next != NULL) delete next;
+}
+
+IVNode::IVNode()
+{
+	parent = children = next = actual = NULL; 
+	name = NULL;
+	fields = NULL;
+}
+
+IVNode::IVNode(const char *s)
+{
+	name = new char[strlen(s)+1];
+	strcpy(name, s);
+	parent = children = next = actual = NULL;
+	fields = NULL;	
+}
+
+IVNode::~IVNode()
+{
+	if (name != NULL) delete[] name;
+	if (fields != NULL) 
+	{
+		IVField *help = fields, *delme = NULL;
+		while (help->next != NULL)
+		{
+			delme = help; help = help->next; delete delme;
+		}
+		delete help;
+	}
+	if (children != NULL) 
+	{
+		IVNode *help = children, *delme = NULL;
+		while (help->next != NULL)
+		{
+			delme = help; help = help->next; delete delme;
+		}
+		delete help;
+	}
+//	if (next != NULL) delete next;
+}
+
+
+
+
+void IVNode::attachNode(IVNode *child)
+{
+	if (children == NULL) children = child;
+	else 
+	{
+		IVNode *help = children;
+		while (help->next != NULL) help = help->next;
+		help->next = child;
+	}
+	child->parent = this;
+}
+
+
+void IVNode::print(int ident)
+{
+	if (IVReader::IVLog != NULL)
+	{
+		std::string msg = ""; 
+
+//		for (int i=0; i < ident; i++) fprintf(stdout, " ");
+		for (int i=0; i < ident; i++) msg = msg + " ";
+//		fprintf(stdout, "%s:\n", name);
+		msg = msg + name + ":";
+		IVReader::IVLog->logMessage(msg);
+
+		IVField *help = fields;
+		while (help != NULL)
+		{
+//			for (int i=0; i < ident; i++) fprintf(stdout, " ");
+			msg = "";
+			for (int i=0; i < ident; i++) msg = msg + " ";
+			
+			if (help->typ == IV_STRING)
+			{
+//				fprintf(stdout, "- %s: %s\n", help->name, (char *)help->value);
+				msg = msg + "- " + help->name + ": " + (char *)help->value;
+				IVReader::IVLog->logMessage(msg);
+			}
+			if (help->typ == IV_INT)
+			{
+//				fprintf(stdout, "- %s (%d): ", help->name, help->cnt);
+				msg = msg + "- " + help->name + "(" + IVReader::intToStr(help->cnt) + "): ";
+//				for (int i=0; i < help->cnt; i++) fprintf(stdout, " %d", ((int *)help->value)[i]);
+				for (int i=0; i < help->cnt; i++) msg = msg + " " + IVReader::realToStr(((float *)help->value)[i]);
+//				fprintf(stdout, "\n");
+				IVReader::IVLog->logMessage(msg);
+			}
+			if (help->typ == IV_REAL)
+			{
+//				fprintf(stdout, "- %s (%d):\n", help->name, help->cnt);
+				msg = msg + "- " + help->name + "(" + IVReader::intToStr(help->cnt) + "): ";
+				for (int i=0; i < help->cnt; i++) 
+				{				
+//					fprintf(stdout, " %.3f", ((float *)help->value)[i]);
+					msg = msg + " " + IVReader::realToStr(((float *)help->value)[i]);
+//					if (i % 3 == 2) fprintf(stdout, "\n");
+					if (i % 3 == 2) msg = msg + "\n";
+				}
+//				fprintf(stdout, "\n");
+				IVReader::IVLog->logMessage(msg);
+			}
+			help = help->next;
+		}	
+		if (children != NULL) { children->print(ident+3); }
+		if (next != NULL) next->print(ident);
+	}
+}
+
+void IVNode::addField(const char *name, void *value, int cnt, IVType typ)
+{
+	IVField *newone = new IVField();
+	newone->name = new char[strlen(name)+1];
+	strcpy(newone->name, name);
+/*
+	if (typ == IV_STRING)
+	{
+		newone->value = new char[strlen((char *)value)+1];
+		strcpy((char *)newone->value, (char *)value);
+	} else
+	if ((typ == IV_INT) || (typ == IV_REAL))
+	{
+		newone->value = new Ogre::Real[cnt];
+		memcpy(newone->value, value, cnt*sizeof(Ogre::Real));
+	}
+*/
+	newone->value = value;
+	newone->typ = typ;
+	newone->cnt = cnt;
+	newone->next = NULL;
+
+	if (fields == NULL) fields = newone;
+	else
+	{
+		IVField *help = fields;
+		while (help->next != NULL) help = help->next;
+		help->next = newone;
+	}
+}
+
+
+void IVNode::addField(const char *name, char *value)
+{
+	addField(name, value, 1, IV_STRING);
+}
+
+
+IVNode *IVNode::getNodeRecursive(const char *name)
+{
+	if (strcmp(name, this->name) == 0) return this;
+	if (this->children != NULL)
+	{
+		IVNode *help = this->children->getNodeRecursive(name);
+		if (help != NULL) return help;
+	}
+	if (this->next != NULL) return this->next->getNodeRecursive(name); else return NULL;
+}
+
+
+IVNode *IVNode::getNextChildNode(bool reset)
+{
+	if (reset) actual = this->children;
+	else if (actual == NULL) actual = this->children; else actual = actual->next;
+	return actual;	
+}
+
+
+IVField *IVNode::getField(const char *name)
+{
+	IVField *help = fields;
+	while (help != NULL)
+	{
+		if (strcmp(name, help->name) == 0) return help;
+		help = help->next;
+	}
+	return NULL;
+}
+
+void *IVNode::getField(const char *name, IVType *typ, int *cnt)
+{
+	IVField *help = fields;
+	while (help != NULL)
+	{
+		if (strcmp(name, help->name) == 0) 
+		{
+			*typ = help->typ;
+			*cnt = help->cnt;
+			return help->value;
+		}
+		help = help->next;
+	}
+	*typ = IV_INVALID;
+	*cnt = 0;
+	return NULL;
+}
Index: trunk/VUT/work/IVReader/src/ivmeshdata.cpp
===================================================================
--- trunk/VUT/work/IVReader/src/ivmeshdata.cpp	(revision 183)
+++ trunk/VUT/work/IVReader/src/ivmeshdata.cpp	(revision 183)
@@ -0,0 +1,263 @@
+#include "ivmeshdata.h"
+#include "IVReader.h"
+
+
+IVMeshData::IVMeshData()
+{ 
+	vertices = normals = texCoords = indices = normalIndices = texCoordIndices = NULL; 
+	vcnt = ncnt = tcnt = icnt = nicnt = ticnt = 0;
+	roType = IV_ROT_INVALID;
+	boundingBox = NULL;
+}
+
+IVMeshData::~IVMeshData()
+{ 
+}
+
+void IVMeshData::collapse()
+{
+	if (indices != NULL)	delete [] indices;
+	if (vertices != NULL)	delete [] vertices;
+	if (normals != NULL)	delete [] normals;
+	if (texCoords != NULL)	delete [] texCoords;
+	if (normalIndices != NULL) delete [] normalIndices;
+	if (texCoordIndices != NULL) delete [] texCoordIndices;
+	if (boundingBox != NULL) delete boundingBox;
+	indices = vertices = normals = texCoords = normalIndices = texCoords = NULL;
+	boundingBox = NULL;
+}
+
+int IVMeshData::getSeparatorCnt(Ogre::Real *data, int end)
+{
+	int cnt = 0;
+	for (int i=0; i < end; i++) if (data[i] < 0.f) cnt++; 
+	return cnt;
+}
+
+Ogre::AxisAlignedBox *IVMeshData::calcBoundingBox()
+{
+	if ((vertices == NULL) || (vcnt <=0)) return new Ogre::AxisAlignedBox(0, 0, 0, 0, 0, 0);
+	Ogre::Real x, y, z, minX, minY, minZ, maxX, maxY, maxZ;
+	minX = minY = minZ = 999999;
+	maxX = maxY = maxZ = -999999;
+	for (int i=0; i<vcnt/3; i++) 
+	{
+		x = vertices[i*3];
+		if (minX > x) minX = x;	if (maxX < x) maxX = x;
+		y = vertices[i*3+1];
+		if (minY > y) minY = y;	if (maxY < y) maxY = y;
+		z = vertices[i*3+2];
+		if (minZ > z) minZ = z;	if (maxZ < z) maxZ = z;
+	}
+	return new Ogre::AxisAlignedBox(minX, minY, minZ, maxX, maxY, maxZ);
+
+}
+
+
+Ogre::Real *IVMeshData::expandTriangleStripIndices(Ogre::Real *indices, int icnt, int *icntOut)
+{
+	if (indices[icnt-1] >= 0.0)
+		*icntOut = (icnt+1 - 3*(getSeparatorCnt(indices, icnt)+1))*3;
+	else
+		*icntOut = (icnt - 3*getSeparatorCnt(indices, icnt))*3;
+if (*icntOut < 0)
+int hoppla = 1;
+	Ogre::Real *indOut = new Ogre::Real[*icntOut];
+
+	int triangleCnt = 0, tc = 0;
+	for (int i=2; i < icnt; i++)
+	{
+		if (indices[i] >= 0)
+		{
+			if (tc % 2 == 0)
+			{
+				indOut[triangleCnt*3]   = indices[i-2]; 
+				indOut[triangleCnt*3+1] = indices[i-1];
+				indOut[triangleCnt*3+2] = indices[i];
+			}
+			else
+			{
+				indOut[triangleCnt*3]   = indices[i]; 
+				indOut[triangleCnt*3+1] = indices[i-1];
+				indOut[triangleCnt*3+2] = indices[i-2];
+			}
+			triangleCnt++; tc++;
+		}
+		else
+		{
+			i += 2; tc = 0;
+		}
+	}
+	return indOut;
+}	
+
+int IVMeshData::getNextFaceSize(int start)
+{
+	for (int i=start; i < icnt; i++) 
+	{
+		if (indices[i] < 0.f) return i - start;
+	}
+	return icnt - start;
+}
+
+Ogre::Real *IVMeshData::expandFaceSetIndices(Ogre::Real *indices, int icnt, int *icntOut)
+{
+	if (indices[icnt-1] >= 0.0)
+		*icntOut = (icnt+1 - 3*(getSeparatorCnt(indices, icnt)+1))*3;
+	else
+		*icntOut = (icnt - 3*getSeparatorCnt(indices, icnt))*3;
+	Ogre::Real *indOut = new Ogre::Real[*icntOut];
+
+	int index = 0, size = 0;
+	for (int i=0; i < icnt; i++)
+	{
+		if ((size = getNextFaceSize(i)) < 3) break;
+		for (int j=0; j < size-2; j++)
+		{
+			indOut[index] = indices[i]; index++;
+			indOut[index] = indices[i+1+j]; index++;
+			indOut[index] = indices[i+2+j]; index++;
+		}
+		i = i + size; 
+	}
+	return indOut;
+}
+
+IVMeshData *IVMeshData::expand()
+{
+	using namespace Ogre;
+
+	IVMeshData *mDataOut = new IVMeshData();
+
+	mDataOut->boundingBox = calcBoundingBox();
+	if ((vertices == NULL) || (vcnt <= 0) || (indices == NULL) || (icnt <= 0))
+	{
+		if (IVReader::IVLog != NULL)
+		{
+			std::string message = "Expand-Error: ((vertices == NULL) || (vcnt <= 0) || (indices == NULL) || (icnt <= 0))";
+			IVReader::IVLog->logMessage(message);
+		}
+	
+		return mDataOut;
+	}
+	bool nOk, tOk, niOk, tiOk, nperv, tperv;
+	nOk = ((normals != NULL) && (ncnt > 0));
+	tOk = ((texCoords != NULL) && (tcnt > 0));
+	nperv = (ncnt == vcnt) && (nicnt != icnt);
+	tperv = (tcnt*3 == vcnt*2) && (ticnt != icnt);
+
+	if ((nOk && !nperv) || (tOk && !tperv)) 
+	{
+		niOk = ((normalIndices != NULL) && (nicnt == icnt));
+		tiOk = ((texCoordIndices != NULL) && (ticnt == icnt));
+
+		if (!nperv && nOk && !niOk) nOk = false;
+		if (!tperv && tOk && !tiOk) tOk = false;
+
+		int sepcnt = getSeparatorCnt(indices, icnt);
+		mDataOut->icnt = icnt;
+		mDataOut->vcnt = (icnt - sepcnt)*3;
+		mDataOut->vertices = new Real[mDataOut->vcnt];
+
+		if (nOk) 
+		{
+			mDataOut->ncnt = mDataOut->vcnt;
+			mDataOut->normals = new Real[mDataOut->ncnt];
+		}
+		if (tOk)
+		{
+			mDataOut->tcnt = (icnt - sepcnt)*2;
+			mDataOut->texCoords = new Real[mDataOut->tcnt];
+		}
+		mDataOut->indices = new Real[mDataOut->icnt];
+
+		int index = 0;
+		for (int i=0; i < icnt; i++)
+		{
+			if (indices[i] >= 0.f)
+			{
+				mDataOut->vertices[index*3]   = vertices[(int)indices[i]*3];
+				mDataOut->vertices[index*3+1] = vertices[(int)indices[i]*3+1];
+				mDataOut->vertices[index*3+2] = vertices[(int)indices[i]*3+2];
+
+				if (nOk)
+				{
+					if (nperv)
+					{
+						mDataOut->normals[index*3]   = normals[(int)indices[i]*3];
+						mDataOut->normals[index*3+1] = normals[(int)indices[i]*3+1];
+						mDataOut->normals[index*3+2] = normals[(int)indices[i]*3+2];
+					}
+					else
+					{
+						mDataOut->normals[index*3]   = normals[(int)normalIndices[i]*3];
+						mDataOut->normals[index*3+1] = normals[(int)normalIndices[i]*3+1];
+						mDataOut->normals[index*3+2] = normals[(int)normalIndices[i]*3+2];
+					}
+				}
+				if (tOk)
+				{
+					if (tperv)
+					{
+						mDataOut->texCoords[index*2]   = texCoords[(int)indices[i]*2];
+						mDataOut->texCoords[index*2+1] = texCoords[(int)indices[i]*2+1];
+					}
+					else
+					{
+						mDataOut->texCoords[index*2]   = texCoords[(int)texCoordIndices[i]*2];
+						mDataOut->texCoords[index*2+1] = texCoords[(int)texCoordIndices[i]*2+1];
+					}
+				}
+
+				mDataOut->indices[i] = index;
+				index++;
+			}
+			else mDataOut->indices[i] = indices[i];
+		}
+	}
+	else
+	{
+		mDataOut->icnt = icnt;
+		mDataOut->indices = new Real[mDataOut->icnt];
+		memcpy(mDataOut->indices, indices, mDataOut->icnt*sizeof(Real));
+
+		mDataOut->vcnt = vcnt;
+		mDataOut->vertices = new Real[mDataOut->vcnt];
+		memcpy(mDataOut->vertices, vertices, mDataOut->vcnt*sizeof(Real));
+
+		if (nOk)
+		{
+			mDataOut->ncnt = ncnt;
+			mDataOut->normals = new Real[mDataOut->ncnt];
+			memcpy(mDataOut->normals, normals, mDataOut->ncnt*sizeof(Real));
+		}
+		if (tOk)
+		{
+			mDataOut->tcnt = tcnt;
+			mDataOut->texCoords = new Real[mDataOut->tcnt];
+			memcpy(mDataOut->texCoords, texCoords, mDataOut->tcnt*sizeof(Real));
+		}
+
+	}
+
+	int icntNew = 0;
+	Real *indicesNew = NULL;
+	mDataOut->roType = roType;
+	if (mDataOut->roType == IV_ROT_TRIANGLE_STRIP)	
+	{	
+		indicesNew = expandTriangleStripIndices(mDataOut->indices, mDataOut->icnt, &icntNew);
+	}
+	else if (mDataOut->roType == IV_ROT_FACE_SET)
+	{
+		indicesNew = expandFaceSetIndices(mDataOut->indices, mDataOut->icnt, &icntNew);
+	}
+	else 
+	{
+		return mDataOut;
+	}
+	delete [] mDataOut->indices;
+	mDataOut->indices = indicesNew;
+	mDataOut->icnt = icntNew;
+
+	return mDataOut;
+}
Index: trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 175)
+++ trunk/VUT/work/TestCullingTerrain/TerrainFrameListener.cpp	(revision 183)
@@ -42,5 +42,5 @@
 {
 	0,
-	0,
+	-0.1,
 	//7,
 	0
Index: trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h
===================================================================
--- trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 173)
+++ trunk/VUT/work/TestCullingTerrain/TestCullingTerrainApplication.h	(revision 183)
@@ -156,4 +156,6 @@
 	Vector3 mTerrainMinPos;
 	Vector3 mTerrainMaxPos;
+
+
 private:
 	void chooseSceneManager(void);
Index: trunk/VUT/work/ogre_changes/OgreMain/include/OgreSceneManager.h
===================================================================
--- trunk/VUT/work/ogre_changes/OgreMain/include/OgreSceneManager.h	(revision 159)
+++ trunk/VUT/work/ogre_changes/OgreMain/include/OgreSceneManager.h	(revision 183)
@@ -161,4 +161,8 @@
 		*/
 		void _renderMovableObject(MovableObject *mov, const int leavePassesInQueue);
+
+		/** Renders a single renderable using pass 0 of the renderable.
+		*/
+		void _renderSingleRenderable(Renderable *rend);
 
 		/** Tells the scene manager that the frame ends (i.e.,
Index: trunk/VUT/work/ogre_changes/OgreMain/src/OgreSceneManager.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/OgreMain/src/OgreSceneManager.cpp	(revision 139)
+++ trunk/VUT/work/ogre_changes/OgreMain/src/OgreSceneManager.cpp	(revision 183)
@@ -4248,4 +4248,11 @@
 	SceneManager::_renderVisibleObjects();
 }
+//-----------------------------------------------------------------------
+void SceneManager::_renderSingleRenderable(Renderable *rend)
+{
+	Pass *pass = rend->getTechnique()->getPass(0);
+	setPass(pass);
+	renderSingleObject(rend, pass, false);
+}
 #endif //GTP_VISIBILITY_MODIFIED_OGRE
 }
Index: trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctreeNode.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctreeNode.cpp	(revision 166)
+++ trunk/VUT/work/ogre_changes/Plugins/OctreeSceneManager/src/OgreOctreeNode.cpp	(revision 183)
@@ -189,5 +189,5 @@
 	AxisAlignedBox box = mLocalAABB;
 	// HACK: scale should not be done here
-	box.scale(Vector3(10,10,10));
+	box.scale(Vector3(3, 3, 3));
 	mWireBoundingBox->setupBoundingBox(box);
 	mWireBoundingBox->getRenderOperation(rend);
Index: trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp
===================================================================
--- trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp	(revision 171)
+++ trunk/VUT/work/ogre_changes/RenderSystems/Direct3D9/src/OgreD3D9RenderWindow.cpp	(revision 183)
@@ -366,5 +366,5 @@
 		md3dpp.BackBufferHeight			= mHeight;
 #ifdef GTP_VISIBILITY_MODIFIED_OGRE
-	md3dpp.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
+	//md3dpp.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
 #endif
 		if (mVSync)
@@ -938,5 +938,5 @@
 		// this will be the dimensions of the front buffer
 		if (FAILED(hr = mpD3DDevice->GetDisplayMode(0, &dm)))
-			OGRE_EXCEPT(hr, "Can't get display mode!", "D3D9RenderWindow::writeContentsToFile");
+			OGRE_EXCEPT(hr, "Can't get display mode!", "D3D9RenderWindow::getBufferContents");
 
 		desc.Width = dm.Width;
@@ -951,5 +951,5 @@
 						NULL)))
 		{
-			OGRE_EXCEPT(hr, "Cannot create offscreen buffer 1!", "D3D9RenderWindow::writeContentsToFile");
+			OGRE_EXCEPT(hr, "Cannot create offscreen buffer 1!", "D3D9RenderWindow::getBufferContents");
 		}
 
@@ -971,5 +971,5 @@
 			desc.Format = D3DFMT_A8R8G8B8;         // this is what we get from the screen, so stick with it
 
-			// NB we can't lock the back buffer direct because it's no created that way
+			// NB we can't lock the back buffer direct because it's not created that way
 			// and to do so hits performance, so copy to another surface
 			// Must be the same format as the source surface
@@ -983,5 +983,5 @@
 			{
 				SAFE_RELEASE(pSurf);
-				OGRE_EXCEPT(hr, "Cannot create offscreen buffer 2!", "D3D9RenderWindow::writeContentsToFile");
+				OGRE_EXCEPT(hr, "Cannot create offscreen buffer 2!", "D3D9RenderWindow::getBufferContents");
 			}
 
@@ -991,5 +991,5 @@
 				SAFE_RELEASE(pTempSurf);
 				SAFE_RELEASE(pSurf);
-				OGRE_EXCEPT(hr, "Cannot update surface!", "D3D9RenderWindow::writeContentsToFile");
+				OGRE_EXCEPT(hr, "Cannot update surface!", "D3D9RenderWindow::getBufferContents");
 			}
 
@@ -1003,5 +1003,5 @@
 			D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK)))
 		{
-			OGRE_EXCEPT(hr, "can't lock rect!", "D3D9RenderWindow::writeContentsToFile");
+			OGRE_EXCEPT(hr, "can't lock rect!", "D3D9RenderWindow::getBufferContents");
 		} 
 
Index: trunk/VUT/work/iv/scripts/Demo_IV.plg
===================================================================
--- trunk/VUT/work/iv/scripts/Demo_IV.plg	(revision 183)
+++ trunk/VUT/work/iv/scripts/Demo_IV.plg	(revision 183)
@@ -0,0 +1,36 @@
+<html>
+<body>
+<pre>
+<h1>Erstellungsprotokoll</h1>
+<h3>
+--------------------Konfiguration: Demo_IV - Win32 Debug--------------------
+</h3>
+<h3>Befehlszeilen</h3>
+Erstellen der temporären Datei  "C:\DOKUME~1\andi\LOKALE~1\Temp\RSP5F.tmp" mit Inhalten
+[
+/nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\..\Common\include" /I "..\..\..\OgreMain\include" /D "_MBCS" /D "_WINDOWS" /D "_DEBUG" /D "WIN32" /Fo"..\obj\Debug/" /Fd"..\obj\Debug/" /FD /GZ /Zm500 /c 
+"G:\prakt\ogrenew\Samples\IV\src\IV.cpp"
+]
+Creating command line "cl.exe @C:\DOKUME~1\andi\LOKALE~1\Temp\RSP5F.tmp" 
+Erstellen der temporären Datei  "C:\DOKUME~1\andi\LOKALE~1\Temp\RSP60.tmp" mit Inhalten
+[
+kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib OgreMain_d.lib /nologo /subsystem:windows /incremental:yes /pdb:"..\bin\Debug/Demo_IV.pdb" /debug /machine:I386 /nodefaultlib:"LIBCMT" /out:"../../Common/Bin/Debug/Demo_IV.exe" /pdbtype:sept /libpath:"..\..\..\OgreMain\lib\debug" 
+\prakt\ogrenew\Samples\IV\obj\Debug\IV.obj
+\prakt\ogrenew\Samples\IV\obj\Debug\ivmanualmeshloader.obj
+\prakt\ogrenew\Samples\IV\obj\Debug\ivmeshdata.obj
+\prakt\ogrenew\Samples\IV\obj\Debug\ivnode.obj
+\prakt\ogrenew\Samples\IV\obj\Debug\ivreader.obj
+]
+Erstellen der Befehlzeile "link.exe @C:\DOKUME~1\andi\LOKALE~1\Temp\RSP60.tmp"
+<h3>Ausgabefenster</h3>
+Kompilierung läuft...
+IV.cpp
+Linker-Vorgang läuft...
+
+
+
+<h3>Ergebnisse</h3>
+Demo_IV.exe - 0 Fehler, 0 Warnung(en)
+</pre>
+</body>
+</html>
Index: trunk/VUT/work/iv/scripts/Demo_IV.vcproj
===================================================================
--- trunk/VUT/work/iv/scripts/Demo_IV.vcproj	(revision 183)
+++ trunk/VUT/work/iv/scripts/Demo_IV.vcproj	(revision 183)
@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="Demo_IV"
+	ProjectGUID="{640481BA-D8FE-41ED-B2F2-9844A8CA1E40}"
+	SccProjectName=""
+	SccLocalPath="">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory=".\..\bin\$(ConfigurationName)"
+			IntermediateDirectory=".\..\obj\$(ConfigurationName)"
+			ConfigurationType="1"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="FALSE"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="..\..\IVReader\include;..\include;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;"
+				PreprocessorDefinitions="NDEBUG;_WINDOWS;WIN32;GTP_VISIBILITY_MODIFIED_OGRE"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				PrecompiledHeaderFile=""
+				AssemblerListingLocation=".\..\obj\Release/"
+				ObjectFile=".\..\obj\Release/"
+				ProgramDataBaseFileName=".\..\obj\Release/"
+				BrowseInformation="1"
+				BrowseInformationFile=".\..\obj\Release/"
+				WarningLevel="3"
+				SuppressStartupBanner="TRUE"
+				DebugInformationFormat="3"
+				CompileAs="0"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				IgnoreImportLibrary="TRUE"
+				AdditionalDependencies="odbc32.lib odbccp32.lib OgreMain.lib IVReader.lib"
+				OutputFile="$(OGRE_PATH)/Samples/Common/bin/Release/Demo_IV.exe"
+				LinkIncremental="1"
+				SuppressStartupBanner="TRUE"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\OgreMain\Lib\$(ConfigurationName)&quot;;&quot;..\..\IVReader\Lib\$(ConfigurationName)&quot;"
+				ProgramDatabaseFile=".\..\bin\Release/Demo_IV.pdb"
+				SubSystem="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"
+				PreprocessorDefinitions="NDEBUG"
+				MkTypLibCompatible="TRUE"
+				SuppressStartupBanner="TRUE"
+				TargetEnvironment="1"
+				TypeLibraryName=".\..\bin\Release/Demo_IV.tlb"
+				HeaderFileName=""/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="NDEBUG"
+				Culture="2057"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory=".\..\bin\Debug"
+			IntermediateDirectory=".\..\obj\Debug"
+			ConfigurationType="1"
+			UseOfMFC="0"
+			ATLMinimizesCRunTimeLibraryUsage="FALSE"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalOptions="/Zm500 "
+				Optimization="0"
+				AdditionalIncludeDirectories="..\include;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;"
+				PreprocessorDefinitions="_WINDOWS;_DEBUG;WIN32;GTP_VISIBILITY_MODIFIED_OGRE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				PrecompiledHeaderFile=".\..\obj\Debug/Demo_IV.pch"
+				AssemblerListingLocation=".\..\obj\Debug/"
+				ObjectFile=".\..\obj\Debug/"
+				ProgramDataBaseFileName=".\..\obj\Debug/"
+				WarningLevel="3"
+				SuppressStartupBanner="TRUE"
+				DebugInformationFormat="4"
+				CompileAs="0"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				IgnoreImportLibrary="TRUE"
+				AdditionalDependencies="odbc32.lib odbccp32.lib OgreMain_d.lib"
+				OutputFile="$(OGRE_PATH)/Samples/Common/bin/Debug/Demo_IV.exe"
+				LinkIncremental="1"
+				SuppressStartupBanner="TRUE"
+				AdditionalLibraryDirectories="&quot;$(OGRE_PATH)\OgreMain\Lib\$(ConfigurationName)&quot;"
+				IgnoreDefaultLibraryNames="LIBCMT"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile=".\..\bin\Debug/Demo_IV.pdb"
+				SubSystem="2"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"
+				PreprocessorDefinitions="_DEBUG"
+				MkTypLibCompatible="TRUE"
+				SuppressStartupBanner="TRUE"
+				TargetEnvironment="1"
+				TypeLibraryName=".\..\bin\Debug/Demo_IV.tlb"
+				HeaderFileName=""/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"
+				PreprocessorDefinitions="_DEBUG"
+				Culture="2057"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<Filter
+			Name="Source Files"
+			Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">
+			<File
+				RelativePath="..\src\IV.cpp">
+			</File>
+		</Filter>
+		<Filter
+			Name="Header Files"
+			Filter="h;hpp;hxx;hm;inl">
+			<File
+				RelativePath="..\src\IV.h">
+			</File>
+		</Filter>
+		<Filter
+			Name="Resource Files"
+			Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">
+		</Filter>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>
Index: trunk/VUT/work/iv/scripts/Demo_IV.dsp
===================================================================
--- trunk/VUT/work/iv/scripts/Demo_IV.dsp	(revision 183)
+++ trunk/VUT/work/iv/scripts/Demo_IV.dsp	(revision 183)
@@ -0,0 +1,141 @@
+# Microsoft Developer Studio Project File - Name="Demo_IV" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** NICHT BEARBEITEN **
+
+# TARGTYPE "Win32 (x86) Application" 0x0101
+
+CFG=Demo_IV - Win32 Debug
+!MESSAGE Dies ist kein gültiges Makefile. Zum Erstellen dieses Projekts mit NMAKE
+!MESSAGE verwenden Sie den Befehl "Makefile exportieren" und führen Sie den Befehl
+!MESSAGE 
+!MESSAGE NMAKE /f "Demo_IV.mak".
+!MESSAGE 
+!MESSAGE Sie können beim Ausführen von NMAKE eine Konfiguration angeben
+!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:
+!MESSAGE 
+!MESSAGE NMAKE /f "Demo_IV.mak" CFG="Demo_IV - Win32 Debug"
+!MESSAGE 
+!MESSAGE Für die Konfiguration stehen zur Auswahl:
+!MESSAGE 
+!MESSAGE "Demo_IV - Win32 Release" (basierend auf  "Win32 (x86) Application")
+!MESSAGE "Demo_IV - Win32 Debug" (basierend auf  "Win32 (x86) Application")
+!MESSAGE 
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF  "$(CFG)" == "Demo_IV - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "..\bin\Release"
+# PROP BASE Intermediate_Dir "..\obj\Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "..\bin\Release"
+# PROP Intermediate_Dir "..\obj\Release"
+# PROP Ignore_Export_Lib 1
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /Zi /Od /I "..\include" /I "..\..\Common\include" /I "..\..\..\OgreMain\include" /D "NDEBUG" /D "_MBCS" /D "_WINDOWS" /D "WIN32" /Fr /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "NDEBUG"
+# ADD RSC /l 0x809 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib OgreMain.lib /nologo /subsystem:windows /machine:I386 /out:"../../Common/Bin/Release/Demo_IV.exe" /libpath:"..\..\..\OgreMain\lib\release"
+# SUBTRACT LINK32 /profile /debug
+
+!ELSEIF  "$(CFG)" == "Demo_IV - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "..\bin\Debug"
+# PROP BASE Intermediate_Dir "..\obj\Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "..\bin\Debug"
+# PROP Intermediate_Dir "..\obj\Debug"
+# PROP Ignore_Export_Lib 1
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "..\include" /I "..\..\Common\include" /I "..\..\..\OgreMain\include" /D "_MBCS" /D "_WINDOWS" /D "_DEBUG" /D "WIN32" /FD /GZ /Zm500 /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x809 /d "_DEBUG"
+# ADD RSC /l 0x809 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib OgreMain_d.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:"LIBCMT" /out:"../../Common/Bin/Debug/Demo_IV.exe" /pdbtype:sept /libpath:"..\..\..\OgreMain\lib\debug"
+# SUBTRACT LINK32 /verbose
+
+!ENDIF 
+
+# Begin Target
+
+# Name "Demo_IV - Win32 Release"
+# Name "Demo_IV - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=..\src\IV.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\src\ivmanualmeshloader.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\src\ivmeshdata.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\src\ivnode.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\src\ivreader.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\src\ivmanualmeshloader.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\src\ivmeshdata.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\src\ivnode.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\src\ivreader.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
Index: trunk/VUT/work/iv/src/IV.cpp
===================================================================
--- trunk/VUT/work/iv/src/IV.cpp	(revision 183)
+++ trunk/VUT/work/iv/src/IV.cpp	(revision 183)
@@ -0,0 +1,39 @@
+#include "IV.h"
+
+#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
+#define WIN32_LEAN_AND_MEAN
+#include "windows.h"
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
+INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
+#else
+int main(int argc, char *argv[])
+#endif
+{
+    // Create application object
+    TerrainApplication app;
+
+    SET_TERM_HANDLER;
+    
+    try {
+        app.go();
+    } catch(Ogre::Exception& e) {
+#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
+        MessageBox( NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
+#else
+        std::cerr << "An exception has occured: " <<
+            e.getFullDescription().c_str() << std::endl;
+#endif
+    }
+
+    return 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
Index: trunk/VUT/work/iv/src/IV.h
===================================================================
--- trunk/VUT/work/iv/src/IV.h	(revision 183)
+++ trunk/VUT/work/iv/src/IV.h	(revision 183)
@@ -0,0 +1,554 @@
+#include "ivreader.h"
+#include "ExampleApplication.h"
+//#include <OgreLogManager.h>
+
+#include "ExampleApplication.h"
+#include "IVReader.h"
+
+Real timeDelay = 0;
+/*#define KEY_PRESSED(_key,_timeDelay, _macro) \
+{ \
+    if (mInputDevice->isKeyDown(_key) && timeDelay <= 0) \
+{ \
+    timeDelay = _timeDelay; \
+    _macro ; \
+} \
+}*/
+
+RaySceneQuery* raySceneQuery = 0;
+
+//-- captions for overlays
+String algorithmCaptions[] = 
+{
+	"Coherent Hierarchical Culling",
+	"View Frustum Culling", 
+	"Stop and Wait Culling"
+};
+
+class TutorialFrameListener : public ExampleFrameListener
+{
+protected:
+	int mCurrentAlgorithm;
+	Overlay* mDebugOverlay;
+	Overlay* mHelpOverlay;
+	Overlay* mCullStatsOverlay;
+	Overlay* mQueryOverlay;
+
+	OverlayElement *mAlgorithmInfo;
+	OverlayElement *mThresholdInfo;
+	OverlayElement *mAssumedVisibilityInfo;
+	OverlayElement *mFrustumCulledNodesInfo;
+	OverlayElement *mQueryCulledNodesInfo;
+    OverlayElement *mTraversedNodesInfo;
+	OverlayElement *mHierarchyNodesInfo;
+	OverlayElement *mTestGeometryForVisibleLeavesInfo;
+	OverlayElement *mUseDepthPassInfo;
+	OverlayElement *mRenderedNodesInfo;
+	OverlayElement *mObjectsCountInfo;
+	OverlayElement *mQueriesIssuedInfo;
+	OverlayElement *mDelayedQueriesIssuedInfo;
+	OverlayElement *mDelayedTraversedNodesInfo;
+	OverlayElement *mCurrentObjectTypeInfo;
+
+	OverlayElement *mQueryTypeInfo;
+	OverlayElement *mQueryVisibleNodesInfo;
+	OverlayElement *mQueryVisibleGeometryInfo;
+	OverlayElement *mQueryVisiblePatchInfo;
+
+	OverlayElement *mQueryVisiblityInfo;
+	OverlayElement *mQueryNodeVisibilityInfo;
+	OverlayElement *mQueryGeometryVisibilityInfo;
+	OverlayElement *mQueryPatchVisibilityInfo;
+
+public:
+	
+	//-----------------------------------------------------------------------
+	void initOverlayElement(OverlayElement **elInfo, String ext, 
+						    String name, int top, String caption)
+	{
+		OverlayElement *el = 
+			OverlayManager::getSingleton().getOverlayElement(ext + name);
+
+		(*elInfo) = OverlayManager::getSingleton().getOverlayElement(ext + name + "Info");
+		(*elInfo)->setCaption(caption);
+
+		el->setTop(top);
+		(*elInfo)->setTop(top);
+	}
+	//-----------------------------------------------------------------------
+	void initVisStatsOverlay()
+	{
+		const int border_height = 10;
+		const int vert_space = 15;
+
+		//-- visibility culling stats overlay
+		int top = border_height;
+
+		String ext = "Example/Visibility/";
+	
+		initOverlayElement(&mAlgorithmInfo, ext, "Algorithm", top,
+			": " + algorithmCaptions[mCurrentAlgorithm]); top += vert_space;
+
+		initOverlayElement(&mThresholdInfo, ext, "Threshold", top, ": 0"); top += vert_space;
+		initOverlayElement(&mTestGeometryForVisibleLeavesInfo, ext, 
+			"TestGeometryForVisibleLeaves", top, ": true"); top += vert_space;
+		initOverlayElement(&mUseDepthPassInfo, ext, "UseDepthPass", top, ": false"); top += vert_space;
+		initOverlayElement(&mAssumedVisibilityInfo, ext, "AssumedVisibility", top, ": 0"); top += vert_space;
+		initOverlayElement(&mCurrentObjectTypeInfo, ext, "CurrentObjectType", top, ": "); top += vert_space;
+		//initOverlayElement(&mHelpInfo, ext, "Help", top, ": "); top += vert_space;
+
+		OverlayElement *optionsPanel = OverlayManager::getSingleton().
+			getOverlayElement("Example/Visibility/VisibilityPanel");
+
+		optionsPanel->setHeight(top + border_height);
+
+		top = border_height;
+		//ext = "Example/Visibility/";
+		initOverlayElement(&mFrustumCulledNodesInfo, ext, "FrustumCulledNodes", top, ": 0"); top += vert_space;
+		initOverlayElement(&mQueryCulledNodesInfo, ext, "QueryCulledNodes", top, ": 0"); top += vert_space;
+		initOverlayElement(&mTraversedNodesInfo, ext, "TraversedNodes", top, ": 0"); top += vert_space;
+		initOverlayElement(&mHierarchyNodesInfo, ext, "HierarchyNodes", top, ": 0"); top += vert_space;
+		initOverlayElement(&mRenderedNodesInfo, ext, "RenderedNodes", top, ": 0"); top += vert_space;
+		initOverlayElement(&mObjectsCountInfo, ext, "ObjectsCount", top, ": 0"); top += vert_space;
+		initOverlayElement(&mQueriesIssuedInfo, ext, "QueriesIssued", top, ": 0"); top += vert_space;
+
+		OverlayElement *visPanel = OverlayManager::getSingleton().
+			getOverlayElement("Example/Visibility/VisibilityStatsPanel");
+
+		visPanel->setHeight(top + border_height);
+	}
+	//-----------------------------------------------------------------------
+	void initQueryOverlay()
+	{
+		const int border_height = 10;
+		const int vert_space = 15;
+
+		//-- visibility culling stats overlay
+		int top = border_height + 25;
+
+		String ext = "Example/Visibility/Query/";
+	    
+		initOverlayElement(&mQueryTypeInfo , ext, "QueryType", top,	": 0"); top += vert_space;
+	
+		initOverlayElement(&mQueryVisibleNodesInfo , ext, "VisibleNodes", top,	": 0"); top += vert_space;
+		initOverlayElement(&mQueryVisibleGeometryInfo , ext, "VisibleGeometry", top,	": 0"); top += vert_space;
+		initOverlayElement(&mQueryVisiblePatchInfo , ext, "VisiblePatches", top,	": 0"); top += vert_space;
+	
+		initOverlayElement(&mQueryNodeVisibilityInfo , ext, "NodeVisibility", top,	": 0"); top += vert_space;
+		initOverlayElement(&mQueryGeometryVisibilityInfo , ext, "GeometryVisibility", top,	": 0"); top += vert_space;
+		initOverlayElement(&mQueryPatchVisibilityInfo , ext, "PatchVisibility", top,	": 0"); top += vert_space;
+
+
+		OverlayElement *queryPanel = OverlayManager::getSingleton().
+		getOverlayElement("Example/Visibility/Query/QueryPanel");
+
+		queryPanel->setHeight(top + border_height);
+	}
+
+	//-----------------------------------------------------------------------
+	void showStats(bool show)
+	{
+		if (mDebugOverlay && mCullStatsOverlay)
+		{
+			if (show)
+			{
+				mDebugOverlay->show();
+				mCullStatsOverlay->show();
+			}
+			else
+			{
+				mDebugOverlay->hide();
+				mCullStatsOverlay->hide();
+			}
+		}
+	}
+}
+
+    TutorialFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr)
+        : ExampleFrameListener(win, cam, false, false), mSceneMgr(sceneMgr), mCurrentAlgorithm(0)
+    {
+		mMoveSpeed = 50;
+
+		//-- overlays
+		mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay");
+		//mHelpOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/HelpOverlay"); 
+		mQueryOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/QueryOverlay"); 
+		mCullStatsOverlay = OverlayManager::getSingleton().getByName("Example/Visibility/CullStatsOverlay"); 
+
+		initVisStatsOverlay(); // visibility stats overlay
+		//initHelpOverlay(); // help overlay
+		initQueryOverlay(); // visibility query stats overlay
+
+		// show stats overlays
+		showStats(true);	
+    }
+
+	bool frameStarted(const FrameEvent& evt)
+	{
+		/*mInputDevice->capture();
+		if (mInputDevice->isKeyDown(KC_B))
+		{
+			showbb = !showbb;
+			mSceneMgr->showBoundingBoxes(showbb);
+		} return ExampleFrameListener::frameStarted(evt);
+		*/
+
+        // clamp to terrain
+        bool ret = ExampleFrameListener::frameStarted(evt);
+
+        static Ray updateRay;
+        
+		updateRay.setOrigin(mCamera->getPosition());
+        updateRay.setDirection(Vector3::NEGATIVE_UNIT_Y);
+        raySceneQuery->setRay(updateRay);
+
+        RaySceneQueryResult& qryResult = raySceneQuery->execute();
+        
+		RaySceneQueryResult::iterator i = qryResult.begin();
+        
+		if (i != qryResult.end() && i->movable)
+        {
+			mCamera->setPosition(mCamera->getPosition().x, 
+								 i->movable->getWorldBoundingBox().getCenter().y + 5, 
+								 mCamera->getPosition().z);
+	
+			std::stringstream d; 
+			d << "World: " << i->movable->getWorldBoundingBox().getCenter().y <<
+				 ", Object: " << i->movable->getBoundingBox().getCenter().y <<
+				 ", Camera: " << mCamera->getPosition();
+
+			LogManager::getSingleton().logMessage(d.str());
+
+        }
+		
+        return ret;
+    }
+
+	/*bool frameEnded(const FrameEvent& evt)
+    {
+        if (timeDelay >= 0) 
+            timeDelay -= evt.timeSinceLastFrame;
+
+        return ExampleFrameListener::frameEnded(evt);        
+    }*/
+
+protected:
+    bool mMouseDown;       // Whether or not the left mouse button was down last frame
+    Real mToggle;          // The time left until next toggle
+    Real mRotate;          // The rotate constant
+    Real mMove;            // The movement constant
+    SceneManager *mSceneMgr;   // The current SceneManager
+    SceneNode *mCamNode;   // The SceneNode the camera is currently attached to
+
+	
+
+private:
+	bool showbb;
+};
+
+
+class TerrainApplication : public ExampleApplication
+{
+public:
+    TerrainApplication()
+    {
+		ivr = new IVReader();
+	}
+
+    ~TerrainApplication() 
+    {
+		OGRE_DELETE(ivr);
+		OGRE_DELETE(raySceneQuery);
+    }
+
+protected:
+
+	IVReader *ivr;
+	
+
+    virtual void chooseSceneManager(void)
+    {
+		//mSceneMgr = mRoot->getSceneManager(ST_EXTERIOR_CLOSE);
+		mSceneMgr = mRoot->getSceneManager(ST_GENERIC);
+    }
+
+    virtual void createCamera(void)
+    {
+        // Create the camera
+        mCamera = mSceneMgr->createCamera("PlayerCam");
+
+        mCamera->setPosition(Vector3(0, 15, -200));
+        // Look back along -Z
+        mCamera->lookAt(Vector3(0, 0, -300));
+        mCamera->setNearClipDistance(1);
+        mCamera->setFarClipDistance(20000);
+
+    }
+
+	////////////////////////////
+    void createScene(void)
+    {
+		String path = "D:/gametools/trunk/VUT/Ogre/resources/";
+		
+		   // Set ambient light
+        mSceneMgr->setAmbientLight(ColourValue(0.5, 0.5, 0.5));
+
+        // Create a light
+        Light* l = mSceneMgr->createLight("MainLight");
+        // Accept default settings: point light, white diffuse, just set position
+        // NB I could attach the light to a SceneNode if I wanted it to move automatically with
+        // other objects, but I don't
+        l->setPosition(20,80,50);
+
+		mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox", 2000, true);
+		ColourValue fadeColour(0.1, 0.1, 0.6);
+		mWindow->getViewport(0)->setBackgroundColour(fadeColour);
+
+
+		SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node1");
+		SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node2");
+		SceneNode *node3 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node3");
+		SceneNode *node4 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node4");
+		SceneNode *node5 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node5");
+		SceneNode *node6 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node6");
+		SceneNode *node7 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node7");
+		SceneNode *node8 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node8");
+		SceneNode *node9 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Node9");
+
+	
+		node1->translate(Vector3(-500, 0, 750));
+		node2->translate(Vector3(-400, 0, 750));
+		node3->scale(Vector3(100, 100 ,100));
+		node3->pitch(Radian(3 * Math::HALF_PI));
+		node4->translate(Vector3(-100, 0, 0));
+		node5->translate(Vector3(0, 300, 0));
+		
+		node6->scale(Vector3(100, 100 ,100));
+		node6->pitch(Radian(3 * Math::HALF_PI));
+		node6->roll(Radian(Math::HALF_PI));
+		node6->translate(Vector3(0, -100, 0));
+
+		node7->scale(Vector3(100, 100 ,100));
+		node7->pitch(Radian(3 * Math::HALF_PI));
+		node7->roll(Radian(Math::HALF_PI));
+		node7->translate(Vector3(100, 0, 0));
+		
+		node8->translate(Vector3(-300, -300, 0));
+
+		Log *log = LogManager::getSingleton().createLog("IVLog.log");
+		ivr->setLog(log);
+
+		/*if (ivr->loadFile("media\\house_test1.iv"))
+		{
+			ivr->buildTree(mSceneMgr, node1);
+			ivr->buildTree(mSceneMgr, node2);
+		}
+		if (ivr->loadFile("media\\anhk.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node3);
+		}
+		if (ivr->loadFile("media\\ant.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node4);
+		}
+		if (ivr->loadFile("media\\zepplin0.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node5);
+		}
+		if (ivr->loadFile("media\\warbird.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node6);
+		}
+		if (ivr->loadFile("media\\z_wing.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node7);
+		}*/
+
+		String fileName = path + "media\\city1500_flat_1.iv";
+		if (ivr->loadFile(fileName.c_str()))
+		{
+			ivr->buildTree(mSceneMgr, node8);
+		}
+
+		fileName = path + "media\\roofs_1500.iv";
+		if (ivr->loadFile(fileName.c_str()))
+		{
+			ivr->buildTree(mSceneMgr, node8);
+		}
+
+		fileName = path + "media\\CityRoads60.iv";
+		if (ivr->loadFile(fileName.c_str()))
+		{
+			ivr->buildTree(mSceneMgr, node8);
+		}
+
+		fileName = path + "media\\CityPlane60.iv";
+        if (ivr->loadFile(fileName.c_str()))
+		{
+			ivr->buildTree(mSceneMgr, node8);
+		}
+		
+		fileName = path + "media\\test.iv";
+		if (ivr->loadFile(fileName.c_str()))
+		{
+			ivr->buildTree(mSceneMgr, node9);
+		}
+	
+		ivr->collapse();
+
+		raySceneQuery = mSceneMgr->createRayQuery(
+            Ray(mCamera->getPosition(), Vector3::NEGATIVE_UNIT_Y));
+	}
+
+  
+
+    // Create new frame listener
+    void createFrameListener(void)
+    {
+        mFrameListener = new TutorialFrameListener(mWindow, mCamera, mSceneMgr);
+        mRoot->addFrameListener(mFrameListener);
+    }
+};
+
+
+
+
+/*class TutorialApplication : public ExampleApplication
+{
+
+public:
+    TutorialApplication()
+    {
+		//LogManager::getSingleton().logMessage("here 0");
+		ivr = new IVReader();
+		mfl = NULL;
+
+    }
+
+    ~TutorialApplication() 
+    {
+		if (ivr != NULL) delete ivr;
+		if (mfl != NULL) delete mfl;
+    }
+protected:
+
+	IVReader *ivr;
+	TutorialFrameListener *mfl;
+
+	////////////////////////////
+    void createScene(void)
+    {
+		//LogManager::getSingleton().logMessage("here 1");
+
+		mSceneMgr->setAmbientLight( ColourValue( 0.3, 0.3, 0.3 ) );
+
+		Light *light = mSceneMgr->createLight( "Light1" );
+        light->setType( Light::LT_DIRECTIONAL );
+        light->setDiffuseColour( ColourValue( 1, 1, 1 ) );
+        light->setSpecularColour( ColourValue( .25, .25, .25 ) );
+		light->setDirection( Vector3( 0, -1, -1 ) );
+
+		Light *light2 = mSceneMgr->createLight( "Light2" );
+        light2->setType( Light::LT_DIRECTIONAL );
+        light2->setDiffuseColour( ColourValue( 1, 1, 1 ) );
+        light2->setSpecularColour( ColourValue( .25, .25, .25 ) );
+		light2->setDirection( Vector3( 0, 1, 1 ) );
+
+
+		SceneNode *node1 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Node1" );
+		SceneNode *node2 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Node2" );
+		SceneNode *node3 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Node3" );
+		SceneNode *node4 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Node4" );
+		SceneNode *node5 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Node5" );
+		SceneNode *node6 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Node6" );
+		SceneNode *node7 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Node7" );
+		SceneNode *node8 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Node8" );
+		SceneNode *node9 = mSceneMgr->getRootSceneNode()->createChildSceneNode( "Node9" );
+
+		LogManager::getSingleton().logMessage("here 2");
+
+
+		node1->translate(Vector3(-500, 0, 750));
+		node2->translate(Vector3(-400, 0, 750));
+		node3->scale(Vector3(100, 100 ,100));
+		node3->pitch(Radian(3*1.57));
+		node4->translate(Vector3(-100, 0, 0));
+		node5->translate(Vector3(0, 300, 0));
+		node6->scale(Vector3(100, 100 ,100));
+		node6->pitch(Radian(3*1.57));
+		node6->roll(Radian(1.57));
+		node6->translate(Vector3(0, -100, 0));
+		node7->scale(Vector3(100, 100 ,100));
+		node7->pitch(Radian(3*1.6));
+		node7->roll(Radian(1.57));
+		node7->translate(Vector3(100, 0, 0));
+		node8->translate(Vector3(-300, -300, 0));
+
+		Log *log = LogManager::getSingleton().createLog("IVLog.log");
+
+		LogManager::getSingleton().logMessage("here 3");
+		ivr->setLog(log);
+
+		if (ivr->loadFile("media\\house_test1.iv"))
+		{
+			ivr->buildTree(mSceneMgr, node1);
+			ivr->buildTree(mSceneMgr, node2);
+		}
+		if (ivr->loadFile("media\\anhk.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node3);
+		}
+		if (ivr->loadFile("media\\ant.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node4);
+		}
+		if (ivr->loadFile("media\\zepplin0.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node5);
+		}
+		if (ivr->loadFile("media\\warbird.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node6);
+		}
+		if (ivr->loadFile("media\\z_wing.wrl"))
+		{
+			ivr->buildTree(mSceneMgr, node7);
+		}
+
+		if (0) {
+		if (ivr->loadFile("media\\city1500_flat_1.iv"))
+		{
+			ivr->buildTree(mSceneMgr, node8);
+		}
+		if (ivr->loadFile("media\\roofs_1500.iv"))
+		{
+			ivr->buildTree(mSceneMgr, node8);
+		}	
+		if (ivr->loadFile("media\\CityRoads60.iv"))
+		{
+			ivr->buildTree(mSceneMgr, node8);
+		}
+
+		if (ivr->loadFile("media\\CityPlane60.iv"))
+		{
+			ivr->buildTree(mSceneMgr, node8);
+		}
+
+		if (ivr->loadFile("media\\test.iv"))
+		{
+			ivr->buildTree(mSceneMgr, node9);
+		}
+}
+		ivr->collapse();
+	
+ 		
+		
+    }
+	// Create new frame listener
+    void createFrameListener(void)
+    {
+		mfl = new TutorialFrameListener(mWindow, mCamera, mSceneMgr);
+        mRoot->addFrameListener(mfl);
+    }
+};
+*/
