本文整理汇总了Python中panda3d.bullet.BulletWorld.remove_ghost方法的典型用法代码示例。如果您正苦于以下问题:Python BulletWorld.remove_ghost方法的具体用法?Python BulletWorld.remove_ghost怎么用?Python BulletWorld.remove_ghost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletWorld
的用法示例。
在下文中一共展示了BulletWorld.remove_ghost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: World
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import remove_ghost [as 别名]
#.........这里部分代码省略.........
np = self.scene.attach_new_node(debug_node)
np.show()
self.physics.set_debug_node(debug_node)
def get_incarn(self):
return random.choice(self.incarnators)
def attach(self, obj):
assert hasattr(obj, 'world') and hasattr(obj, 'name')
assert obj.name not in self.objects
obj.world = self
if obj.name.startswith('Incarnator'):
self.incarnators.append(obj)
if hasattr(obj, 'create_node') and hasattr(obj, 'create_solid'):
# Let each object define it's own NodePath, then reparent them.
obj.node = obj.create_node()
obj.solid = obj.create_solid()
if obj.solid:
if isinstance(obj.solid, BulletRigidBodyNode):
self.physics.attach_rigid_body(obj.solid)
elif isinstance(obj.solid, BulletGhostNode):
self.physics.attach_ghost(obj.solid)
if obj.node:
if obj.solid:
# If this is a solid visible object, create a new physics node and reparent the visual node to that.
phys_node = self.scene.attach_new_node(obj.solid)
obj.node.reparent_to(phys_node)
obj.node = phys_node
else:
# Otherwise just reparent the visual node to the root.
obj.node.reparent_to(self.scene)
elif obj.solid:
obj.node = self.scene.attach_new_node(obj.solid)
if obj.solid and obj.collide_bits is not None:
obj.solid.set_into_collide_mask(obj.collide_bits)
self.objects[obj.name] = obj
# Let the object know it has been attached.
obj.attached()
return obj
def create_hector(self, name=None):
# TODO: get random incarn, start there
h = self.attach(Hector(name))
h.move((0, 15, 0))
return h
def register_updater(self, obj):
assert isinstance(obj, WorldObject)
self.updatables.add(obj)
def register_updater_later(self, obj):
assert isinstance(obj, WorldObject)
self.updatables_to_add.add(obj)
def update(self, task):
"""
Called every frame to update the physics, etc.
"""
dt = globalClock.getDt()
for obj in self.updatables_to_add:
self.updatables.add(obj)
self.updatables_to_add = set()
for obj in self.updatables:
obj.update(dt)
self.updatables -= self.garbage
self.collidables -= self.garbage
while True:
if len(self.garbage) < 1:
break;
trash = self.garbage.pop()
if(isinstance(trash.solid, BulletGhostNode)):
self.physics.remove_ghost(trash.solid)
if(isinstance(trash.solid, BulletRigidBodyNode)):
self.physics.remove_rigid_body(trash.solid)
if hasattr(trash, 'dead'):
trash.dead()
trash.node.remove_node()
del(trash)
self.physics.do_physics(dt)
for obj in self.collidables:
result = self.physics.contact_test(obj.node.node())
for contact in result.get_contacts():
obj1 = self.objects.get(contact.get_node0().get_name())
obj2 = self.objects.get(contact.get_node1().get_name())
if obj1 and obj2:
# Check the collision bits to see if the two objects should collide.
should_collide = obj1.collide_bits & obj2.collide_bits
if not should_collide.is_zero():
pt = contact.get_manifold_point()
if obj1 in self.collidables:
obj1.collision(obj2, pt, True)
if obj2 in self.collidables:
obj2.collision(obj1, pt, False)
return task.cont
示例2: World
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import remove_ghost [as 别名]
#.........这里部分代码省略.........
expl_body = BulletGhostNode("expl")
expl_shape = BulletSphereShape(radius)
expl_body.add_shape(expl_shape)
expl_bodyNP = self.render.attach_new_node(expl_body)
expl_bodyNP.set_pos(center)
self.physics.attach_ghost(expl_body)
result = self.physics.contact_test(expl_body)
for contact in result.getContacts():
n0_name = contact.getNode0().get_name()
n1_name = contact.getNode1().get_name()
obj = None
try:
obj = self.objects[n1_name]
except:
break
if n0_name == "expl" and n1_name not in EXPLOSIONS_DONT_PUSH and not n1_name.startswith('Walker'):
# repeat contact test with just this pair of objects
# otherwise all manifold point values will be the same
# for all objects in original result
real_c = self.physics.contact_test_pair(expl_body, obj.solid)
mpoint = real_c.getContacts()[0].getManifoldPoint()
distance = mpoint.getDistance()
if distance < 0:
if hasattr(obj, 'decompose'):
obj.decompose()
else:
expl_vec = Vec3(mpoint.getPositionWorldOnA() - mpoint.getPositionWorldOnB())
expl_vec.normalize()
magnitude = force * 1.0/math.sqrt(abs(radius - abs(distance)))
obj.solid.set_active(True)
obj.solid.apply_impulse(expl_vec*magnitude, mpoint.getLocalPointB())
if hasattr(obj, 'damage'):
obj.damage(magnitude/5)
self.physics.remove_ghost(expl_body)
expl_bodyNP.detach_node()
del(expl_body, expl_bodyNP)
def do_plasma_push(self, plasma, node, energy):
obj = None
try:
obj = self.objects[node]
except:
raise
if node not in EXPLOSIONS_DONT_PUSH and not node.startswith('Walker'):
if hasattr(obj, 'decompose'):
obj.decompose()
else:
solid = obj.solid
dummy_node = NodePath('tmp')
dummy_node.set_hpr(plasma.hpr)
dummy_node.set_pos(plasma.pos)
f_vec = render.get_relative_vector(dummy_node, Vec3(0,0,1))
local_point = (obj.node.get_pos() - dummy_node.get_pos()) *-1
f_vec.normalize()
solid.set_active(True)
try:
solid.apply_impulse(f_vec*(energy*35), Point3(local_point))
except:
pass
del(dummy_node)
if hasattr(obj, 'damage'):
obj.damage(energy*5)
def update(self, task):