VR-Forces 4.1 Class Documentation
osgToBullet.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2010 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 /*******************************************************************************
6 ** $RCSfile: $ $Revision: $ $State: $
7 *******************************************************************************/
8 
11 
13 
14 #pragma once
15 
16 
19 #include <btBulletCollisionCommon.h>
20 #include <memory>
22 #include <vlutil/vlSmartPointers.h>
23 #include <vlutil/vlFilename.h>
24 #include <geometry/surface.h>
25 
27 #include <osg/Matrix>
28 #include <vrvOsg/DtOsgRenderer.h>
30 
32 #include <vlutil/vlSmartPointers.h>
33 
35 #include <memory>
36 #include "vlutil/vlFilename.h"
37 
38 class btTriangleMesh;
39 class Coordinate_System;
40 
41 
42 
43 namespace osg
44 {
45  class Node;
46  class LOD;
47 }
48 
50 //This should move to surface.h
52 
53 
54 
55 namespace makVrf {
57  {
58 
59  public:
60 
63 
66 
69 
72 
74  virtual bool init(const DtFilename filename, bool displayWarning = false);
75 
77  virtual bool get(std::istream& stream);
78 
80  virtual bool processToken(std::istream& stream, DtString& token);
81 
83  virtual bool characteristicsFromString(const char* str,
84  unsigned int& characteristics, int& position);
85 
86  protected:
87 
89  virtual DtSurface* createSurface();
90 
91  protected:
92  typedef std::map <DtString, DtSurface::DtCharacteristics> DtSurfaceStringToCharacteristics;
93  typedef DtSurfaceStringToCharacteristics::const_iterator DtSurfStrToCharsConstIter;
94  typedef DtSurfaceStringToCharacteristics::iterator DtSurfStrToCharsIter;
95 
97  static const DtString theMatchString;
99 
100  private:
101 
108  std::set<std::string> myPrintedWarnings;
109 
110  };
111 
112 
113 }
114 
115 //class makVrv::DtOsgRenderer::RootList;
116 
117 
120 {
121 public:
122  DtTriangleMeshWithSoil (bool use32bitIndices=true,bool use4componentVertices=true) :
123  btTriangleMesh(use32bitIndices, use4componentVertices),
124  myUseSurfaceArray(false) {}
126 
127  void addTriangleWithSurface(const btVector3& vertex0,const btVector3& vertex1,const btVector3& vertex2,
128  const DtSurface& surface, bool removeDuplicateVertices=false);
129 
130  DtSurface triangleSurface(unsigned int triangleIndex) const;
131 
132 protected:
135  void initializeSurfaceArray();
136 
139  void syncSurfaceArray();
140 
146  btAlignedObjectArray<DtSurface> mySurfaceTypes;
147 };
148 
149 typedef std::map<osg::Geode*, DtTriangleMeshWithSoil*> DtGeodeToMeshMap;
150 typedef std::list<std::pair<btCollisionObject*, DtTriangleMeshWithSoil*> >
152 typedef std::list<std::pair<DtTriangleMeshWithSoil*, osg::Matrix> >
154 
159 {
161  : osgRenderer(r), sceneRoot(sr) {};
164 };
165 
169  unsigned int& numTriangleOut, const osg::Matrix& baseTransform,
170  const DtFilename& surfaceCharacterFilename = "");
171 
175  unsigned int& numTriangleOut, const osg::Matrix& baseTransform,
176  const DtFilename& surfaceCharacterFilename = "");
177 
179 
180 void getBasisAndOrigin(osg::Matrix& matrix,
181  btMatrix3x3& basisA, btVector3& origin);
182 
186 template<typename T_Node>
188  T_Node node,
189  DtCollObjMeshPairList* collObjMeshPairs, const DtDrawMode& drawMode,
190  osg::Matrix* worldMatrix = NULL,
191  const DtFilename& surfaceCharacterFilename = "")
192 {
193  unsigned int numTriangles = 0;
194  osg::Matrix baseMatrix;
195  if (worldMatrix)
196  {
197  baseMatrix = *worldMatrix;
198  }
200  node, numTriangles, baseMatrix, surfaceCharacterFilename);
201 
202  DtMeshTransformPairList::iterator itr = meshTransformPairs->begin();
203  DtMeshTransformPairList::iterator end = meshTransformPairs->end();
204  for(; itr != end; ++itr)
205  {
206  if (itr->first->getNumTriangles() != 0)
207  {
208  numTriangles += itr->first->getNumTriangles();
209 
210  btCollisionObject* collisionObject = new btCollisionObject();
211  btBvhTriangleMeshShape* terrainShape =
212  new btBvhTriangleMeshShape(itr->first, true);
213 
214  collisionObject->setCollisionShape(terrainShape);
215 
216  if (drawMode & DT_DRAW_POLYGONS)
217  {
218  collisionObject->setCollisionFlags(collisionObject->getCollisionFlags() & !btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT);
219  }
220  else
221  {
222  collisionObject->setCollisionFlags(collisionObject->getCollisionFlags() | btCollisionObject::CF_DISABLE_VISUALIZE_OBJECT);
223  }
224 
225  osg::Matrix matrix;
226  matrix = itr->second;
227  btMatrix3x3 basisA;
228  btVector3 origin;
229 
230  getBasisAndOrigin(matrix, basisA, origin);
231 
232  collisionObject->getWorldTransform().setBasis(basisA);
233  collisionObject->getWorldTransform().setOrigin(origin);
234 
235  collObjMeshPairs->push_back(std::make_pair(collisionObject, itr->first));
236  }
237  }
238  delete meshTransformPairs;
239 
240  return numTriangles;
241 }

Document ID: Generated on Tue Jan 29 18:21:16 EST 2013 from SVN revision 123193
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)