本文整理汇总了Python中panda3d.bullet.BulletRigidBodyNode.setFriction方法的典型用法代码示例。如果您正苦于以下问题:Python BulletRigidBodyNode.setFriction方法的具体用法?Python BulletRigidBodyNode.setFriction怎么用?Python BulletRigidBodyNode.setFriction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类panda3d.bullet.BulletRigidBodyNode
的用法示例。
在下文中一共展示了BulletRigidBodyNode.setFriction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createPlane
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setFriction [as 别名]
def createPlane(self):
rb = BulletRigidBodyNode('Ground')
rb.addShape(BulletPlaneShape(Vec3(0, 0, 1), 1))
rb.setFriction(1.0)
np = self.render.attachNewNode(rb)
np.setPos(Vec3(0, 0, -100))
np.setCollideMask(BitMask32.bit(0))
self.world.attachRigidBody(rb)
return np
示例2: createBox
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setFriction [as 别名]
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)
np = self.render.attachNewNode(rb)
np.setPos(pos)
np.setCollideMask(BitMask32.bit(1))
cube = self.loader.loadModel('cube')
cube.setScale(scale)
cube.setColor(color)
cube.reparentTo(np)
return np
示例3: CharacterController
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setFriction [as 别名]
class CharacterController(DynamicObject, FSM):
def __init__(self, game):
self.game = game
FSM.__init__(self, "Player")
# key states
# dx direction left or right, dy direction forward or backward
self.kh = self.game.kh
self.dx = 0
self.dy = 0
self.jumping = 0
self.crouching = 0
# maximum speed when only walking
self.groundSpeed = 5.0
# acceleration used when walking to rise to self.groundSpeed
self.groundAccel = 100.0
# maximum speed in the air (air friction)
self.airSpeed = 30.0
# player movement control when in the air
self.airAccel = 10.0
# horizontal speed on jump start
self.jumpSpeed = 5.5
self.turnSpeed = 5
self.moveSpeedVec = Vec3(0,0,0)
self.platformSpeedVec = Vec3(0,0,0)
h = 1.75
w = 0.4
self.shape = BulletCapsuleShape(w, h - 2 * w, ZUp)
self.node = BulletRigidBodyNode('Player')
self.node.setMass(2)
self.node.addShape(self.shape)
self.node.setActive(True, True)
self.node.setDeactivationEnabled(False, True)
self.node.setFriction(200)
#self.node.setGravity(10)
#self.node.setFallSpeed(200)
self.node.setCcdMotionThreshold(1e-7)
self.node.setCcdSweptSphereRadius(0.5)
self.node.setAngularFactor(Vec3(0,0,1))
self.np = self.game.render.attachNewNode(self.node)
self.np.setPos(0, 0, 0)
self.np.setH(0)
#self.np.setCollideMask(BitMask32.allOn())
self.game.world.attachRigidBody(self.node)
self.playerModel = None
self.slice_able = False
def setActor(self, modelPath, animDic={}, flip = False, pos = (0,0,0), scale = 1.0):
self.playerModel = Actor(modelPath, animDic)
self.playerModel.reparentTo(self.np)
self.playerModel.setScale(scale) # 1ft = 0.3048m
if flip:
self.playerModel.setH(180)
self.playerModel.setPos(pos)
self.playerModel.setScale(scale)
#-------------------------------------------------------------------
# Speed
def getSpeedVec(self):
return self.node.getLinearVelocity()
def setSpeedVec(self, speedVec):
#print "setting speed to %s" % (speedVec)
self.node.setLinearVelocity(speedVec)
return speedVec
def setPlatformSpeed(self, speedVec):
self.platformSpeedVec = speedVec
def getSpeed(self):
return self.getSpeedVec().length()
def setSpeed(self, speed):
speedVec = self.getSpeedVec()
speedVec.normalize()
self.setSpeedVec(speedVec*speed)
def getLocalSpeedVec(self):
return self.np.getRelativeVector(self.getSpeed())
def getSpeedXY(self):
vec = self.getSpeedVec()
return Vec3(vec[0], vec[1], 0)
def setSpeedXY(self, speedX, speedY):
vec = self.getSpeedVec()
z = self.getSpeedZ()
self.setSpeedVec(Vec3(speedX, speedY, z))
def getSpeedH(self):
return self.getSpeedXY().length()
#.........这里部分代码省略.........
示例4: Player
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setFriction [as 别名]
class Player(object):
#global playerNode
#playerNode = NodePath('player')
F_MOVE = 400.0
def __init__(self, btWorld):
self._attachControls()
self._initPhysics(btWorld)
self._loadModel()
taskMgr.add(self.mouseUpdate, 'player-task')
taskMgr.add(self.moveUpdate, 'player-task')
self._vforce = Vec3(0,0,0)
#ItemHandling(self.playerNode)
def _attachControls(self):
#base.accept( "s" , self.__setattr__,["walk",self.STOP] )
base.accept("w", self.goForward)
base.accept("w-up", self.nogoForward)
base.accept("s", self.goBack)
base.accept("s-up", self.nogoBack)
base.accept("a", self.goLeft)
base.accept("a-up", self.nogoLeft)
base.accept("d", self.goRight)
base.accept("d-up", self.nogoRight)
base.accept("space", self.goUp)
base.accept("space-up", self.nogoUp)
def _loadModel(self):
#self._model = loader.loadModel("../data/models/d1_sphere.egg")
#self._model.reparentTo(self.playerNode)
pl = base.cam.node().getLens()
pl.setNear(0.2)
base.cam.node().setLens(pl)
def _initPhysics(self, world):
rad = 1
shape = BulletSphereShape(rad)
self._rb_node = BulletRigidBodyNode('Box')
self._rb_node.setMass(80.0)
self._rb_node.setFriction(1.8)
self._rb_node.addShape(shape)
self._rb_node.setAngularFactor(Vec3(0,0,0))
self._rb_node.setDeactivationEnabled(False, True)
self.playerNode = render.attachNewNode(self._rb_node)
self.playerNode.setPos(0, 0, 4)
self.playerNode.setHpr(0,0,0)
world.attachRigidBody(self._rb_node)
self.camNode = self.playerNode.attachNewNode("cam node")
base.camera.reparentTo(self.camNode)
self.camNode.setPos(self.camNode, 0, 0, 1.75-rad)
#self.camNode.setPos(self.camNode, 0, -5,0.5)
#self.camNode.lookAt(Point3(0,0,0),Vec3(0,1,0))
def mouseUpdate(self,task):
md = base.win.getPointer(0)
dx = md.getX() - base.win.getXSize()/2.0
dy = md.getY() - base.win.getYSize()/2.0
yaw = dx/(base.win.getXSize()/2.0) * 90
self.camNode.setHpr(self.camNode, -yaw, 0, 0)
#base.camera.setHpr(base.camera, yaw, pith, roll)
base.win.movePointer(0, base.win.getXSize() / 2, base.win.getYSize() / 2)
return task.cont
def moveUpdate(self,task):
if (self._vforce.length() > 0):
#self.rbNode.applyCentralForce(self._vforce)
self._rb_node.applyCentralForce(self.playerNode.getRelativeVector(self.camNode, self._vforce))
else:
pass
return task.cont
def goForward(self):
self._vforce.setY( self.F_MOVE)
def nogoForward(self):
self._vforce.setY( 0)
def goBack(self):
self._vforce.setY(-self.F_MOVE)
def nogoBack(self):
self._vforce.setY( 0)
def goLeft(self):
self._vforce.setX(-self.F_MOVE)
def nogoLeft(self):
self._vforce.setX( 0)
def goRight(self):
self._vforce.setX( self.F_MOVE)
def nogoRight(self):
self._vforce.setX( 0)
def goUp(self):
self._vforce.setZ( self.F_MOVE*1.4)
def nogoUp(self):
self._vforce.setZ( 0)
#.........这里部分代码省略.........
示例5: BulletNPC
# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setFriction [as 别名]
class BulletNPC(DynamicObject):
def __init__(self, name, game, pos):
self.game = game
self.name = name
self.jumping = 0
self.crouching = 0
# maximum speed when only walking
self.groundSpeed = 4.0
# acceleration used when walking to rise to self.groundSpeed
self.groundAccel = 150.0
self.groundFriction = 0.0
# maximum speed in the air (air friction)
self.airSpeed = 30.0
# player movement control when in the air
self.airAccel = 10.0
# horizontal speed on jump start
self.jumpSpeed = 5.5
self.turnSpeed = 5
self.moveSpeedVec = Vec3(0, 0, 0)
self.platformSpeedVec = Vec3(0, 0, 0)
h = 1.75
w = 0.4
self.shape = BulletCapsuleShape(w, h - 2 * w, ZUp)
self.node = BulletRigidBodyNode(self.name)
self.node.setMass(1.0)
self.node.addShape(self.shape)
self.node.setActive(True, True)
self.node.setDeactivationEnabled(False, True)
self.node.setFriction(self.groundFriction)
# self.node.setGravity(10)
# self.node.setFallSpeed(200)
self.node.setCcdMotionThreshold(1e-7)
# do not use setCcdSweptSphereRadius
# it messes up the bite contact test
# self.node.setCcdSweptSphereRadius(0.5)
self.node.setAngularFactor(Vec3(0, 0, 1))
self.np = self.game.render.attachNewNode(self.node)
self.setPos(pos)
self.setH(0)
# self.np.setCollideMask(BitMask32.allOn())
self.game.world.attachRigidBody(self.node)
self.playerModel = Actor(
"models/monsters/ghoul2.egg",
{"idle": "models/monsters/ghoul2-idle.egg", "walk": "models/monsters/ghoul2-walk.egg"},
)
self.playerModel.setScale(0.15)
self.playerModel.setZ(0.15)
self.playerModel.reparentTo(self.np)
interval = Wait(random.uniform(0, 1))
i2 = Func(self.startWalkAnim)
seq = Sequence()
seq.append(interval)
seq.append(i2)
seq.start()
self.growlTimer = 5.0
self.sound = None
self.alive = True
self.targetNp = NodePath(self.name)
self.brainTimer = 0.0
self.brainDelay = 1.2
self.currentForce = Vec3(0, 0, 0)
def startWalkAnim(self):
self.playerModel.loop("walk")
def stopWalkAnim(self):
self.playerModel.loop("idle")
def checkFront(self):
p1 = Point3(self.getPos())
direction = self.game.playerNp.getPos() - self.getPos()
direction.normalize()
direction = direction * 2.0
p2 = Point3(self.getPos() + direction)
result = self.game.world.rayTestClosest(p1, p2)
# ts1 = TransformState.makePos(p1)
# ts2 = TransformState.makePos(p2)
# result = self.game.world.sweepTestClosest(self.shape, ts1, ts2, 0)
#.........这里部分代码省略.........