本文整理汇总了Python中panda3d.bullet.BulletWorld.setPythonFilterCallback方法的典型用法代码示例。如果您正苦于以下问题:Python BulletWorld.setPythonFilterCallback方法的具体用法?Python BulletWorld.setPythonFilterCallback怎么用?Python BulletWorld.setPythonFilterCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletWorld
的用法示例。
在下文中一共展示了BulletWorld.setPythonFilterCallback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import setPythonFilterCallback [as 别名]
#.........这里部分代码省略.........
def toggleWireframe(self):
base.toggleWireframe()
def toggleTexture(self):
base.toggleTexture()
def toggleDebug(self):
if self.debugNP.isHidden():
self.debugNP.show()
else:
self.debugNP.hide()
def doScreenshot(self):
base.screenshot('Bullet')
def doSelect(self, i):
self.boxNP = self.boxes[i]
# ____TASK___
def processInput(self, dt):
force = Vec3(0, 0, 0)
torque = Vec3(0, 0, 0)
if inputState.isSet('forward'): force.setY( 1.0)
if inputState.isSet('reverse'): force.setY(-1.0)
if inputState.isSet('left'): force.setX(-1.0)
if inputState.isSet('right'): force.setX( 1.0)
if inputState.isSet('turnLeft'): torque.setZ( 1.0)
if inputState.isSet('turnRight'): torque.setZ(-1.0)
force *= 30.0
torque *= 10.0
self.boxNP.node().setActive(True)
self.boxNP.node().applyCentralForce(force)
self.boxNP.node().applyTorque(torque)
def update(self, task):
dt = globalClock.getDt()
self.processInput(dt)
self.world.doPhysics(dt)
return task.cont
def cleanup(self):
self.world = None
self.worldNP.removeNode()
def setup(self):
self.worldNP = render.attachNewNode('World')
# World
self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.show()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
self.world.setPythonFilterCallback(self.filter)
# Ground
shape = BulletPlaneShape(Vec3(0, 0, 1), -1)
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Ground'))
np.node().addShape(shape)
np.setPos(0, 0, -1)
np.setPythonTag('foo', 2)
self.world.attachRigidBody(np.node())
# Box 1
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-1'))
np.node().setMass(1.0)
np.node().addShape(shape)
np.setPos(3, 0, 4)
np.setPythonTag('foo', 0)
self.world.attachRigidBody(np.node())
self.boxNP = np
# Box 2
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
np = self.worldNP.attachNewNode(BulletRigidBodyNode('Box-2'))
np.node().setMass(1.0)
np.node().addShape(shape)
np.setPos(-3, 0, 4)
np.setPythonTag('foo', -1)
self.world.attachRigidBody(np.node())
def filter(self, node1, node2):
"""
A rather silly collision filtering algorithm. We assume every node
has the Python tag 'foo' set, and that the value of this tag is integer.
Then we add the values and if the result is greater than zero we want
the nodes to collide.
"""
x1 = node1.getPythonTag('foo')
x2 = node2.getPythonTag('foo')
return (x1 + x2 > 0)