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


Python bullet.BulletRigidBodyNode类代码示例

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


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

示例1: genCollisionMeshMultiNp

def genCollisionMeshMultiNp(nodepath, basenodepath=None, name='autogen'):
    """
    generate the collision mesh of a nodepath using nodepath
    this function suppose the nodepath has multiple models with many geomnodes

    use genCollisionMeshMultiNp instead of genCollisionMeshNp for generality

    :param nodepath: the panda3d nodepath of the object
    :param basenodepath: the nodepath to compute relative transform, identity if none
    :param name: the name of the rigidbody
    :return: bulletrigidbody

    author: weiwei
    date: 20161212, tsukuba
    """

    gndcollection = nodepath.findAllMatches("**/+GeomNode")
    geombullnode = BulletRigidBodyNode(name)
    for gnd in gndcollection:
        geom = gnd.node().getGeom(0)
        geomtf = gnd.getTransform(base.render)
        if basenodepath is not None:
            geomtf = gnd.getTransform(basenodepath)
        geombullmesh = BulletTriangleMesh()
        geombullmesh.addGeom(geom)
        bullettmshape = BulletTriangleMeshShape(geombullmesh, dynamic=True)
        bullettmshape.setMargin(0)
        geombullnode.addShape(bullettmshape, geomtf)
    return geombullnode
开发者ID:wanweiwei07,项目名称:pyhiro,代码行数:29,代码来源:collisiondetection.py

示例2: genBulletBoxes

def genBulletBoxes(env,world):
    boxes = list()
    for np in listNodes(env,"Collision_box_"):
        geom = np.node().getGeom(0)
        # get the minimum and maximum points
        vdata = geom.getVertexData()
        vertices = GeomVertexReader(vdata,'vertex')
        vmin = LPoint3()
        vmax = LPoint3()
        np.calcTightBounds(vmin,vmax)
        #Create the bullet box with center at (0,0)
        norm = vmax-vmin
        hnorm = LVecBase3(norm[0]*.5,norm[1]*.5,norm[2]*.5)
        shape = BulletBoxShape(hnorm)
        # create the surrounding nodes
        node = BulletRigidBodyNode('env')
        node.addShape(shape)
        enp = env.attachNewNode(node)
        enp.setPos(vmin+hnorm)
        # attach it to the world and save it for later
        world.attachRigidBody(node)
        boxes.append(enp.node())
        # clean up the environment higherarchy
        np.removeNode()
    return boxes
开发者ID:MattMcMullan,项目名称:GdProj3,代码行数:25,代码来源:objects.py

示例3: Akis

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,代码行数:27,代码来源:Akis.py

示例4: genHand

 def genHand(self, handz=100.0):
     # fgr0
     boxx = 5.0
     boxy = 2.0
     boxz = 20.0
     boxpx = 0.0
     boxpy = 10.0
     boxpz = handz
     shape = BulletBoxShape(Vec3(boxx, boxy, boxz))  # the parameters are half extends
     node = BulletRigidBodyNode('fgr0')
     node.addShape(shape)
     node.setTransform(TransformState.makePos(VBase3(boxpx, boxpy, boxpz)))
     self.bltWorld.attachRigidBody(node)
     pg.plotBox(self.base.render, pos=[boxpx, boxpy, boxpz], x=boxx * 2.0, y=boxy * 2.0, z=boxz * 2.0, rgba=None)
     # fgr1
     boxx = 5.0
     boxy = 2.0
     boxz = 20.0
     boxpx = 0.0
     boxpy = -10.0
     boxpz = handz
     shape = BulletBoxShape(Vec3(boxx, boxy, boxz))  # the parameters are half extends
     node = BulletRigidBodyNode('fgr1')
     node.addShape(shape)
     node.setTransform(TransformState.makePos(VBase3(boxpx, boxpy, boxpz)))
     self.bltWorld.attachRigidBody(node)
     pg.plotBox(self.base.render, pos=[boxpx, boxpy, boxpz], x=boxx * 2.0, y=boxy * 2.0, z=boxz * 2.0, rgba=None)
开发者ID:wanweiwei07,项目名称:pyhiro,代码行数:27,代码来源:dropblt.py

示例5: demoContinue

    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,代码行数:29,代码来源:physics.py

示例6: StaticTerrain

class StaticTerrain(BulletObject):
	def __init__(self, game, imgPath, height):
		self.game = game
		self.img = PNMImage(Filename(imgPath))
		self.shape = BulletHeightfieldShape(self.img, height, 2)
		self.node = BulletRigidBodyNode('Ground')
		self.node.addShape(self.shape)
		
		self.np = self.game.render.attachNewNode(self.node)
		self.np.setPos(0, 0, 0)
		self.np.setScale(1, 1, 1)
		self.game.world.attachRigidBody(self.node)
		
		self.terrain = GeoMipTerrain('terrain')
		self.terrain.setHeightfield(self.img)
		self.terrain.generate()
		self.terrainNP = self.terrain.getRoot()
		self.offset = self.img.getXSize() / 2.0 - 0.5
		self.terrainNP.setSz(height)
		self.terrainNP.setPos(-self.offset,-self.offset,-height/2.0)
		#self.terrainNP.flattenStrong()
		self.terrainNP.reparentTo(self.np)
		
		self.terrainNP.show()
		self.debugOff()
		self.slice_able = False
		
		self.terrain.setBlockSize(32)
		self.terrain.setNear(100)
		self.terrain.setFar(400)
		self.terrain.setFocalPoint(self.game.playerNp)
	
	def update(self, dt=0.1):
		self.terrain.update()
开发者ID:arikel,项目名称:PPARPG,代码行数:34,代码来源:bulletHandler.py

示例7: Ball

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,代码行数:34,代码来源:Ball.py

示例8: StaticModel

class StaticModel(BulletObject):
	def __init__(self, name, modelPath, displayModelPath, 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)
		
		mesh = BulletTriangleMesh()
		mesh.addGeom(self.geom)
		self.shape = BulletTriangleMeshShape(mesh, dynamic=False)
		
		self.node = BulletRigidBodyNode(self.name)
		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.displayModel = self.game.loader.loadModel(displayModelPath)
		self.displayModel.reparentTo(self.np)
		self.displayModel.setTwoSided(True)
		self.slice_able = False
开发者ID:arikel,项目名称:PPARPG,代码行数:31,代码来源:bulletHandler.py

示例9: rayHit

def rayHit(pfrom, pto, geom):
    """
    NOTE: this function is quite slow
    find the nearest collision point between vec(pto-pfrom) and the mesh of nodepath

    :param pfrom: starting point of the ray, Point3
    :param pto: ending point of the ray, Point3
    :param geom: meshmodel, a panda3d datatype
    :return: None or Point3

    author: weiwei
    date: 20161201
    """

    bulletworld = BulletWorld()
    facetmesh = BulletTriangleMesh()
    facetmesh.addGeom(geom)
    facetmeshnode = BulletRigidBodyNode('facet')
    bullettmshape = BulletTriangleMeshShape(facetmesh, dynamic=True)
    bullettmshape.setMargin(0)
    facetmeshnode.addShape(bullettmshape)
    bulletworld.attachRigidBody(facetmeshnode)
    result = bulletworld.rayTestClosest(pfrom, pto)

    if result.hasHit():
        return result.getHitPos()
    else:
        return None
开发者ID:wanweiwei07,项目名称:pyhiro,代码行数:28,代码来源:collisiondetection.py

示例10: __init__

    def __init__(self,mainReference):
        
        super(Player, self).__init__(mainReference)
        
        # setting player HP
        self.healthPoints = 100
        
        # fine tuning the camera properties
        self.mainRef.camLens.setFov(50)
        self.mainRef.camLens.setNear(0.02)
        self.mainRef.camLens.setFar(80.0)
        
        self.currentRegionID = 1

        # dummy nodepath for our player; we will attach everything to it
        
        # player bullet node - NOTE: for detecting collision with attacks, only
        playerNode = BulletRigidBodyNode('Player_NP') 
        playerNode.addShape( BulletCapsuleShape(0.3, 1, ZUp) ) # adicionar node no lugar da string
        self.mainRef.world.attachRigidBody(playerNode)
        
        self.playerNP = self.mainRef.render.attachNewNode(playerNode)
        # this collision mask will only avoid CharacterBody collision on itself
        self.playerNP.setCollideMask(BitMask32(0x7FFFFFFF))
        # notify collision contacts
        self.playerNP.node().notifyCollisions(True)
        
        
        self.playerHeadNP = NodePath("empty") # This node is intended to be a placeholder for the camera (maintainability only)
        
        self.playerHeadNP.reparentTo( self.playerNP )
        self.playerHeadNP.setPos(0, 0, 1.35)
                
#        self.mainRef.camera.setPos(0, -4, 0)
        self.mainRef.camera.reparentTo( self.playerHeadNP )
        
        
        # NodePath position
        self.playerNP.setPos(0,0,1.0)
        
        # setting player's character body
        self.playerBody = CharacterBody(self.mainRef, self.playerNP.getPos(), 0.38, 0.5)
        self.playerBody.charBodyNP.reparentTo(self.playerNP) 
        
        # setting our movementHandler
        self.movementHandler = MovementHandler(self.mainRef)
        self.movementHandler.registerFPSMovementInput()
        
        # attach default weapon
        self.activeWeapon = Glock(self.mainRef.camera)
            
        # adding the shoot event
        self.mainRef.accept("mouse1", self.shootBullet)
        
        # adding the reload event
        self.mainRef.accept("mouse3", self.reloadWeapon)
        
        # player boolean to authorize player HP decrease when zombie contact happens
        self.canLoseHP = True
开发者ID:vitutc,项目名称:anim-jogos-2012-1,代码行数:59,代码来源:Player.py

示例11: setupDeathzone

	def setupDeathzone(self, height):
		planeShape = BulletPlaneShape(Vec3(0, 0, 1), 1)
		planeNode = BulletRigidBodyNode('DeathZone')
		planeNode.addShape(planeShape)
		planeNP = render.attachNewNode(planeNode)
		planeNP.setPos(0, 0, height)
		self.worldBullet.attachRigidBody(planeNode)
		return planeNP
开发者ID:tbackus127,项目名称:AbominableSnowmanGame,代码行数:8,代码来源:SMWorld.py

示例12: addGround

 def addGround(self):
     boxx = 500.0
     boxy = 500.0
     boxz = 1.0
     shape = BulletBoxShape(Vec3(boxx, boxy, boxz)) # the parameters are half extends
     node = BulletRigidBodyNode('Ground')
     node.addShape(shape)
     self.bltWorld.attachRigidBody(node)
     pg.plotBox(self.base.render, pos = [0,0,-1.0], x = boxx*2.0, y = boxy*2.0, z = boxz*2.0, rgba=None)
开发者ID:wanweiwei07,项目名称:pyhiro,代码行数:9,代码来源:dropblt.py

示例13: initBullet

 def initBullet(self):
     self.world = BulletWorld()
     #self.world.setGravity(Vec3(0, 0, -9.81))
     self.world.setGravity(Vec3(0, 0, -1.62))
     
     groundShape = BulletPlaneShape(Vec3(0, 0, 1), 0)
     groundNode = BulletRigidBodyNode('Ground')
     groundNode.addShape(groundShape)
     self.world.attachRigidBody(groundNode)
开发者ID:endaramiz,项目名称:Pandillas-Game,代码行数:9,代码来源:gameStatePlaying.py

示例14: createGround

    def createGround(self, terrainData):
        """Create ground using a heightmap"""

        # Create heightfield for physics
        heightRange = terrainData["heightRange"]

        # Image needs to have dimensions that are a power of 2 + 1
        heightMap = PNMImage(self.basePath + terrainData["elevation"])
        xdim = heightMap.getXSize()
        ydim = heightMap.getYSize()
        shape = BulletHeightfieldShape(heightMap, heightRange, ZUp)
        shape.setUseDiamondSubdivision(True)

        np = self.outsideWorldRender.attachNewNode(BulletRigidBodyNode("terrain"))
        np.node().addShape(shape)
        np.setPos(0, 0, 0)
        self.physicsWorld.attachRigidBody(np.node())

        # Create graphical terrain from same height map
        terrain = GeoMipTerrain("terrain")
        terrain.setHeightfield(heightMap)

        terrain.setBlockSize(32)
        terrain.setBruteforce(True)
        rootNP = terrain.getRoot()
        rootNP.reparentTo(self.worldRender)
        rootNP.setSz(heightRange)

        offset = xdim / 2.0 - 0.5
        rootNP.setPos(-offset, -offset, -heightRange / 2.0)
        terrain.generate()

        # Apply texture
        diffuse = self.loader.loadTexture(Filename(self.basePath + terrainData["texture"]))
        diffuse.setWrapU(Texture.WMRepeat)
        diffuse.setWrapV(Texture.WMRepeat)
        rootNP.setTexture(diffuse)
        textureSize = 6.0
        ts = TextureStage.getDefault()
        rootNP.setTexScale(ts, xdim / textureSize, ydim / textureSize)

        # Create planes around area to prevent player flying off the edge
        # Levels can define barriers around them but it's probably a good
        # idea to leave this here just in case
        sides = (
            (Vec3(1, 0, 0), -xdim / 2.0),
            (Vec3(-1, 0, 0), -xdim / 2.0),
            (Vec3(0, 1, 0), -ydim / 2.0),
            (Vec3(0, -1, 0), -ydim / 2.0),
        )
        for sideNum, side in enumerate(sides):
            normal, offset = side
            sideShape = BulletPlaneShape(normal, offset)
            sideNode = BulletRigidBodyNode("side%d" % sideNum)
            sideNode.addShape(sideShape)
            self.physicsWorld.attachRigidBody(sideNode)
开发者ID:Red-Gravel,项目名称:Red-Gravel,代码行数:56,代码来源:game.py

示例15: create_colliders

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,代码行数:56,代码来源:physics_utils.py


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