当前位置: 首页>>代码示例>>Python>>正文


Python BulletWorld.getManifolds方法代码示例

本文整理汇总了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}]
开发者ID:Red-Gravel,项目名称:Red-Gravel,代码行数:70,代码来源:game.py


注:本文中的panda3d.bullet.BulletWorld.getManifolds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。