From 642f4a4e55ed76124264d7fb6a10e4a327d05efe Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 5 Feb 2021 23:48:41 +0100 Subject: [PATCH] bullet: Implement make_copy() for BulletGhostNode --- panda/src/bullet/bulletGhostNode.cxx | 33 ++++++++++++++++++++++++++++ panda/src/bullet/bulletGhostNode.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/panda/src/bullet/bulletGhostNode.cxx b/panda/src/bullet/bulletGhostNode.cxx index 38ccb1811c..d86dd59598 100644 --- a/panda/src/bullet/bulletGhostNode.cxx +++ b/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 ©) : + 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); +} + /** * */ diff --git a/panda/src/bullet/bulletGhostNode.h b/panda/src/bullet/bulletGhostNode.h index 1efc47a484..3c12ff0201 100644 --- a/panda/src/bullet/bulletGhostNode.h +++ b/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 ©); static TypedWritable *make_from_bam(const FactoryParams ¶ms); public: