소스 검색

bullet: support Plane class in BulletPlaneShape

rdb 7 년 전
부모
커밋
eda47c7f3b
2개의 변경된 파일26개의 추가작업 그리고 0개의 파일을 삭제
  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;
 
+/**
+ * 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;
 }
 
+/**
+ *
+ */
+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) {};
 
 PUBLISHED:
+  explicit BulletPlaneShape(LPlane plane);
   explicit BulletPlaneShape(const LVector3 &normal, PN_stdfloat constant);
   BulletPlaneShape(const BulletPlaneShape &copy);
   INLINE ~BulletPlaneShape();
 
+  LPlane get_plane() const;
   LVector3 get_plane_normal() const;
   PN_stdfloat get_plane_constant() const;
 
   static BulletPlaneShape *make_from_solid(const CollisionPlane *solid);
 
+  MAKE_PROPERTY(plane, get_plane);
   MAKE_PROPERTY(plane_normal, get_plane_normal);
   MAKE_PROPERTY(plane_constant, get_plane_constant);