Implement make_copy() for BulletRigidBodyNode

This appears to be the last piece needed to load BulletRigidBodyNodes from BAM files.
This commit is contained in:
Mitchell Stokes 2016-10-27 13:56:02 +02:00 committed by rdb
parent 758cd523e2
commit 81dd4d97ad
4 changed files with 47 additions and 0 deletions

View File

@ -36,6 +36,25 @@ BulletBodyNode(const char *name) : PandaNode(name) {
set_into_collide_mask(CollideMask::all_on());
}
/**
*
*/
BulletBodyNode::
BulletBodyNode(const BulletBodyNode &copy) :
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.

View File

@ -33,6 +33,7 @@ class BulletShape;
class EXPCL_PANDABULLET BulletBodyNode : public PandaNode {
protected:
BulletBodyNode(const char *name);
BulletBodyNode(const BulletBodyNode &copy);
PUBLISHED:
INLINE ~BulletBodyNode();

View File

@ -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 &copy) :
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);
}
/**
*
*/

View File

@ -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 &copy);
static TypedWritable *make_from_bam(const FactoryParams &params);
void fillin(DatagramIterator &scan, BamReader *manager);