Panda3D
bulletConvexHullShape.cxx
1 // Filename: bulletConvexHullShape.cxx
2 // Created by: enn0x (26Jan10)
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 "bulletConvexHullShape.h"
16 
17 #include "nodePathCollection.h"
18 #include "geomNode.h"
19 #include "geomVertexReader.h"
20 
21 TypeHandle BulletConvexHullShape::_type_handle;
22 
23 ////////////////////////////////////////////////////////////////////
24 // Function: BulletConvexHullShape::Constructor
25 // Access: Published
26 // Description:
27 ////////////////////////////////////////////////////////////////////
28 BulletConvexHullShape::
29 BulletConvexHullShape() {
30 
31  _shape = new btConvexHullShape(NULL, 0);
32  _shape->setUserPointer(this);
33 }
34 
35 ////////////////////////////////////////////////////////////////////
36 // Function: BulletConvexHullShape::ptr
37 // Access: Public
38 // Description:
39 ////////////////////////////////////////////////////////////////////
40 btCollisionShape *BulletConvexHullShape::
41 ptr() const {
42 
43  return _shape;
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: BulletConvexHullShape::add_point
48 // Access: Published
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 void BulletConvexHullShape::
52 add_point(const LPoint3 &p) {
53 
54  _shape->addPoint(LVecBase3_to_btVector3(p));
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: BulletConvexHullShape::Constructor
59 // Access: Published
60 // Description:
61 ////////////////////////////////////////////////////////////////////
62 void BulletConvexHullShape::
63 add_array(const PTA_LVecBase3 &points) {
64 
65  _shape = new btConvexHullShape(NULL, 0);
66  _shape->setUserPointer(this);
67 
68  PTA_LVecBase3::const_iterator it;
69  for (it=points.begin(); it!=points.end(); it++) {
70  LVecBase3 v = *it;
71  _shape->addPoint(LVecBase3_to_btVector3(v));
72  }
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function: BulletConvexHullShape::Constructor
77 // Access: Published
78 // Description:
79 ////////////////////////////////////////////////////////////////////
80 void BulletConvexHullShape::
81 add_geom(const Geom *geom, const TransformState *ts) {
82 
83  nassertv(geom);
84  nassertv(ts);
85 
86  LMatrix4 m = ts->get_mat();
87 
88  // Collect points
89  pvector<LPoint3> points;
90 
91  CPT(GeomVertexData) vdata = geom->get_vertex_data();
92  GeomVertexReader reader = GeomVertexReader(vdata, InternalName::get_vertex());
93 
94  while (!reader.is_at_end()) {
95  points.push_back(m.xform_point(reader.get_data3()));
96  }
97 
98  // Create shape
99  _shape = new btConvexHullShape(NULL, 0);
100  _shape->setUserPointer(this);
101 
103  for (it=points.begin(); it!=points.end(); it++) {
104  _shape->addPoint(LVecBase3_to_btVector3(*it));
105  }
106 }
107 
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
LVecBase3f xform_point(const LVecBase3f &v) const
The matrix transforms a 3-component point (including translation component) and returns the result...
Definition: lmatrix.h:1667
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
This defines the actual numeric vertex data stored in a Geom, in the structure defined by a particula...
A container for geometry primitives.
Definition: geom.h:58
const LVecBase3 & get_data3()
Returns the data associated with the read row, expressed as a 3-component value, and advances the rea...
This object provides a high-level interface for quickly reading a sequence of numeric values from a v...
bool is_at_end() const
Returns true if the reader is currently at the end of the list of vertices, false otherwise...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85