Browse Source

Support for optional TransformState when adding a Geom to a triangle mesh or convex mesh.

enn0x 13 years ago
parent
commit
b7eb296cff

+ 7 - 2
panda/src/bullet/bulletConvexHullShape.cxx

@@ -78,7 +78,12 @@ add_array(const PTA_LVecBase3 &points) {
 //  Description:
 ////////////////////////////////////////////////////////////////////
 void BulletConvexHullShape::
-add_geom(const Geom *geom) {
+add_geom(const Geom *geom, CPT(TransformState) ts) {
+
+  nassertv(geom);
+  nassertv(ts);
+
+  LMatrix4 m = ts->get_mat();
 
   // Collect points
   pvector<LPoint3> points;
@@ -87,7 +92,7 @@ add_geom(const Geom *geom) {
   GeomVertexReader reader = GeomVertexReader(vdata, InternalName::get_vertex());
 
   while (!reader.is_at_end()) {
-    points.push_back(reader.get_data3());
+    points.push_back(m.xform_point(reader.get_data3()));
   }
 
   // Create shape

+ 2 - 1
panda/src/bullet/bulletConvexHullShape.h

@@ -38,7 +38,8 @@ PUBLISHED:
 
   void add_point(const LPoint3 &p);
   void add_array(const PTA_LVecBase3 &points);
-  void add_geom(const Geom *geom);
+  void add_geom(const Geom *geom,
+                CPT(TransformState) ts=TransformState::make_identity());
 
 public:
   virtual btCollisionShape *ptr() const;

+ 7 - 2
panda/src/bullet/bulletTriangleMesh.cxx

@@ -101,7 +101,12 @@ get_welding_distance() const {
 //  Description:
 ////////////////////////////////////////////////////////////////////
 void BulletTriangleMesh::
-add_geom(const Geom *geom, bool remove_duplicate_vertices) {
+add_geom(const Geom *geom, bool remove_duplicate_vertices, CPT(TransformState) ts) {
+
+  nassertv(geom);
+  nassertv(ts);
+
+  LMatrix4 m = ts->get_mat();
 
   // Collect points
   pvector<LPoint3> points;
@@ -110,7 +115,7 @@ add_geom(const Geom *geom, bool remove_duplicate_vertices) {
   GeomVertexReader reader = GeomVertexReader(vdata, InternalName::get_vertex());
 
   while (!reader.is_at_end()) {
-    points.push_back(reader.get_data3());
+    points.push_back(m.xform_point(reader.get_data3()));
   }
 
   // Convert points

+ 2 - 1
panda/src/bullet/bulletTriangleMesh.h

@@ -45,7 +45,8 @@ PUBLISHED:
                  const PTA_int &indices,
                  bool remove_duplicate_vertices=false);
   void add_geom(const Geom *geom, 
-                bool remove_duplicate_vertices=false);
+                bool remove_duplicate_vertices=false,
+                CPT(TransformState) ts=TransformState::make_identity());
 
   void set_welding_distance(PN_stdfloat distance);
   void preallocate(int num_verts, int num_indices);