Panda3D
bulletConvexPointCloudShape.cxx
1 // Filename: bulletConvexPointCloudShape.cxx
2 // Created by: enn0x (30Jan10)
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 "bulletConvexPointCloudShape.h"
16 
17 #include "geomVertexReader.h"
18 
19 TypeHandle BulletConvexPointCloudShape::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: BulletConvexPointCloudShape::Constructor
23 // Access: Published
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 BulletConvexPointCloudShape::
27 BulletConvexPointCloudShape(const PTA_LVecBase3 &points, LVecBase3 scale) {
28 
29  btVector3 btScale = LVecBase3_to_btVector3(scale);
30 
31  // Convert points
32  btVector3 *btPoints = new btVector3[points.size()];
33 
34  int i = 0;
35  PTA_LVecBase3::const_iterator it;
36  for (it=points.begin(); it!=points.end(); it++) {
37  btPoints[i] = LVecBase3_to_btVector3(*it);
38  i++;
39  }
40 
41  // Create shape
42  _shape = new btConvexPointCloudShape(btPoints, points.size(), btScale);
43  _shape->setUserPointer(this);
44 }
45 
46 ////////////////////////////////////////////////////////////////////
47 // Function: BulletConvexPointCloudShape::ptr
48 // Access: Public
49 // Description:
50 ////////////////////////////////////////////////////////////////////
51 btCollisionShape *BulletConvexPointCloudShape::
52 ptr() const {
53 
54  return _shape;
55 }
56 
57 ////////////////////////////////////////////////////////////////////
58 // Function: BulletConvexPointCloudShape::Constructor
59 // Access: Published
60 // Description:
61 ////////////////////////////////////////////////////////////////////
62 BulletConvexPointCloudShape::
63 BulletConvexPointCloudShape(const Geom *geom, LVecBase3 scale) {
64 
65  btVector3 btScale = LVecBase3_to_btVector3(scale);
66 
67  // Collect points
68  pvector<LPoint3> points;
69 
70  CPT(GeomVertexData) vdata = geom->get_vertex_data();
71  GeomVertexReader reader = GeomVertexReader(vdata, InternalName::get_vertex());
72 
73  while (!reader.is_at_end()) {
74  points.push_back(reader.get_data3());
75  }
76 
77  // Convert points
78  btVector3 *btPoints = new btVector3[points.size()];
79 
80  int i = 0;
82  for (it=points.begin(); it!=points.end(); it++) {
83  btPoints[i] = LVecBase3_to_btVector3(*it);
84  i++;
85  }
86 
87  // Create
88  _shape = new btConvexPointCloudShape(btPoints, points.size(), btScale);
89  _shape->setUserPointer(this);
90 }
91 
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
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