本文整理汇总了Python中panda3d.bullet.BulletWorld.getManifolds方法的典型用法代码示例。如果您正苦于以下问题:Python BulletWorld.getManifolds方法的具体用法?Python BulletWorld.getManifolds怎么用?Python BulletWorld.getManifolds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletWorld
的用法示例。
在下文中一共展示了BulletWorld.getManifolds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: World
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import getManifolds [as 别名]
#.........这里部分代码省略.........
self.worldRender.setShaderAuto()
def initialiseCollisionInfo(self):
"""
Sets up information required to later check for collisions
"""
self.previousContactForce = defaultdict(float)
self.collisionDetected = defaultdict(bool)
# List of node paths that we want to check for collisions on,
# with information about the collision sounds to play
self.collisionObjects = dict((v.rigidNode, v.collisionSound) for v in self.playerVehicles)
self.collisionObjects.update(self.level.collisionObjects)
# For assigning points etc, keep track of the player that
# controls each vehicle
self.vehicleControllers = dict(
(vehicle.rigidNode, player) for vehicle, player in zip(self.playerVehicles, self.playerControllers)
)
def checkCollisions(self, dt):
"""
Check to see what objects have collided and take actions
Eg. play sounds, update player points
"""
# Use the change in the sum of contact force magnitudes to
# check for collisions.
# Go though contact points, calculating the total contact
# force on all nodes of interest
totalContactForce = defaultdict(float)
for manifold in self.world.getManifolds():
nodes = (manifold.getNode0(), manifold.getNode1())
# Sum all points to get total impulse. Not sure if this is a
# good idea or we should use individual points, and if we
# need to use force direction rather than just magnitude
points = manifold.getManifoldPoints()
totalImpulse = sum((p.getAppliedImpulse() for p in points))
# Use force to get a more frame-rate independent measure of
# collision magnitude
force = totalImpulse / dt
for node in nodes:
if node in self.collisionObjects:
totalContactForce[node] += force
# If both objects are vehicles, then update points
if all(n in self.vehicleControllers for n in nodes):
self.calculateCollisionPoints(
manifold, self.vehicleControllers[nodes[0]], self.vehicleControllers[nodes[1]]
)
for node, force in totalContactForce.iteritems():
forceChange = force - self.previousContactForce[node]
if self.collisionDetected[node]:
# If a collision was recently detected, don't keep checking
# This avoids sounds repeatedly starting to play
continue
soundInfo = self.collisionObjects[node]
if forceChange > soundInfo.thresholdForce:
self.playCollisionSound(soundInfo, forceChange)
# Set collision detected, and then set a time out
# so that it is later reset to False
self.collisionDetected[node] = True
self.taskMgr.doMethodLater(
0.2, self.collisionDetected.update, "clearColision", extraArgs=[{node: False}]