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


Python BulletRigidBodyNode.setMass方法代码示例

本文整理汇总了Python中panda3d.bullet.BulletRigidBodyNode.setMass方法的典型用法代码示例。如果您正苦于以下问题:Python BulletRigidBodyNode.setMass方法的具体用法?Python BulletRigidBodyNode.setMass怎么用?Python BulletRigidBodyNode.setMass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在panda3d.bullet.BulletRigidBodyNode的用法示例。


在下文中一共展示了BulletRigidBodyNode.setMass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: demoContinue

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
    def demoContinue(self):
        if self.newObjects < self.NrObjectToDrop:

            node = BulletRigidBodyNode('Box')
            node.setMass(1.0)
            node.addShape(self.shape)
            np = self.rbcnp.attachNewNode(node)
            np.setPos(self.spawnNP.getPos(render))
            np.setHpr(randint(-45, 45), randint(-45, 45), randint(-45, 45))
            self.world.attachRigidBody(node)

            bNP = self.model.copyTo(np)
            #bNP.setPos(self.spawnNP.getPos())
            #bNP.setColor(random(), random(), random(), 1)
            #bNP.setHpr(randint(-45, 45), randint(-45, 45), randint(-45, 45))
            #self.setUntextured(bNP)
            #bNP.setTexureOff()
            #np.setScale(10)
            np.flattenStrong()

            self.objects.append(np)
            self.newObjects += 1
            self.rbcnp.node().collect()

        if self.newObjects < self.NrObjectToDrop:
            return False
        else:
            self.running = False
            return True
开发者ID:StephenLujan,项目名称:Panda-3d-Procedural-Terrain-Engine,代码行数:31,代码来源:physics.py

示例2: create_object

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
    def create_object(self):
        from panda3d.core import Filename, NodePath, BitMask32
        from direct.actor.Actor import Actor
        from panda3d.bullet import BulletRigidBodyNode, BulletCapsuleShape

        from game_system.resources import ResourceManager
        f = Filename.fromOsSpecific(ResourceManager.get_absolute_path(ResourceManager["TestAI"]["lp_char_bs.egg"]))
        model = Actor(f)

        bullet_node = BulletRigidBodyNode("TestAIBulletNode")
        bullet_nodepath = NodePath(bullet_node)

        bullet_node.set_angular_factor((0, 0, 1))

        shape = BulletCapsuleShape(0.3, 1.4, 2)
        bullet_node.addShape(shape)
        bullet_node.setMass(1.0)

        model.reparentTo(bullet_nodepath)
        model.set_hpr(180, 0, 0)
        model.set_pos(0, 0, -1)

        bullet_nodepath.set_collide_mask(BitMask32.bit(0))
        bullet_nodepath.set_python_tag("actor", model)

        return bullet_nodepath
开发者ID:TurBoss,项目名称:PyAuthServer,代码行数:28,代码来源:actors.py

示例3: DynamicNp

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
class DynamicNp(DynamicObject):
	def __init__(self, name, model, game, pos):
		self.name = name
		self.game = game
		
		self.model = model
		self.geomNode = self.model.node()
		self.geom = self.geomNode.getGeom(0)
		
		# with triangle mesh it crashes
		#mesh = BulletTriangleMesh()
		#mesh.addGeom(self.geom)
		#self.shape = BulletTriangleMeshShape(mesh, dynamic=True)
		
		# with convex hull
		self.shape = BulletConvexHullShape()
		self.shape.addGeom(self.geom)
		
		self.node = BulletRigidBodyNode(self.name)
		self.node.setMass(10.0)
		self.node.addShape(self.shape)
		
		self.np = self.game.render.attachNewNode(self.node)
		self.np.setPos(pos)
		self.game.world.attachRigidBody(self.node)
		
		self.model.reparentTo(self.np)
		
		self.node.setCcdMotionThreshold(1e-7)
		self.node.setCcdSweptSphereRadius(0.5)
		self.slice_able = True
开发者ID:arikel,项目名称:PPARPG,代码行数:33,代码来源:bulletHandler.py

示例4: Ball

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
class Ball(object):
  def __init__(self, render, world, loader, player):
    self.render = render
    self.world = world
    self.loader = loader
    self.player = player
    self.dropHeight = 5
    self.createItem()
  
  def createItem(self):
    self.collisionShape = BulletSphereShape(0.5)
    self.actor = BulletRigidBodyNode('Ball')
    self.actor.setMass(5.0)
    self.actor.addShape(self.collisionShape)
    self.np = self.render.attachNewNode(self.actor)
    self.np.setCollideMask(BitMask32.allOff())
    
    self.x = self.player.getCharacterNP().getX()
    self.y = self.player.getCharacterNP().getY()
    self.z = self.player.getCharacterNP().getZ() + self.dropHeight
    
    self.np.setPos(self.x, self.y, self.z)
    self.world.attachRigidBody(self.actor)
    
    self.actorModelNP = self.loader.loadModel('models/sphere/ball.egg')
    self.actorModelNP.reparentTo(self.np)
    self.actorModelNP.setScale(0.5)
    self.actorModelNP.setPos(0, 0, 0)

  def getActor(self):
    return self.actor
  
  def getNP(self):
    return self.np
开发者ID:nextmatrixman,项目名称:UpAllTheWay,代码行数:36,代码来源:Ball.py

示例5: Akis

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
class Akis(Enemy):
  def createCharacter(self):
    self.shape = BulletBoxShape(Vec3(0.4, 0.4, 0.85))
    self.actor = BulletRigidBodyNode('Akis')
    self.actor.setMass(5.0)
    self.np = self.render.attachNewNode(self.actor)
    self.np.node().addShape(self.shape)
    self.np.setPos(self.x, self.y, self.z)
    self.np.setCollideMask(BitMask32.allOn())
    self.world.attachRigidBody(self.np.node())
    
    self.actorModelNP = Actor('models/SecurityGuard/SecurityGuard.egg', {
                     'run': 'models/SecurityGuard/SecurityGuard-run.egg'})
    self.actorModelNP.reparentTo(self.np)
    self.actorModelNP.setScale(0.3048)
    self.actorModelNP.setH(180)
    self.actorModelNP.setPos(0, 0, 0.27)
    self.actorModelNP.loop('run')
  
  def move(self, player):
    playerNP = player.getCharacterNP()
    self.np.lookAt(playerNP.getX(), playerNP.getY(), self.np.getZ())
    vec = playerNP.getPos() - self.np.getPos()
    vec.setZ(0)
    dist = vec.length()
    vec.normalize()
    self.np.setPos(self.np.getPos() + vec * dist * 0.01)
开发者ID:nextmatrixman,项目名称:UpAllTheWay,代码行数:29,代码来源:Akis.py

示例6: DynamicModel

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
class DynamicModel(DynamicObject):
	def __init__(self, name, modelPath, game, pos):
		self.name = name
		self.modelPath = modelPath
		self.game = game
		
		self.model = self.game.loader.loadModel(self.modelPath)
		geomNodes = self.model.findAllMatches('**/+GeomNode')
		self.geomNode = geomNodes.getPath(0).node()
		self.geom = self.geomNode.getGeom(0)
		self.shape = BulletConvexHullShape()
		self.shape.addGeom(self.geom)
		
		self.node = BulletRigidBodyNode(self.name)
		self.node.setMass(10.0)
		self.node.addShape(self.shape)
		
		self.np = self.game.render.attachNewNode(self.node)
		self.np.setPos(pos)
		self.game.world.attachRigidBody(self.node)
		
		self.model.reparentTo(self.np)
		
		self.node.setCcdMotionThreshold(1e-7)
		self.node.setCcdSweptSphereRadius(0.5)
		self.slice_able = True
开发者ID:arikel,项目名称:PPARPG,代码行数:28,代码来源:bulletHandler.py

示例7: setupPlayer

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
	def setupPlayer(self, x, y, z):
		yetiHeight = 7
		yetiRadius = 2
		yetiShape = BulletCapsuleShape(yetiRadius, yetiHeight - 2 * yetiRadius, ZUp)
		
		modelPrefix = "../res/models/yeti_"
		self.yetiModel = Actor("../res/models/yeti.egg", {"idle":"../res/models/yeti_idle.egg", "walk":"../res/models/yeti_walking.egg"})
		self.yetiModel.setH(90)
		self.yetiModel.setPos(0, 0, SNOW_HEIGHT)

		playerNode = BulletRigidBodyNode("Player")
		playerNode.setMass(MASS)
		playerNode.addShape(yetiShape)
		
		# Without this set to 0,0,0, the Yeti would wobble like a Weeble but not fall down.
		playerNode.setAngularFactor(Vec3(0,0,0))

		# Without this disabled, things will weld together after a certain amount of time. It's really annoying.
		playerNode.setDeactivationEnabled(False)
		
		playerNP = self.worldNP.attachNewNode(playerNode)
		playerNP.setPos(x, y, z)
		playerNP.setH(270)
		
		self.yetiModel.reparentTo(playerNP)
		
		self.bulletWorld.attachRigidBody(playerNP.node())
		
		# Hopefully Brandon will get those animation files to me so I can convert them.
		# self.setAnimation('idle')
		
		return playerNP
开发者ID:tbackus127,项目名称:AbominableSnowmanGame,代码行数:34,代码来源:SMPlayer.py

示例8: create_colliders

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
def create_colliders(root, pose_rig, joints_config):
    for node, parent in pose_rig.exposed_joints:
        if node.getName() not in joints_config:
            continue

        joint_config = joints_config[node.getName()]
        if "joints" not in joint_config:
            continue

        joints = joint_config["joints"]
        if len(joints) == 0:
            continue

        mass = joint_config["mass"] if "mass" in joint_config else 1

        box_rb = BulletRigidBodyNode(node.getName())
        box_rb.setMass(1.0)
        # box_rb.setLinearDamping(0.2)
        # box_rb.setAngularDamping(0.9)
        # box_rb.setFriction(1.0)
        # box_rb.setAnisotropicFriction(1.0)
        # box_rb.setRestitution(0.0)

        for joint in joints:
            child_node, child_parent = next(
                (child_node, child_parent)
                for child_node, child_parent in pose_rig.exposed_joints
                if child_node.getName() == joint
            )

            pos = child_node.getPos(child_parent)
            width = pos.length() / 2.0
            scale = Vec3(3, width, 3)

            shape = BulletBoxShape(scale)

            quat = Quat()
            lookAt(quat, child_node.getPos(child_parent), Vec3.up())
            if len(joints) > 1:
                transform = TransformState.makePosHpr(child_node.getPos(child_parent) / 2.0, quat.getHpr())
            else:
                transform = TransformState.makeHpr(quat.getHpr())

            box_rb.addShape(shape, transform)

        box_np = root.attachNewNode(box_rb)

        if len(joints) > 1:
            pos = node.getPos(pose_rig.actor)
            hpr = node.getHpr(pose_rig.actor)
            box_np.setPosHpr(root, pos, hpr)
        else:
            box_np.setPos(child_parent, child_node.getPos(child_parent) / 2.0)
            box_np.lookAt(child_parent, child_node.getPos(child_parent))

        yield box_np
开发者ID:BarkingMouseStudio,项目名称:python-experiments,代码行数:58,代码来源:physics_utils.py

示例9: DynamicBox

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
class DynamicBox(DynamicObject):
	def __init__(self, name, game, pos):
		self.name = name
		self.game = game
		self.shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
		self.node = BulletRigidBodyNode(name)
		self.node.setMass(10.0)
		self.node.addShape(self.shape)
		self.setFriction(20)
		
		self.np = self.game.render.attachNewNode(self.node)
		self.np.setPos(pos)
		self.game.world.attachRigidBody(self.node)
		self.model = self.game.loader.loadModel("models/crate.egg")
		self.model.reparentTo(self.np)
		
		self.node.setCcdMotionThreshold(1e-7)
		self.node.setCcdSweptSphereRadius(0.5)
		self.debugOff()
		self.slice_able = True
	
	def update(self, dt):
		#self.activate()
		#if self.node.isActive():
		#	return
		contact = self.checkFeet()
		contacts = self.getContacts()
		
		if contact in self.game.objects and contact in contacts:
			obj = self.game.objects[contact]
			if type(obj) is KinematicPlatform:
				self.activate()
				self.setAngularVelocity(self.getAngularVelocity()*0.9)
				self.setFriction(0.1)
				#print "%s is a box sliding on %s" % (self.name, obj.name)
				#self.addSpeedVec(self.game.objects[contact].getSpeedVec())
				#self.setForce(obj.getSpeedVec()*self.node.getMass() * 100)
				platform_speed = obj.getSpeedVec()
				force = platform_speed * self.node.getMass() * 50
				#self.setSpeedXY(platform_speed[0], platform_speed[1])
				self.setSpeedVec(platform_speed)
				#self.setAngularVelocity(0)
				
				#self.node.addLin(obj.getSpeedVec()*self.node.getMass() * 100)
				#self.node.applyCentralForce(force)
				#self.setForce(force)
				#self.setFriction(20)
				#self.setPos(self.getPos() + obj.getSpeedVec())
				#self.node.setActive(False)
			else:
				self.setFriction(20)
开发者ID:arikel,项目名称:PPARPG,代码行数:53,代码来源:bulletHandler.py

示例10: renderObject

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
	def renderObject(self,scale,hpr,collisionOn=False):
		(x_scale,y_scale,z_scale) = scale
		(h,p,r) = hpr
		if collisionOn is True:
			if self.name is 'wide_ramp':
				(x_c,y_c,z_c) = (x_scale + .2,y_scale+2.5,z_scale+1.75)
			if self.name is 'tree1':
				(x_c,y_c,z_c) = (x_scale,y_scale,z_scale)
			if self.name is 'tree2':
				(x_c,y_c,z_c) = (x_scale,y_scale,z_scale)
			if self.name is 'rock1':
				(x_c,y_c,z_c) = (x_scale * 2,y_scale * 2,z_scale*2)
			if self.name is 'rock2':
				(x_c,y_c,z_c) = (x_scale*100,y_scale*100,z_scale*100)
			if self.name is 'gate':
				(x_c,y_c,z_c) = (x_scale * 10,y_scale,z_scale*3.5)
			if self.name is 'statue':
				(x_c,y_c,z_c) = (x_scale,y_scale,z_scale)

       			mesh = BulletTriangleMesh()
        		for geomNP in self.model.findAllMatches('**/+GeomNode'):
            			geomNode = geomNP.node()
            			ts = geomNP.getTransform(self.model)
          		for geom in geomNode.getGeoms():
                		mesh.addGeom(geom, ts)

        		shape = BulletTriangleMeshShape(mesh, dynamic=False)

            		node = BulletRigidBodyNode(self.name)
            		node.setMass(0)
            		node.addShape(shape)

			np = self.__game.render.attachNewNode(node)
			np.setPos(self.x,self.y,self.z)
			np.setHpr(h,p,r)
			np.setScale(x_c,y_c,z_c)

			self.__game.world.attachRigidBody(node)
		self.model.setPos(self.x,self.y,self.z)
		self.model.setHpr(h,p,r)
		self.model.setScale(x_scale,y_scale,z_scale)
		self.model.reparentTo(self.__game.render)
		
		if self.name is 'statue':
			plat_texture = loader.loadTexture('models/textures/rocky.jpg')
		        self.model.setTexture(plat_texture,1)
			ts = TextureStage.getDefault()
	       	 	texture = self.model.getTexture()
			self.model.setTexScale(ts, 1, 1)
开发者ID:cgaldamez14,项目名称:rolling-eve,代码行数:51,代码来源:envobject.py

示例11: setupFloaters2

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
    def setupFloaters2(self):
        size = Vec3(3.5, 5.5, 0.3)
        randNum = random.sample(range(10, 1500, 500), 3)
        for i in range(3):
            randX = random.randrange(-2, 3, 10)
            randY = float(randNum[i])
            # randY = random.randint(1000, 1500)
            shape = BulletBoxShape(size * 0.55)
            node = BulletRigidBodyNode('Floater')
            node.setMass(0)
            node.addShape(shape)
            np = self.render.attachNewNode(node)
            # np.setPos(9, 30, 3)
            np.setPos(randX, randY, 6)
            np.setR(0)
            self.world2.attachRigidBody(node)

            dummyNp = self.render.attachNewNode('milkyway')
            dummyNp.setPos(randX, randY, 6)

            modelNP = loader.loadModel('models/box.egg')
            modelNP_tex = loader.loadTexture("models/sky/moon_tex.jpg")
            modelNP.setTexture(modelNP_tex, 1)
            modelNP.reparentTo(dummyNp)
            modelNP.setPos(-1, 0, -1)
            modelNP.setPos(-size.x / 2.0, -size.y / 2.0, -size.z / 2.0)
            modelNP.setScale(size)
            dummyNp.hprInterval(2.5, Vec3(360, 0, 0)).loop()

            # Put A Coin On the Floater
            shape = BulletSphereShape(0.75)
            coinNode = BulletGhostNode('FloaterCoin-' + str(i))
            coinNode.addShape(shape)
            np = self.render.attachNewNode(coinNode)
            np.setCollideMask(BitMask32.allOff())
            # np.setPos(randX, randY, 2)
            np.setPos(randX, randY, 7.0)

            # Adding sphere model
            sphereNp = loader.loadModel('models/smiley.egg')
            sphereNp_tex = loader.loadTexture("models/sky/coin_2_tex.jpg")
            sphereNp.setTexture(sphereNp_tex, 1)
            sphereNp.reparentTo(np)
            sphereNp.setScale(0.85)
            sphereNp.hprInterval(1.5, Vec3(360, 0, 0)).loop()

            self.world2.attachGhost(coinNode)
            self.coins2.append(coinNode)
            print "node name:" + str(coinNode.getName())
开发者ID:anto004,项目名称:game-programming,代码行数:51,代码来源:Ecco.py

示例12: createSphere

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
    def createSphere(self, world, mass=1, scale=1):
        shape = BulletSphereShape(scale)
        node = BulletRigidBodyNode('Sphere')
        node.setMass(mass)
        node.addShape(shape)
        #np = render.attachNewNode(node)
        #np.setPos(0, 0, 4)
        world.attachRigidBody(node)
        model = loader.loadModel('models/smiley.egg')

        model.setScale(scale)
        #model.setPos(-scale[0],-scale[1],-scale[2])
        model.flattenLight()
        #model.reparentTo(np)
        return BasePhysicalObject(model,node)
开发者ID:Williangalvani,项目名称:panda_robot_thing_again,代码行数:17,代码来源:ModelCreator.py

示例13: makeBall

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
 def makeBall(self, num, pos = (0, 0, 0)):
   shape = BulletSphereShape(0.5)
   node = BulletRigidBodyNode('ball_' + str(num))
   node.setMass(1.0)
   node.setRestitution(.9)
   node.setDeactivationEnabled(False)
   node.addShape(shape)
   physics = render.attachNewNode(node)
   physics.setPos(*pos)
   self.world.attachRigidBody(node)
   model = loader.loadModel('models/ball')
   color = self.makeColor()
   model.setColor(color)
   self.ballColors['ball_' + str(num)] = color
   model.reparentTo(physics)
开发者ID:r3t,项目名称:master-term1-gamedev,代码行数:17,代码来源:main.py

示例14: start

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
 def start(self):
     # Boxes
     model = loader.loadModel('models/box.egg')
     model.setPos(-0.5, -0.5, -0.5)
     model.flattenLight()
     shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
     for i in range(10):
         node = BulletRigidBodyNode('Box')
         node.setMass(1.0)
         node.addShape(shape)
         np = render.attachNewNode(node)
         np.setPos(self.spawnNP.getPos(render) + Vec3(0, 0, 2 + i * 2))
         self.world.attachRigidBody(node)
         model.copyTo(np)
     logging.info("Box test placed at " + str(self.spawnNP.getPos()))
开发者ID:StephenLujan,项目名称:Panda-3d-Procedural-Terrain-Engine,代码行数:17,代码来源:physics.py

示例15: setupFloor2

# 需要导入模块: from panda3d.bullet import BulletRigidBodyNode [as 别名]
# 或者: from panda3d.bullet.BulletRigidBodyNode import setMass [as 别名]
    def setupFloor2(self):
        size = Vec3(7.5, 3000, 1.81818)
        shape = BulletBoxShape(size * 0.55)
        # shape = BulletPlaneShape(Vec3(0, 0, 1), 0)
        node = BulletRigidBodyNode('Box-Floor')
        node.addShape(shape)
        node.setMass(0)
        stairNP = self.render.attachNewNode(node)
        stairNP.setPos(0, 0, 0)
        stairNP.setCollideMask(BitMask32.allOn())
        self.world2.attachRigidBody(stairNP.node())

        modelNP = loader.loadModel('models/box.egg')
        modelNP.reparentTo(stairNP)
        modelNP.setPos(-size.x / 2.0, -size.y / 2.0, -size.z / 2.0)
        modelNP.setScale(size)
开发者ID:anto004,项目名称:game-programming,代码行数:18,代码来源:Ecco.py


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