28 _sync = TransformState::make_identity();
29 _sync_disable =
false;
33 btTransform trans = btTransform::getIdentity();
36 _ghost =
new btPairCachingGhostObject();
37 _ghost->setUserPointer(
this);
38 _ghost->setCollisionFlags(btCollisionObject::CF_NO_CONTACT_RESPONSE);
39 _ghost->setWorldTransform(trans);
40 _ghost->setInterpolationWorldTransform(trans);
41 _ghost->setCollisionShape(_shape);
47 btCollisionObject *BulletGhostNode::
56 void BulletGhostNode::
61 for (
size_t i = 0; i < parents.get_num_parents(); ++i) {
65 if (BulletRigidBodyNode::get_class_type() == type ||
66 BulletSoftBodyNode::get_class_type() == type ||
67 BulletGhostNode::get_class_type() == type ||
68 type.
is_derived_from(BulletBaseCharacterControllerNode::get_class_type())) {
81 void BulletGhostNode::
82 do_transform_changed() {
84 if (_sync_disable)
return;
89 LMatrix4 m_sync = _sync->
get_mat();
90 LMatrix4 m_ts = ts->get_mat();
92 if (!m_sync.almost_equal(m_ts)) {
95 btTransform trans = TransformState_to_btTrans(ts);
96 _ghost->setWorldTransform(trans);
97 _ghost->setInterpolationWorldTransform(trans);
99 if (ts->has_scale()) {
100 LVecBase3 scale = ts->get_scale();
101 if (!scale.almost_equal(LVecBase3(1.0f, 1.0f, 1.0f))) {
103 shape->do_set_local_scale(scale);
110 void BulletGhostNode::
111 transform_changed() {
113 if (_sync_disable)
return;
117 do_transform_changed();
123 int BulletGhostNode::
124 get_num_overlapping_nodes()
const {
127 return _ghost->getNumOverlappingObjects();
134 get_overlapping_node(
int idx)
const {
137 nassertr(idx >=0 && idx < _ghost->getNumOverlappingObjects(),
nullptr);
139 btCollisionObject *
object = _ghost->getOverlappingObject(idx);
140 return (
object) ? (
PandaNode *)object->getUserPointer() :
nullptr;
149 do_transform_changed();
159 LVecBase3 scale = np.get_net_transform()->
get_scale();
161 btTransform trans = _ghost->getWorldTransform();
164 LMatrix4 m_sync = _sync->get_mat();
165 LMatrix4 m_ts = ts->get_mat();
167 if (!m_sync.almost_equal(m_ts)) {
169 _sync_disable =
true;
171 _sync_disable =
false;