diff --git a/panda/src/bullet/bulletBodyNode.cxx b/panda/src/bullet/bulletBodyNode.cxx index e8dbe968f2..6580c79722 100644 --- a/panda/src/bullet/bulletBodyNode.cxx +++ b/panda/src/bullet/bulletBodyNode.cxx @@ -36,6 +36,25 @@ BulletBodyNode(const char *name) : PandaNode(name) { set_into_collide_mask(CollideMask::all_on()); } +/** + * + */ +BulletBodyNode:: +BulletBodyNode(const BulletBodyNode ©) : + PandaNode(copy), + _shapes(copy._shapes) +{ + if (copy._shape && copy._shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) { + _shape = new btCompoundShape(copy._shape); + } + else if (copy._shape && copy._shape->getShapeType() == EMPTY_SHAPE_PROXYTYPE) { + _shape = new btEmptyShape(); + } + else { + _shape = copy._shape; + } +} + /** * Returns the subset of CollideMask bits that may be set for this particular * type of PandaNode. For BodyNodes this returns all bits on. diff --git a/panda/src/bullet/bulletBodyNode.h b/panda/src/bullet/bulletBodyNode.h index 42f43cfd6a..53fe6c7136 100644 --- a/panda/src/bullet/bulletBodyNode.h +++ b/panda/src/bullet/bulletBodyNode.h @@ -33,6 +33,7 @@ class BulletShape; class EXPCL_PANDABULLET BulletBodyNode : public PandaNode { protected: BulletBodyNode(const char *name); + BulletBodyNode(const BulletBodyNode ©); PUBLISHED: INLINE ~BulletBodyNode(); diff --git a/panda/src/bullet/bulletRigidBodyNode.cxx b/panda/src/bullet/bulletRigidBodyNode.cxx index cc5f5945f5..23c6d17afd 100644 --- a/panda/src/bullet/bulletRigidBodyNode.cxx +++ b/panda/src/bullet/bulletRigidBodyNode.cxx @@ -46,6 +46,31 @@ BulletRigidBodyNode(const char *name) : BulletBodyNode(name) { _rigid->setUserPointer(this); } +/** + * Do not call the copy constructor directly; instead, use make_copy() or + * copy_subgraph() to make a copy of a node. + */ +BulletRigidBodyNode:: +BulletRigidBodyNode(const BulletRigidBodyNode ©) : + BulletBodyNode(copy) +{ + _motion = new MotionState(*copy._motion); + _rigid = new btRigidBody(*copy._rigid); + _rigid->setUserPointer(this); + _rigid->setCollisionShape(_shape); + _rigid->setMotionState(_motion); +} + +/** + * 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 *BulletRigidBodyNode:: +make_copy() const { + return new BulletRigidBodyNode(*this); +} + /** * */ diff --git a/panda/src/bullet/bulletRigidBodyNode.h b/panda/src/bullet/bulletRigidBodyNode.h index 2d6b54f2f3..42b2495aff 100644 --- a/panda/src/bullet/bulletRigidBodyNode.h +++ b/panda/src/bullet/bulletRigidBodyNode.h @@ -130,8 +130,10 @@ private: public: static void register_with_read_factory(); virtual void write_datagram(BamWriter *manager, Datagram &dg); + virtual PandaNode *make_copy() const; protected: + BulletRigidBodyNode(const BulletRigidBodyNode ©); static TypedWritable *make_from_bam(const FactoryParams ¶ms); void fillin(DatagramIterator &scan, BamReader *manager);