本文整理汇总了Python中panda3d.bullet.BulletWorld.attachConstraint方法的典型用法代码示例。如果您正苦于以下问题:Python BulletWorld.attachConstraint方法的具体用法?Python BulletWorld.attachConstraint怎么用?Python BulletWorld.attachConstraint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletWorld
的用法示例。
在下文中一共展示了BulletWorld.attachConstraint方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachConstraint [as 别名]
#.........这里部分代码省略.........
self.world.attachRigidBody(body0)
# Box A
shape = BulletBoxShape(Vec3(0.1, 0.1, 5))
self.hLeg = BulletRigidBodyNode('Box A')
bodyNP = self.worldNP.attachNewNode(self.hLeg)
bodyNP.node().addShape(shape)
bodyNP.node().setMass(1.0)
bodyNP.node().setDeactivationEnabled(False)
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(0, 0, 5.1)
visNP = loader.loadModel('models/box.egg')
visNP.clearModelNodes()
visNP.setScale(Vec3(0.2, 0.2, 10))
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(self.hLeg)
# Box B
shape = BulletBoxShape(Vec3(0.1, 0.1, 5))
self.lLeg = BulletRigidBodyNode('Box B')
bodyNP = self.worldNP.attachNewNode(self.lLeg)
bodyNP.node().addShape(shape)
bodyNP.node().setMass(1.0)
bodyNP.node().setDeactivationEnabled(False)
force = bodyNP.node().getTotalForce()
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(0, 0, -5.1)
visNP = loader.loadModel('models/box.egg')
visNP.clearModelNodes()
visNP.setScale(Vec3(0.2, 0.2, 10))
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(self.lLeg)
# Box C
shape = BulletBoxShape(Vec3(0.5, 1, 0.1))
self.foot = BulletRigidBodyNode('Box C')
bodyNP = self.worldNP.attachNewNode(self.foot)
bodyNP.node().addShape(shape)
bodyNP.node().setMass(1.0)
bodyNP.node().setDeactivationEnabled(False)
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(0, 0.5, -5.2)
visNP = loader.loadModel('models/box.egg')
visNP.clearModelNodes()
visNP.setScale(Vec3(1, 2, 0.2))
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(self.foot)
# Text data
self.kneeJointText = OnscreenText(text = 'kneeJoint', pos = (-0.4, 0.6), scale = 0.05, fg = (1.0,1.0,1.0,1.0))
self.ankleJointText = OnscreenText(text = 'ankleJoint', pos = (-0.4, 0.4), scale = 0.05, fg = (1.0,1.0,1.0,1.0))
self.hLegText = OnscreenText(text = 'highLeg', pos = (-1, 0.8), scale = 0.05, fg = (1.0,1.0,1.0,1.0))
self.lLegText = OnscreenText(text = 'lowLeg', pos = (-1, 0.6), scale = 0.05, fg = (1.0,1.0,1.0,1.0))
self.footText = OnscreenText(text = 'foot', pos = (-1, 0.4), scale = 0.05, fg = (1.0,1.0,1.0,1.0))
# attachment to hip
# Hinge01
pivotA = Point3(0, 0, -2.0)
pivotB = Point3(0, 0, 5.1)
axisA = Vec3(1, 0, 0)
axisB = Vec3(1, 0, 0)
hinge = BulletHingeConstraint(body0, self.hLeg, pivotA, pivotB, axisA, axisB, True)
hinge.setDebugDrawSize(2.0)
hinge.setLimit(-90, 180, softness=0.1, bias=0.3, relaxation=0.1)
self.world.attachConstraint(hinge)
# Hinge1
pivotA = Point3(0, 0, -5.3)
pivotB = Point3(0, 0, 5.3)
axisA = Vec3(1, 0, 0)
axisB = Vec3(1, 0, 0)
self.kneeJoint = BulletHingeConstraint(self.hLeg, self.lLeg, pivotA, pivotB, axisA, axisB, True)
#self.kneeJoint.enableAngularMotor(True,1,1)
self.kneeJoint.setDebugDrawSize(2.0)
self.kneeJoint.setLimit(-10, 180, softness=0.1, bias=0.3, relaxation=0.1)
self.world.attachConstraint(self.kneeJoint)
# Hinge2
pivotA = Point3(0, 0.2, -5.2)
pivotB = Point3(0, 0.2, 0.1)
axisA = Vec3(1, 0, 0)
axisB = Vec3(1, 0, 0)
self.ankleJoint = BulletHingeConstraint(self.lLeg, self.foot, pivotA, pivotB, axisA, axisB, True)
self.ankleJoint.setDebugDrawSize(2.0)
self.ankleJoint.setLimit(-60, 80, softness=0.1, bias=0.3, relaxation=0.1)
self.world.attachConstraint(self.ankleJoint)
示例2: RonnieRacer
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachConstraint [as 别名]
#.........这里部分代码省略.........
visNP.clearModelNodes()
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(bodyA)
# Box C
shape = BulletBoxShape(Vec3(0.1, 0.1, 0.9)*scale)
bodyC = BulletRigidBodyNode('Box C')
bodyNP = self.worldNP.attachNewNode(bodyC)
bodyNP.node().addShape(shape)
bodyNP.node().setMass(1.0)
bodyNP.node().setLinearDamping(0.5)
bodyNP.node().setDeactivationEnabled(False)
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(pos)
bodyNP.setHpr(turn)
visNP = loader.loadModel('media/models/box.egg')
visNP.setScale(Vec3(0.1, 0.1, 0.9)*2*scale)
visNP.clearModelNodes()
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(bodyC)
pivotA = Point3(0, 0, -0.1 * scale)
pivotB = Point3(0, 0, 1 * scale)
axisA = Vec3(1, 0, 0)
axisB = Vec3(1, 0, 0)
hinge = BulletHingeConstraint(bodyA, bodyC, pivotA, pivotB, axisA, axisB, True)
hinge.setDebugDrawSize(2.0)
hinge.setLimit(-90,90, softness=1.0, bias=0.3, relaxation=1.0)
self.world.attachConstraint(hinge)
# Box B
shape = BulletBoxShape(Vec3(3, 2, 0.1)*scale)
bodyB = BulletRigidBodyNode('Box B')
bodyNP = self.worldNP.attachNewNode(bodyB)
bodyNP.node().addShape(shape)
bodyNP.node().setMass(1.0)
bodyNP.node().setLinearDamping(0.5)
bodyNP.node().setDeactivationEnabled(False)
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(pos)
bodyNP.setHpr(turn);
visNP = loader.loadModel('media/models/box.egg')
visNP.setScale(Vec3(3, 2, 0.1)*2*scale)
visNP.clearModelNodes()
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(bodyB)
# Hinge
pivotA = Point3(0, 0, 0)
pivotB = Point3(0, 0, -1 * scale)
hinge = BulletHingeConstraint(bodyB, bodyC, pivotA, pivotB, axisA, axisB, True)
hinge.setLimit(0,360, softness=1.0, bias=0.3, relaxation=1.0)
self.world.attachConstraint(hinge)
def setupObstacleTwo(self,pos,scale,turn):
#box A
示例3: Game
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachConstraint [as 别名]
#.........这里部分代码省略.........
v.normalize()
v *= 100.0
# Create bullet
shape = BulletSphereShape(0.3)
body = BulletRigidBodyNode('Bullet')
bodyNP = self.worldNP.attachNewNode(body)
bodyNP.node().addShape(shape)
bodyNP.node().setMass(1.0)
bodyNP.node().setLinearVelocity(v)
bodyNP.node().setCcdMotionThreshold(1e-7);
bodyNP.node().setCcdSweptSphereRadius(0.50);
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(pFrom)
visNP = loader.loadModel('models/ball.egg')
visNP.setScale(0.8)
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(bodyNP.node())
# Remove the bullet again after 2 seconds
taskMgr.doMethodLater(2, self.doRemove, 'doRemove',
extraArgs=[bodyNP],
appendTask=True)
def doRemove(self, bodyNP, task):
self.world.removeRigidBody(bodyNP.node())
bodyNP.removeNode()
return task.done
# ____TASK___
def update(self, task):
dt = globalClock.getDt()
self.world.doPhysics(dt, 20, 1.0/180.0)
return task.cont
def cleanup(self):
self.worldNP.removeNode()
self.worldNP = None
self.world = None
def setup(self):
self.worldNP = render.attachNewNode('World')
# World
self.debugNP = self.worldNP.attachNewNode(BulletDebugNode('Debug'))
self.debugNP.show()
self.debugNP.node().showWireframe(True)
self.debugNP.node().showConstraints(True)
self.debugNP.node().showBoundingBoxes(False)
self.debugNP.node().showNormals(False)
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.world.setDebugNode(self.debugNP.node())
# Box A
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
bodyA = BulletRigidBodyNode('Box A')
bodyNP = self.worldNP.attachNewNode(bodyA)
bodyNP.node().addShape(shape)
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(-2, 0, 1)
visNP = loader.loadModel('models/box.egg')
visNP.clearModelNodes()
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(bodyA)
# Box B
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
bodyB = BulletRigidBodyNode('Box B')
bodyNP = self.worldNP.attachNewNode(bodyB)
bodyNP.node().addShape(shape)
bodyNP.node().setMass(1.0)
bodyNP.node().setDeactivationEnabled(False)
bodyNP.setCollideMask(BitMask32.allOn())
bodyNP.setPos(2, 0, 1)
visNP = loader.loadModel('models/box.egg')
visNP.clearModelNodes()
visNP.reparentTo(bodyNP)
self.world.attachRigidBody(bodyB)
# Hinge
pivotA = Point3(2, 0, 0)
pivotB = Point3(-4, 0, 0)
axisA = Vec3(0, 0, 1)
axisB = Vec3(0, 0, 1)
hinge = BulletHingeConstraint(bodyA, bodyB, pivotA, pivotB, axisA, axisB, True)
hinge.setDebugDrawSize(2.0)
hinge.setLimit(-90, 120, softness=0.9, bias=0.3, relaxation=1.0)
self.world.attachConstraint(hinge)
示例4: App
# 需要导入模块: from panda3d.bullet import BulletWorld [as 别名]
# 或者: from panda3d.bullet.BulletWorld import attachConstraint [as 别名]
class App(ShowBase):
def __init__(self, args):
ShowBase.__init__(self)
width = args['--width']
height = args['--height']
globalClock.setMode(ClockObject.MNonRealTime)
globalClock.setDt(0.02) # 20ms per frame
self.setBackgroundColor(0.9, 0.9, 0.9)
self.createLighting()
self.setupCamera(width, height, Vec3(0, -10, 10), Vec3(0, 0, 0))
self.render.setShaderAuto()
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
# self.setupDebug()
self.createPlane(Vec3(0, 0, -1), Vec3(10, 10, 1))
box_a = self.createBox(1.5, Vec3(2, 0, 1), Vec3(2, 1, 1), VBase4(0.5, 1, 0.5, 1.0))
box_b = self.createBox(1.0, Vec3(-2, 0, 1), Vec3(2, 1, 1), VBase4(0.5, 0.5, 1, 1.0))
constraint = BulletHingeConstraint(box_a.node(), box_b.node(), \
Vec3(-2, 0, 0), Vec3(2, 0, 0), \
Vec3(0, 1, 0), Vec3(0, 1, 0))
self.world.attachConstraint(constraint, linked_collision=True)
self.muscle = Muscle(30)
self.muscle.setA(box_a, Vec3(-1, 0, 1))
self.muscle.setB(box_b, Vec3(1, 0, 1))
self.muscle.setJointCenter(Vec3(-2, 0, 0))
# self.muscle.setupDebug(self.loader)
self.disableCollisions()
self.accept('escape', sys.exit)
self.taskMgr.add(self.update, 'update')
def disableCollisions(self):
for i in range(32):
self.world.setGroupCollisionFlag(i, i, False)
self.world.setGroupCollisionFlag(0, 1, True)
def setupDebug(self):
node = BulletDebugNode('Debug')
node.showWireframe(True)
self.world.setDebugNode(node)
np = self.render.attachNewNode(node)
np.show()
def createLens(self, aspect_ratio, fov=60.0, near=1.0, far=1000.0):
lens = PerspectiveLens()
lens.setFov(fov)
lens.setAspectRatio(aspect_ratio)
lens.setNearFar(near, far)
return lens
def setupCamera(self, width, height, pos, look):
self.cam.setPos(pos)
self.cam.lookAt(look)
self.cam.node().setLens(self.createLens(width / height))
def createLighting(self):
light = DirectionalLight('light')
light.setColor(VBase4(0.6, 0.6, 0.6, 1))
light.setShadowCaster(True, 1024, 1024)
light.getLens().setNearFar(1.0, 40.0)
light.getLens().setFilmSize(40, 40)
# light.showFrustum()
np = self.render.attachNewNode(light)
np.setPos(10, -10, 20)
np.lookAt(0, 0, 0)
self.render.setLight(np)
light = AmbientLight('ambient')
light.setColor(VBase4(0.4, 0.4, 0.4, 1))
np = self.render.attachNewNode(light)
self.render.setLight(np)
def createBox(self, mass, pos, scale, color):
rb = BulletRigidBodyNode('box')
rb.addShape(BulletBoxShape(scale))
rb.setMass(mass)
rb.setLinearDamping(0.2)
rb.setAngularDamping(0.9)
rb.setFriction(1.0)
rb.setAnisotropicFriction(1.0)
rb.setRestitution(0.0)
self.world.attachRigidBody(rb)
#.........这里部分代码省略.........