Browse Source

bullet: support Plane class in BulletPlaneShape

rdb 7 years ago
parent
commit
eda47c7f3b
2 changed files with 26 additions and 0 deletions
  1. 23 0
      panda/src/bullet/bulletPlaneShape.cxx
  2. 3 0
      panda/src/bullet/bulletPlaneShape.h

+ 23 - 0
panda/src/bullet/bulletPlaneShape.cxx

@@ -15,6 +15,18 @@
 
 
 TypeHandle BulletPlaneShape::_type_handle;
 TypeHandle BulletPlaneShape::_type_handle;
 
 
+/**
+ * Creates a plane shape from a plane definition.
+ */
+BulletPlaneShape::
+BulletPlaneShape(LPlane plane) {
+
+  btVector3 btNormal = LVecBase3_to_btVector3(plane.get_normal());
+
+  _shape = new btStaticPlaneShape(btNormal, plane.get_w());
+  _shape->setUserPointer(this);
+}
+
 /**
 /**
  *
  *
  */
  */
@@ -50,6 +62,17 @@ ptr() const {
   return _shape;
   return _shape;
 }
 }
 
 
+/**
+ *
+ */
+LPlane BulletPlaneShape::
+get_plane() const {
+  LightMutexHolder holder(BulletWorld::get_global_lock());
+
+  btVector3 normal = _shape->getPlaneNormal();
+  return LPlane(normal[0], normal[1], normal[2], (PN_stdfloat)_shape->getPlaneConstant());
+}
+
 /**
 /**
  *
  *
  */
  */

+ 3 - 0
panda/src/bullet/bulletPlaneShape.h

@@ -32,15 +32,18 @@ private:
   INLINE BulletPlaneShape() : _shape(nullptr) {};
   INLINE BulletPlaneShape() : _shape(nullptr) {};
 
 
 PUBLISHED:
 PUBLISHED:
+  explicit BulletPlaneShape(LPlane plane);
   explicit BulletPlaneShape(const LVector3 &normal, PN_stdfloat constant);
   explicit BulletPlaneShape(const LVector3 &normal, PN_stdfloat constant);
   BulletPlaneShape(const BulletPlaneShape &copy);
   BulletPlaneShape(const BulletPlaneShape &copy);
   INLINE ~BulletPlaneShape();
   INLINE ~BulletPlaneShape();
 
 
+  LPlane get_plane() const;
   LVector3 get_plane_normal() const;
   LVector3 get_plane_normal() const;
   PN_stdfloat get_plane_constant() const;
   PN_stdfloat get_plane_constant() const;
 
 
   static BulletPlaneShape *make_from_solid(const CollisionPlane *solid);
   static BulletPlaneShape *make_from_solid(const CollisionPlane *solid);
 
 
+  MAKE_PROPERTY(plane, get_plane);
   MAKE_PROPERTY(plane_normal, get_plane_normal);
   MAKE_PROPERTY(plane_normal, get_plane_normal);
   MAKE_PROPERTY(plane_constant, get_plane_constant);
   MAKE_PROPERTY(plane_constant, get_plane_constant);