|
From: <axl...@us...> - 2009-10-10 22:22:59
|
Revision: 556
http://hgengine.svn.sourceforge.net/hgengine/?rev=556&view=rev
Author: axlecrusher
Date: 2009-10-10 22:22:50 +0000 (Sat, 10 Oct 2009)
Log Message:
-----------
add terrain
Modified Paths:
--------------
Mercury2/modules/Makefile
Added Paths:
-----------
Mercury2/modules/Terrain.cpp
Mercury2/modules/Terrain.h
Modified: Mercury2/modules/Makefile
===================================================================
--- Mercury2/modules/Makefile 2009-10-10 22:21:49 UTC (rev 555)
+++ Mercury2/modules/Makefile 2009-10-10 22:22:50 UTC (rev 556)
@@ -1,8 +1,8 @@
-CFLAGS=-O2 -g0 -Wall -I/usr/include/libxml2 -I.. -msse2 -DHAVE_CONFIG -DHGENGINE -fno-exceptions -fPIC -I../src -g
+CFLAGS=-O2 -g0 -Wall -I/usr/include/libxml2 -I.. -msse2 -DHAVE_CONFIG -DHGENGINE -fexceptions -fPIC -I../src -I../src/DataTypes -I../src/DataStructures -g
CXXFLAGS=${CFLAGS}
LDFLAGS=-shared
-all : BillboardNode.so TextNode.so
+all : BillboardNode.so TextNode.so Terrain.so
clean :
rm -rf *~ *.o *.so
@@ -12,3 +12,6 @@
TextNode.so : TextNode.o
g++ -o$@ $^ ${LDFLAGS}
+
+Terrain.so : Terrain.o
+ g++ -o$@ $^ ${LDFLAGS}
Added: Mercury2/modules/Terrain.cpp
===================================================================
--- Mercury2/modules/Terrain.cpp (rev 0)
+++ Mercury2/modules/Terrain.cpp 2009-10-10 22:22:50 UTC (rev 556)
@@ -0,0 +1,70 @@
+#include "Terrain.h"
+
+REGISTER_ASSET_TYPE(Terrain);
+
+Terrain::Terrain()
+ :base()
+{
+}
+
+Terrain::~Terrain()
+{
+}
+
+Terrain* Terrain::Generate()
+{
+ LOG.Write( "new Terrain" );
+ return new Terrain();
+}
+
+void Terrain::LoadedCallback()
+{
+ BuildHash();
+ base::LoadedCallback();
+}
+
+void Terrain::BuildHash()
+{
+ for( unsigned int i = 0; i < m_meshes.size(); ++i)
+ {
+ MAutoPtr< HGMDLMesh > mesh = m_meshes[i];
+ const HGMDLMesh& m = *mesh;
+ ImportMeshToHash( m );
+ }
+}
+
+void Terrain::ImportMeshToHash(const HGMDLMesh& mesh)
+{
+ const float* vertice = mesh.GetVertexHandle() + MercuryVBO::VERTEX_OFFSET;
+ const short unsigned int* indice = mesh.GetIndexHandle();
+
+ uint16_t length = mesh.IndiceCount();
+
+ float xMax, yMax, zMax;
+ xMax = yMax = zMax = 0;
+
+ for(uint16_t i = 0; i < length; ++i)
+ {
+ MercuryVertex v(vertice+(indice[i]*HGMDLMesh::STRIDE));
+ xMax = MAX<float>(v.GetX(),xMax);
+ yMax = MAX<float>(v.GetY(),yMax);
+ zMax = MAX<float>(v.GetZ(),zMax);
+ }
+
+ printf("%f %f %f\n", xMax, yMax, zMax);
+ m_hash.Allocate(xMax, yMax, zMax, 1);
+
+ for(uint16_t i = 0; i < length; i+=3)
+ {
+ MercuryVertex v1(vertice+(indice[i]*HGMDLMesh::STRIDE));
+ MercuryVertex v2(vertice+(indice[i+1]*HGMDLMesh::STRIDE));
+ MercuryVertex v3(vertice+(indice[i+2]*HGMDLMesh::STRIDE));
+ MTriangle t( v1, v2, v3 );
+
+ m_hash.Insert( v1.GetX(), v1.GetY(), v1.GetZ(), t );
+ m_hash.Insert( v2.GetX(), v2.GetY(), v2.GetZ(), t );
+ m_hash.Insert( v3.GetX(), v3.GetY(), v3.GetZ(), t );
+ }
+}
+
+
Added: Mercury2/modules/Terrain.h
===================================================================
--- Mercury2/modules/Terrain.h (rev 0)
+++ Mercury2/modules/Terrain.h 2009-10-10 22:22:50 UTC (rev 556)
@@ -0,0 +1,64 @@
+#ifndef TERRAIN_H
+#define TERRAIN_H
+
+#include <MercuryAsset.h>
+#include <HGMDLModel.h>
+#include <MercuryFile.h>
+
+#include <SpatialHash.h>
+#include <MTriangle.h>
+
+class Terrain : public HGMDLModel
+{
+ public:
+ Terrain();
+ ~Terrain();
+
+ static Terrain* Generate();
+ virtual void LoadedCallback(); //thread safe
+
+ private:
+ CLASS_HELPERS( HGMDLModel );
+ void BuildHash();
+ void ImportMeshToHash(const HGMDLMesh& mesh);
+
+ SpatialHash<MTriangle> m_hash;
+// void LoadHGMDL( const MString& path );
+// static void* LoaderThread(void* d);
+
+// std::vector< MAutoPtr< HGMDLMesh > > m_meshes;
+};
+
+#endif
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|