OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bulletshape.hpp
Go to the documentation of this file.
1 #ifndef OPENMW_COMPONENTS_RESOURCE_BULLETSHAPE_H
2 #define OPENMW_COMPONENTS_RESOURCE_BULLETSHAPE_H
3 
4 #include <map>
5 
6 #include <osg/Object>
7 #include <osg/ref_ptr>
8 #include <osg/Vec3f>
9 
10 #include <BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h>
11 
12 class btCollisionShape;
13 
14 namespace Resource
15 {
16 
17  class BulletShapeInstance;
18  class BulletShape : public osg::Object
19  {
20  public:
21  BulletShape();
22  BulletShape(const BulletShape& copy, const osg::CopyOp& copyop);
23  virtual ~BulletShape();
24 
25  META_Object(Resource, BulletShape)
26 
27  btCollisionShape* mCollisionShape;
28 
29  // Used for actors. Note, ideally actors would use a separate loader - as it is
30  // we have to keep a redundant copy of the actor model around in mCollisionShape, which isn't used.
31  // For now, use one file <-> one resource for simplicity.
34 
35  // Stores animated collision shapes. If any collision nodes in the NIF are animated, then mCollisionShape
36  // will be a btCompoundShape (which consists of one or more child shapes).
37  // In this map, for each animated collision shape,
38  // we store the node's record index mapped to the child index of the shape in the btCompoundShape.
39  std::map<int, int> mAnimatedShapes;
40 
41  osg::ref_ptr<BulletShapeInstance> makeInstance() const;
42 
43  btCollisionShape* duplicateCollisionShape(const btCollisionShape* shape) const;
44 
45  btCollisionShape* getCollisionShape();
46 
47  private:
48 
49  void deleteShape(btCollisionShape* shape);
50  };
51 
52 
53  // An instance of a BulletShape that may have its own unique scaling set on the mCollisionShape.
54  // Vertex data is shallow-copied where possible. A ref_ptr to the original shape is held to keep vertex pointers intact.
56  {
57  public:
58  BulletShapeInstance(osg::ref_ptr<const BulletShape> source);
59 
60  private:
61  osg::ref_ptr<const BulletShape> mSource;
62  };
63 
64  // Subclass btBhvTriangleMeshShape to auto-delete the meshInterface
66  {
67  TriangleMeshShape(btStridingMeshInterface* meshInterface, bool useQuantizedAabbCompression, bool buildBvh = true)
68  : btBvhTriangleMeshShape(meshInterface, useQuantizedAabbCompression, buildBvh)
69  {
70  }
71 
73  {
74  delete getTriangleInfoMap();
75  delete m_meshInterface;
76  }
77  };
78 
79 
80 }
81 
82 #endif
META_Object(Resource, BulletShape) btCollisionShape *mCollisionShape
osg::Vec3f mCollisionBoxHalfExtents
Definition: bulletshape.hpp:32
osg::Vec3f mCollisionBoxTranslate
Definition: bulletshape.hpp:33
virtual ~BulletShape()
Definition: bulletshape.cpp:28
btCollisionShape * getCollisionShape()
Definition: bulletshape.cpp:80
void deleteShape(btCollisionShape *shape)
Definition: bulletshape.cpp:33
BulletShape()
Definition: bulletshape.cpp:14
std::map< int, int > mAnimatedShapes
Definition: bulletshape.hpp:39
osg::ref_ptr< BulletShapeInstance > makeInstance() const
Definition: bulletshape.cpp:85
Definition: bulletshape.hpp:55
btCollisionShape * duplicateCollisionShape(const btCollisionShape *shape) const
Definition: bulletshape.cpp:48
BulletShapeInstance(osg::ref_ptr< const BulletShape > source)
Definition: bulletshape.cpp:91
Definition: bulletshape.hpp:18
TriangleMeshShape(btStridingMeshInterface *meshInterface, bool useQuantizedAabbCompression, bool buildBvh=true)
Definition: bulletshape.hpp:67
Definition: bulletshape.hpp:65
osg::ref_ptr< const BulletShape > mSource
Definition: bulletshape.hpp:61
virtual ~TriangleMeshShape()
Definition: bulletshape.hpp:72