Browse Source

bullet: Implement make_copy() for BulletGhostNode

rdb 4 years ago
parent
commit
642f4a4e55
2 changed files with 35 additions and 0 deletions
  1. 33 0
      panda/src/bullet/bulletGhostNode.cxx
  2. 2 0
      panda/src/bullet/bulletGhostNode.h

+ 33 - 0
panda/src/bullet/bulletGhostNode.cxx

@@ -41,6 +41,39 @@ BulletGhostNode(const char *name) : BulletBodyNode(name) {
   _ghost->setCollisionShape(_shape);
 }
 
+/**
+ * Do not call the copy constructor directly; instead, use make_copy() or
+ * copy_subgraph() to make a copy of a node.
+ */
+BulletGhostNode::
+BulletGhostNode(const BulletGhostNode &copy) :
+  BulletBodyNode(copy),
+  _sync(TransformState::make_identity()),
+  _sync_disable(false),
+  _sync_local(false)
+{
+  // Initial transform - the node has no parent yet, so this is the local one
+  btTransform trans = TransformState_to_btTrans(get_transform());
+
+  // Ghost object
+  _ghost = new btPairCachingGhostObject();
+  _ghost->setUserPointer(this);
+  _ghost->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
+  _ghost->setWorldTransform(trans);
+  _ghost->setInterpolationWorldTransform(trans);
+  _ghost->setCollisionShape(_shape);
+}
+
+/**
+ * Returns a newly-allocated PandaNode that is a shallow copy of this one.  It
+ * will be a different pointer, but its internal data may or may not be shared
+ * with that of the original PandaNode.  No children will be copied.
+ */
+PandaNode *BulletGhostNode::
+make_copy() const {
+  return new BulletGhostNode(*this);
+}
+
 /**
  *
  */

+ 2 - 0
panda/src/bullet/bulletGhostNode.h

@@ -61,8 +61,10 @@ private:
 
 public:
   static void register_with_read_factory();
+  virtual PandaNode *make_copy() const;
 
 protected:
+  BulletGhostNode(const BulletGhostNode &copy);
   static TypedWritable *make_from_bam(const FactoryParams &params);
 
 public: