Panda3D
 All Classes Functions Variables Enumerations
bulletTriangleMeshShape.cxx
1 // Filename: bulletTriangleMeshShape.cxx
2 // Created by: enn0x (09Feb10)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "bulletTriangleMeshShape.h"
16 #include "bulletTriangleMesh.h"
17 
18 #include "nodePathCollection.h"
19 #include "geomNode.h"
20 #include "geomVertexReader.h"
21 
22 TypeHandle BulletTriangleMeshShape::_type_handle;
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function: BulletTriangleMeshShape::Constructor
26 // Access: Published
27 // Description: The parameters 'compress' and 'bvh' are only used
28 // if 'dynamic' is set to FALSE.
29 ////////////////////////////////////////////////////////////////////
31 BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress, bool bvh) {
32 
33  // Assert that mesh is not NULL
34  if (!mesh) {
35  bullet_cat.warning() << "mesh is NULL! creating new mesh." << endl;
36  mesh = new BulletTriangleMesh();
37  }
38 
39  // Assert that mesh has at least one triangle
40  if (mesh->get_num_triangles() == 0) {
41  bullet_cat.warning() << "mesh has zero triangles! adding degenerated triangle." << endl;
42  mesh->add_triangle(LPoint3::zero(), LPoint3::zero(), LPoint3::zero());
43  }
44 
45  // Retain a pointer to the mesh, to prevent it from being deleted
46  _mesh = mesh;
47 
48  // Dynamic will create a GImpact mesh shape
49  if (dynamic) {
50 
51  _gimpact_shape = new btGImpactMeshShape(mesh->ptr());
52  _gimpact_shape->updateBound();
53  _gimpact_shape->setUserPointer(this);
54 
55  _bvh_shape = NULL;
56  }
57 
58  // Static will create a Bvh mesh shape
59  else {
60 
61  _bvh_shape = new btBvhTriangleMeshShape(mesh->ptr(), compress, bvh);
62  _bvh_shape->setUserPointer(this);
63 
64  _gimpact_shape = NULL;
65  }
66 }
67 
68 ////////////////////////////////////////////////////////////////////
69 // Function: BulletTriangleMeshShape::ptr
70 // Access: Public
71 // Description:
72 ////////////////////////////////////////////////////////////////////
73 btCollisionShape *BulletTriangleMeshShape::
74 ptr() const {
75 
76  if (_bvh_shape) {
77  return _bvh_shape;
78  }
79 
80  if (_gimpact_shape) {
81  return _gimpact_shape;
82  }
83 
84  return NULL;
85 }
86 
87 ////////////////////////////////////////////////////////////////////
88 // Function: BulletTriangleMeshShape::refit_tree
89 // Access: Published
90 // Description:
91 ////////////////////////////////////////////////////////////////////
92 void BulletTriangleMeshShape::
93 refit_tree(const LPoint3 &aabb_min, const LPoint3 &aabb_max) {
94 
95  nassertv(!aabb_max.is_nan());
96  nassertv(!aabb_max.is_nan());
97 
98  nassertv(this->is_static());
99 
100  _bvh_shape->refitTree(LVecBase3_to_btVector3(aabb_min),
101  LVecBase3_to_btVector3(aabb_max));
102 }
103 
static const LPoint3f & zero()
Returns a zero-length point.
Definition: lpoint3.h:258
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
Definition: lvecBase3.h:463
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
BulletTriangleMeshShape(BulletTriangleMesh *mesh, bool dynamic, bool compress=true, bool bvh=true)
The parameters &#39;compress&#39; and &#39;bvh&#39; are only used if &#39;dynamic&#39; is set to FALSE.