mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 02:15:43 -04:00
Bullet fixes: copying compound shapes, compile warnings, motion state alignment
This commit is contained in:
parent
948ff8562d
commit
5ad900a413
@ -45,7 +45,16 @@ BulletBodyNode(const BulletBodyNode ©) :
|
|||||||
_shapes(copy._shapes)
|
_shapes(copy._shapes)
|
||||||
{
|
{
|
||||||
if (copy._shape && copy._shape->getShapeType() == COMPOUND_SHAPE_PROXYTYPE) {
|
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) {
|
else if (copy._shape && copy._shape->getShapeType() == EMPTY_SHAPE_PROXYTYPE) {
|
||||||
_shape = new btEmptyShape();
|
_shape = new btEmptyShape();
|
||||||
|
@ -55,7 +55,7 @@ void BulletGhostNode::
|
|||||||
parents_changed() {
|
parents_changed() {
|
||||||
|
|
||||||
Parents parents = get_parents();
|
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);
|
PandaNode *parent = parents.get_parent(i);
|
||||||
TypeHandle type = parent->get_type();
|
TypeHandle type = parent->get_type();
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ INLINE BulletRigidBodyNode::
|
|||||||
~BulletRigidBodyNode() {
|
~BulletRigidBodyNode() {
|
||||||
|
|
||||||
delete _rigid;
|
delete _rigid;
|
||||||
delete _motion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,16 +21,12 @@ TypeHandle BulletRigidBodyNode::_type_handle;
|
|||||||
*/
|
*/
|
||||||
BulletRigidBodyNode::
|
BulletRigidBodyNode::
|
||||||
BulletRigidBodyNode(const char *name) : BulletBodyNode(name) {
|
BulletRigidBodyNode(const char *name) : BulletBodyNode(name) {
|
||||||
|
|
||||||
// Motion state
|
|
||||||
_motion = new MotionState();
|
|
||||||
|
|
||||||
// Mass properties
|
// Mass properties
|
||||||
btScalar mass(0.0);
|
btScalar mass(0.0);
|
||||||
btVector3 inertia(0, 0, 0);
|
btVector3 inertia(0, 0, 0);
|
||||||
|
|
||||||
// construction info
|
// construction info
|
||||||
btRigidBody::btRigidBodyConstructionInfo ci(mass, _motion, _shape, inertia);
|
btRigidBody::btRigidBodyConstructionInfo ci(mass, &_motion, _shape, inertia);
|
||||||
|
|
||||||
// Additional damping
|
// Additional damping
|
||||||
if (bullet_additional_damping) {
|
if (bullet_additional_damping) {
|
||||||
@ -52,13 +48,13 @@ BulletRigidBodyNode(const char *name) : BulletBodyNode(name) {
|
|||||||
*/
|
*/
|
||||||
BulletRigidBodyNode::
|
BulletRigidBodyNode::
|
||||||
BulletRigidBodyNode(const BulletRigidBodyNode ©) :
|
BulletRigidBodyNode(const BulletRigidBodyNode ©) :
|
||||||
BulletBodyNode(copy)
|
BulletBodyNode(copy),
|
||||||
|
_motion(copy._motion)
|
||||||
{
|
{
|
||||||
_motion = new MotionState(*copy._motion);
|
|
||||||
_rigid = new btRigidBody(*copy._rigid);
|
_rigid = new btRigidBody(*copy._rigid);
|
||||||
_rigid->setUserPointer(this);
|
_rigid->setUserPointer(this);
|
||||||
_rigid->setCollisionShape(_shape);
|
_rigid->setCollisionShape(_shape);
|
||||||
_rigid->setMotionState(_motion);
|
_rigid->setMotionState(&_motion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -280,7 +276,7 @@ apply_central_impulse(const LVector3 &impulse) {
|
|||||||
void BulletRigidBodyNode::
|
void BulletRigidBodyNode::
|
||||||
transform_changed() {
|
transform_changed() {
|
||||||
|
|
||||||
if (_motion->sync_disabled()) return;
|
if (_motion.sync_disabled()) return;
|
||||||
|
|
||||||
NodePath np = NodePath::any_path((PandaNode *)this);
|
NodePath np = NodePath::any_path((PandaNode *)this);
|
||||||
CPT(TransformState) ts = np.get_net_transform();
|
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
|
// transform within the motion state. For dynamic bodies we need to store
|
||||||
// the net scale within the motion state, since Bullet might update the
|
// the net scale within the motion state, since Bullet might update the
|
||||||
// transform via MotionState::setWorldTransform.
|
// 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.
|
// For dynamic or static bodies we directly apply the new transform.
|
||||||
if (!is_kinematic()) {
|
if (!is_kinematic()) {
|
||||||
@ -334,7 +330,7 @@ sync_p2b() {
|
|||||||
void BulletRigidBodyNode::
|
void BulletRigidBodyNode::
|
||||||
sync_b2p() {
|
sync_b2p() {
|
||||||
|
|
||||||
_motion->sync_b2p((PandaNode *)this);
|
_motion.sync_b2p((PandaNode *)this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -589,7 +585,7 @@ pick_dirty_flag() {
|
|||||||
bool BulletRigidBodyNode::
|
bool BulletRigidBodyNode::
|
||||||
pick_dirty_flag() {
|
pick_dirty_flag() {
|
||||||
|
|
||||||
return _motion->pick_dirty_flag();
|
return _motion.pick_dirty_flag();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,7 +124,7 @@ private:
|
|||||||
bool _was_dirty;
|
bool _was_dirty;
|
||||||
};
|
};
|
||||||
|
|
||||||
MotionState *_motion;
|
MotionState _motion;
|
||||||
btRigidBody *_rigid;
|
btRigidBody *_rigid;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user