Bullet fixes: copying compound shapes, compile warnings, motion state alignment

This commit is contained in:
rdb 2016-11-29 22:43:28 +01:00
parent 948ff8562d
commit 5ad900a413
5 changed files with 20 additions and 16 deletions

View File

@ -45,7 +45,16 @@ BulletBodyNode(const BulletBodyNode &copy) :
_shapes(copy._shapes)
{
if (copy._shape && copy._shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) {
_shape = new btCompoundShape(copy._shape);
// btCompoundShape does not define a copy constructor. Manually copy.
btCompoundShape *shape = new btCompoundShape;
_shape = shape;
btCompoundShape *copy_shape = (btCompoundShape *)copy._shape;
int num_children = copy_shape->getNumChildShapes();
for (int i = 0; i < num_children; ++i) {
shape->addChildShape(copy_shape->getChildTransform(i),
copy_shape->getChildShape(i));
}
}
else if (copy._shape && copy._shape->getShapeType() == EMPTY_SHAPE_PROXYTYPE) {
_shape = new btEmptyShape();

View File

@ -55,7 +55,7 @@ void BulletGhostNode::
parents_changed() {
Parents parents = get_parents();
for (int i=0; i < parents.get_num_parents(); ++i) {
for (size_t i = 0; i < parents.get_num_parents(); ++i) {
PandaNode *parent = parents.get_parent(i);
TypeHandle type = parent->get_type();

View File

@ -18,7 +18,6 @@ INLINE BulletRigidBodyNode::
~BulletRigidBodyNode() {
delete _rigid;
delete _motion;
}
/**

View File

@ -21,16 +21,12 @@ TypeHandle BulletRigidBodyNode::_type_handle;
*/
BulletRigidBodyNode::
BulletRigidBodyNode(const char *name) : BulletBodyNode(name) {
// Motion state
_motion = new MotionState();
// Mass properties
btScalar mass(0.0);
btVector3 inertia(0, 0, 0);
// construction info
btRigidBody::btRigidBodyConstructionInfo ci(mass, _motion, _shape, inertia);
btRigidBody::btRigidBodyConstructionInfo ci(mass, &_motion, _shape, inertia);
// Additional damping
if (bullet_additional_damping) {
@ -52,13 +48,13 @@ BulletRigidBodyNode(const char *name) : BulletBodyNode(name) {
*/
BulletRigidBodyNode::
BulletRigidBodyNode(const BulletRigidBodyNode &copy) :
BulletBodyNode(copy)
BulletBodyNode(copy),
_motion(copy._motion)
{
_motion = new MotionState(*copy._motion);
_rigid = new btRigidBody(*copy._rigid);
_rigid->setUserPointer(this);
_rigid->setCollisionShape(_shape);
_rigid->setMotionState(_motion);
_rigid->setMotionState(&_motion);
}
/**
@ -280,7 +276,7 @@ apply_central_impulse(const LVector3 &impulse) {
void BulletRigidBodyNode::
transform_changed() {
if (_motion->sync_disabled()) return;
if (_motion.sync_disabled()) return;
NodePath np = NodePath::any_path((PandaNode *)this);
CPT(TransformState) ts = np.get_net_transform();
@ -290,7 +286,7 @@ transform_changed() {
// transform within the motion state. For dynamic bodies we need to store
// the net scale within the motion state, since Bullet might update the
// transform via MotionState::setWorldTransform.
_motion->set_net_transform(ts);
_motion.set_net_transform(ts);
// For dynamic or static bodies we directly apply the new transform.
if (!is_kinematic()) {
@ -334,7 +330,7 @@ sync_p2b() {
void BulletRigidBodyNode::
sync_b2p() {
_motion->sync_b2p((PandaNode *)this);
_motion.sync_b2p((PandaNode *)this);
}
/**
@ -589,7 +585,7 @@ pick_dirty_flag() {
bool BulletRigidBodyNode::
pick_dirty_flag() {
return _motion->pick_dirty_flag();
return _motion.pick_dirty_flag();
}
/**

View File

@ -124,7 +124,7 @@ private:
bool _was_dirty;
};
MotionState *_motion;
MotionState _motion;
btRigidBody *_rigid;
public: