![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /******************************************************************************* 00002 ** Copyright (c) 2010 MAK Technologies, Inc. 00003 ** All rights reserved. 00004 *******************************************************************************/ 00005 /******************************************************************************* 00006 ** $RCSfile: $ $Revision: $ $State: $ 00007 *******************************************************************************/ 00008 00011 00013 00014 #pragma once 00015 00016 00017 #include <vantageTerrainImplementation/vantageTerrainImplementationDefines.h> 00018 #include <vantageTerrainImplementation/vantageTerrainImplementationUtil.h> 00019 #include <btBulletCollisionCommon.h> 00020 #include <memory> 00021 #include <vrvUtil/DtCoordinateSystem.h> 00022 #include <vlutil/vlSmartPointers.h> 00023 #include <vlutil/vlFilename.h> 00024 #include <geometry/surface.h> 00025 00027 #include <osg/Matrix> 00028 #include <vrvOsg/DtOsgRenderer.h> 00029 #include <vrvUtil/DtCoordinateSystem.h> 00030 00032 #include <vlutil/vlSmartPointers.h> 00033 00035 #include <memory> 00036 #include "vlutil/vlFilename.h" 00037 00038 class btTriangleMesh; 00039 class Coordinate_System; 00040 00041 00042 00043 namespace osg 00044 { 00045 class Node; 00046 class LOD; 00047 } 00048 00050 //This should move to surface.h 00051 const DT_DLL_vantageTerrainImplementation DtSurface& DtUndefinedSoilType(); 00052 00053 00054 00055 namespace makVrf { 00056 class DtSurfaceCharacteristicMap 00057 { 00058 00059 public: 00060 00062 DtSurfaceCharacteristicMap(); 00063 00065 virtual ~DtSurfaceCharacteristicMap(); 00066 00068 DtSurfaceCharacteristicMap(const DtSurfaceCharacteristicMap& orig); 00069 00072 00074 virtual bool init(const DtFilename filename, bool displayWarning = false); 00075 00077 virtual bool get(std::istream& stream); 00078 00080 virtual bool processToken(std::istream& stream, DtString& token); 00081 00083 virtual bool characteristicsFromString(const char* str, 00084 unsigned int& characteristics, int& position); 00085 00086 protected: 00087 00089 virtual DtSurface* createSurface(); 00090 00091 protected: 00092 typedef std::map <DtString, DtSurface::DtCharacteristics> DtSurfaceStringToCharacteristics; 00093 typedef DtSurfaceStringToCharacteristics::const_iterator DtSurfStrToCharsConstIter; 00094 typedef DtSurfaceStringToCharacteristics::iterator DtSurfStrToCharsIter; 00095 00096 DtSurfaceStringToCharacteristics mySurfaceStringToCharacteristics; 00097 static const DtString theMatchString; 00098 DtSurface* mySurface; 00099 00100 private: 00101 00108 std::set<std::string> myPrintedWarnings; 00109 00110 }; 00111 00112 00113 } 00114 00115 //class makVrv::DtOsgRenderer::RootList; 00116 00117 00119 class DT_DLL_vantageTerrainImplementation DtTriangleMeshWithSoil : public btTriangleMesh 00120 { 00121 public: 00122 DtTriangleMeshWithSoil (bool use32bitIndices=true,bool use4componentVertices=true) : 00123 btTriangleMesh(use32bitIndices, use4componentVertices), 00124 myUseSurfaceArray(false) {} 00125 virtual ~DtTriangleMeshWithSoil() {}; 00126 00127 void addTriangleWithSurface(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2, 00128 const DtSurface& surface, bool removeDuplicateVertices=false); 00129 00130 DtSurface triangleSurface(unsigned int triangleIndex) const; 00131 00132 protected: 00135 void initializeSurfaceArray(); 00136 00139 void syncSurfaceArray(); 00140 00145 bool myUseSurfaceArray; 00146 btAlignedObjectArray<DtSurface> mySurfaceTypes; 00147 }; 00148 00149 typedef std::map<osg::Geode*, DtTriangleMeshWithSoil*> DtGeodeToMeshMap; 00150 typedef std::list<std::pair<btCollisionObject*, DtTriangleMeshWithSoil*> > 00151 DtCollObjMeshPairList; 00152 typedef std::list<std::pair<DtTriangleMeshWithSoil*, osg::Matrix> > 00153 DtMeshTransformPairList; 00154 00158 struct DtVantageRootNode 00159 { 00160 DtVantageRootNode(makVrv::DtOsgRenderer* r, makVrv::DtOsgRenderer::SceneRoot sr) 00161 : osgRenderer(r), sceneRoot(sr) {}; 00162 makVrv::DtOsgRenderer* osgRenderer; 00163 makVrv::DtOsgRenderer::SceneRoot sceneRoot; 00164 }; 00165 00168 DtMeshTransformPairList* convertOsgNodeToTriangeMesh(osg::Node* node, 00169 unsigned int& numTriangleOut, const osg::Matrix& baseTransform, 00170 const DtFilename& surfaceCharacterFilename = ""); 00171 00174 DtMeshTransformPairList* convertOsgNodeToTriangeMesh(DtVantageRootNode node, 00175 unsigned int& numTriangleOut, const osg::Matrix& baseTransform, 00176 const DtFilename& surfaceCharacterFilename = ""); 00177 00178 Coordinate_System* createVrfCoordinateSystem( const makVrv::DtCoordinateSystem& coodSysIn ); 00179 00180 void getBasisAndOrigin(osg::Matrix& matrix, 00181 btMatrix3x3& basisA, btVector3& origin); 00182 00186 template<typename T_Node> 00187 unsigned int createCollisionObjects( 00188 T_Node node, 00189 DtCollObjMeshPairList* collObjMeshPairs, const DtDrawMode& drawMode, 00190 osg::Matrix* worldMatrix = NULL, 00191 const DtFilename& surfaceCharacterFilename = "") 00192 { 00193 unsigned int numTriangles = 0; 00194 osg::Matrix baseMatrix; 00195 if (worldMatrix) 00196 { 00197 baseMatrix = *worldMatrix; 00198 } 00199 DtMeshTransformPairList* meshTransformPairs = convertOsgNodeToTriangeMesh( 00200 node, numTriangles, baseMatrix, surfaceCharacterFilename); 00201 00202 DtMeshTransformPairList::iterator itr = meshTransformPairs->begin(); 00203 DtMeshTransformPairList::iterator end = meshTransformPairs->end(); 00204 for(; itr != end; ++itr) 00205 { 00206 if (itr->first->getNumTriangles() != 0) 00207 { 00208 numTriangles += itr->first->getNumTriangles(); 00209 00210 btCollisionObject* collisionObject = new btCollisionObject(); 00211 btBvhTriangleMeshShape* terrainShape = 00212 new btBvhTriangleMeshShape(itr->first, true); 00213 00214 collisionObject->setCollisionShape(terrainShape); 00215 00216 if (drawMode & DT_DRAW_POLYGONS) 00217 { 00218 collisionObject->setCollisionFlags(collisionObject->getCollisionFlags() & !btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT); 00219 } 00220 else 00221 { 00222 collisionObject->setCollisionFlags(collisionObject->getCollisionFlags() | btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT); 00223 } 00224 00225 osg::Matrix matrix; 00226 matrix = itr->second; 00227 btMatrix3x3 basisA; 00228 btVector3 origin; 00229 00230 getBasisAndOrigin(matrix, basisA, origin); 00231 00232 collisionObject->getWorldTransform().setBasis(basisA); 00233 collisionObject->getWorldTransform().setOrigin(origin); 00234 00235 collObjMeshPairs->push_back(std::make_pair(collisionObject, itr->first)); 00236 } 00237 } 00238 delete meshTransformPairs; 00239 00240 return numTriangles; 00241 }