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


Python PNMImage.getXSize方法代码示例

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


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

示例1: terrainFromHeightMap

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
    def terrainFromHeightMap(self, main):
        self.parentNodePath = NodePath("FloorNodePath")
        self.parentNodePath.setPos(0, 0, -2)
        self.parentNodePath.setScale(5, 5, 0.75)
        # Heightfield (static)
        height = 8.0

        img = PNMImage(Filename('models/elevation.png'))
        xdim = img.getXSize()
        ydim = img.getYSize()
        shape = BulletHeightfieldShape(img, height, ZUp)
        shape.setUseDiamondSubdivision(True)
        self.rigidNode = BulletRigidBodyNode('Heightfield')
        self.rigidNode.notifyCollisions(False)
        self.rigidNodePath = self.parentNodePath.attachNewNode(self.rigidNode)
        self.rigidNodePath.node().addShape(shape)
        self.rigidNodePath.setPos(0, 0, 0)
        self.rigidNodePath.setCollideMask(BitMask32.allOn())
        self.rigidNodePath.node().notifyCollisions(False)

        main.world.attachRigidBody(self.rigidNodePath.node())

        self.hf = self.rigidNodePath.node() # To enable/disable debug visualisation

        self.terrain = GeoMipTerrain('terrain')
        self.terrain.setHeightfield(img)

        self.terrain.setBlockSize(32)
        self.terrain.setNear(50)
        self.terrain.setFar(100)
        self.terrain.setFocalPoint(base.camera)

        rootNP = self.terrain.getRoot()
        rootNP.reparentTo(self.parentNodePath)
        rootNP.setSz(8.0)

        offset = img.getXSize() / 2.0 - 0.5
        rootNP.setPos(-offset, -offset, -height / 2.0)

        self.terrain.generate()

        # Apply texture
        diffuseTexture = loader.loadTexture(Filename('models/diffuseMap.jpg'))
        diffuseTexture.setWrapU(Texture.WMRepeat)
        diffuseTexture.setWrapV(Texture.WMRepeat)
        rootNP.setTexture(diffuseTexture)

        # Normal map
        texStage = TextureStage('texStageNormal')
        texStage.setMode(TextureStage.MNormal)
        normalTexture = loader.loadTexture(Filename('models/normalMap.jpg'))
        rootNP.setTexture(texStage, normalTexture)

        # Glow map
        texStage = TextureStage('texStageNormal')
        texStage.setMode(TextureStage.MGlow)
        glowTexture = loader.loadTexture(Filename('models/glowMap.jpg'))
        rootNP.setTexture(texStage, glowTexture)
开发者ID:genusgant,项目名称:CS594-ThrottleThunder-GameClient,代码行数:60,代码来源:Terrain.py

示例2: __makeSprite__

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
 def __makeSprite__(self,pnm_img,subfile,flip):  
   
   img  = None
   if flip:
     img = PNMImage(pnm_img.getXSize(),pnm_img.getYSize())  
     img.copyFrom(pnm_img)        
     img.flip(True ,False,False)    
   else:
     img = pnm_img                
             
   sff_image = Sprite()     
   sff_image.setXSize(img.getXSize())
   sff_image.setYSize(pnm_img.getYSize())
   sff_image.setZSize(1)    
   sff_image.axisx = -subfile.axisx if (not flip ) else subfile.axisx
   sff_image.axisy = subfile.axisy
   sff_image.group = subfile.groupno
   sff_image.no = subfile.imageno
   sff_image.load(img)
   sff_image.setWrapU(Texture.WM_border_color) # gets rid of odd black edges around image
   sff_image.setWrapV(Texture.WM_border_color)
   sff_image.setBorderColor(LColor(0,0,0,0))
   
   return sff_image
         
     
   
开发者ID:jrgnicho,项目名称:platformer_games_project,代码行数:26,代码来源:sff.py

示例3: __map_Topography

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
 def __map_Topography(self, planet, model, pts=[]):
     height_map = PNMImage()
     height_map_path = "{}/maps/{}".format(planet.path, planet.height_map)
     height_map.read(Filename(height_map_path))
     _hu_size = height_map.getXSize()-1
     _hv_size = height_map.getYSize()-1
     
     radius = planet.radius
     bottom = radius + planet.height_min
     elev_range = planet.height_max - planet.height_min
     _has_sea = "sea_level" in planet.__dict__
     if _has_sea:
         sea_level = planet.sea_level + planet.radius
     
     if not pts: pts = model.read("vertex")
     for pt in pts:
         u, v = self.__get_Pt_Uv(pt, _hu_size, _hv_size)
         height_val = height_map.getGray(u, v)  ## watch when extending w colours.
         height = bottom + elev_range*height_val
         ratio = height / radius
         pt *= ratio
         
         # If planet has sea then raise vert to sea level.
         if _has_sea:
             len_pt = pt.length()
             if len_pt <= sea_level:
                 ratio = sea_level/len_pt
                 pt *= ratio
     
     model.modify("vertex", pts)
开发者ID:svfgit,项目名称:solex,代码行数:32,代码来源:model.py

示例4: makeTextureMap

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
 def makeTextureMap(self):
     '''Citymania function that generates and sets the 4 channel texture map'''
     self.colorTextures = []
     for terrain in self.terrains:
         terrain.getRoot().clearTexture()
         heightmap = terrain.heightfield()
         colormap = PNMImage(heightmap.getXSize()-1, heightmap.getYSize()-1)
         colormap.addAlpha()
         slopemap = terrain.makeSlopeImage()
         for x in range(0, colormap.getXSize()):
             for y in range(0, colormap.getYSize()):
                 # Else if statements used to make sure one channel is used per pixel
                 # Also for some optimization
                 # Snow. We do things funky here as alpha will be 1 already.
                 if heightmap.getGrayVal(x, y) < 200:
                     colormap.setAlpha(x, y, 0)
                 else:
                     colormap.setAlpha(x, y, 1)
                 # Beach. Estimations from http://www.simtropolis.com/omnibus/index.cfm/Main.SimCity_4.Custom_Content.Custom_Terrains_and_Using_USGS_Data
                 if heightmap.getGrayVal(x,y) < 62:
                     colormap.setBlue(x, y, 1)
                 # Rock
                 elif slopemap.getGrayVal(x, y) > 170:
                     colormap.setRed(x, y, 1)
                 else:
                     colormap.setGreen(x, y, 1)
         colorTexture = Texture()
         colorTexture.load(colormap)
         colorTS = TextureStage('color')
         colorTS.setSort(0)
         colorTS.setPriority(1)
         self.colorTextures.append((colorTexture, colorTS))
开发者ID:croxis,项目名称:CityMania,代码行数:34,代码来源:PagedGeoMipTerrain.py

示例5: setHeightfield

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
 def setHeightfield(self, heightfield):
     '''Loads the heighmap image. Currently only accepts PNMIMage
     TODO: str path, FileName'''
     if type(heightfield) is str:
         heightfield = PNMImage(heightfield)
     self.heightfield = heightfield
     self.xsize = heightfield.getXSize()
     self.ysize = heightfield.getYSize()
开发者ID:croxis,项目名称:CityMania,代码行数:10,代码来源:PagedGeoMipTerrain.py

示例6: createGround

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
    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,代码行数:58,代码来源:game.py

示例7: paintAvatar

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
    def paintAvatar(self, entry):
        """ Paints onto an avatar.  Returns true on success, false on
        failure (because there are no avatar pixels under the mouse,
        for instance). """

        # First, we have to render the avatar in its false-color
        # image, to determine which part of its texture is under the
        # mouse.
        if not self.avbuf:
            return False

        #mpos = base.mouseWatcherNode.getMouse()
        mpos = entry.getSurfacePoint(self.player)
        ppos = entry.getSurfacePoint(render)

        self.player.showThrough(BitMask32.bit(1))
        self.avbuf.setActive(True)
        base.graphicsEngine.renderFrame()
        self.player.show(BitMask32.bit(1))
        self.avbuf.setActive(False)

        # Now we have the rendered image in self.avbufTex.
        if not self.avbufTex.hasRamImage():
            print "Weird, no image in avbufTex."
            return False
        p = PNMImage()
        self.avbufTex.store(p)
        ix = int((1 + mpos.getX()) * p.getXSize() * 0.5)
        iy = int((1 - mpos.getY()) * p.getYSize() * 0.5)
        x = 1
        if ix >= 0 and ix < p.getXSize() and iy >= 0 and iy < p.getYSize():
            s = p.getBlue(ix, iy)
            t = p.getGreen(ix, iy)
            x = p.getRed(ix, iy)
        if x > 0.5:
            # Off the avatar.
            return False

        # At point (s, t) on the avatar's map.

        self.__paint(s, t)
        return True
开发者ID:grimfang,项目名称:Paintball,代码行数:44,代码来源:playerBase.py

示例8: loadSpriteImages

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
 def loadSpriteImages(self,file_path,cols,rows,flipx = False,flipy = False):
     """
     Loads an image file containing individual animation frames and returns then in a list of PNMImages
     inputs:
         - file_path
         - cols
         - rows
         - flipx
         - flipy
     Output: 
         - tuple ( bool , list[PNMImage]  )
     """
     
     # Make a filepath
     image_file = Filename(file_path)
     if image_file .empty():
         raise IOError("File not found")
         return (False, [])
 
     # Instead of loading it outright, check with the PNMImageHeader if we can open
     # the file.
     img_head = PNMImageHeader()
     if not img_head.readHeader(image_file ):
         raise IOError("PNMImageHeader could not read file %s. Try using absolute filepaths"%(file_path))
         return (False, [])
 
     # Load the image with a PNMImage
     full_image = PNMImage(img_head.getXSize(),img_head.getYSize())
     full_image.alphaFill(0)
     full_image.read(image_file) 
     
     if flipx or flipy:
         full_image.flip(flipx,flipy,False)
 
     w = int(full_image.getXSize()/cols)
     h = int(full_image.getYSize()/rows)
     
     images = []
 
     counter = 0
     for i in range(0,cols):
       for j in range(0,rows):
         sub_img = PNMImage(w,h)
         sub_img.addAlpha()
         sub_img.alphaFill(0)
         sub_img.fill(1,1,1)
         sub_img.copySubImage(full_image ,0 ,0 ,i*w ,j*h ,w ,h)
 
         images.append(sub_img)
         
     return (True, images)
开发者ID:jrgnicho,项目名称:platformer_games_project,代码行数:53,代码来源:sprite_loader.py

示例9: transparencyKey

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
def transparencyKey(filename):
    image = PNMImage(GAME+'/textures/effects/'+filename)
    image.addAlpha()
    backgroundColor = None
    for y in range(image.getYSize()):
        for x in range(image.getXSize()):
            if backgroundColor == None:
                backgroundColor = Color(image.getRedVal(x, y), image.getGreenVal(x, y), image.getGreenVal(x, y), 0)
            if image.getRedVal(x, y) == backgroundColor.R and \
                image.getGreenVal(x, y) == backgroundColor.G and \
                image.getGreenVal(x, y) == backgroundColor.B:
                # Transparent
                image.setAlpha(x, y, 0.0)
            else:
                # Opaque
                image.setAlpha(x, y, 1.0) 
    return image
开发者ID:gaconkzk,项目名称:tethical,代码行数:19,代码来源:Effect.py

示例10: __map_Colours

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
 def __map_Colours(self, planet, model, rec, pts=[]):
     col_map_path = planet.colour_map.replace(".","_low.")
     col_map_fn = Filename("{}/maps/{}".format(planet.path, col_map_path))
     col_map = PNMImage()
     col_map.read(col_map_fn)
     _cu_size = col_map.getXSize()-1
     _cv_size = col_map.getYSize()-1
    
     cols = []
     if not pts: pts = model.read("vertex")
     for pt in pts:
         u, v = self.__get_Pt_Uv(pt, _cu_size, _cv_size)
         r = col_map.getRed(u, v)
         g = col_map.getGreen(u, v)
         b = col_map.getBlue(u, v)
         pt_col = (r, g, b, 1)
         cols.append(pt_col)
     model.modify("color", cols)
开发者ID:svfgit,项目名称:solex,代码行数:20,代码来源:model.py

示例11: createMap

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
    def createMap(self):

        height = 10.0
        img = PNMImage(Filename('resources/map1.bmp'))
        shape = BulletHeightfieldShape(img, height, ZUp)
        node = BulletRigidBodyNode('Map')
        node.setMass(99999999)
        node.addShape(shape)
        self.world.attachRigidBody(node)
        offset = img.getXSize() / 2.0 - 0.5
        terrain = GeoMipTerrain('terrain')
        terrain.setHeightfield(img)
        terrainNP = terrain.getRoot()
        terrainNP.setSz(height)
        terrainNP.setPos(-offset, -offset, -height / 2.0)
        #terrain.setColorMap('resources/map1color.bmp')
        terrain.setAutoFlatten(GeoMipTerrain.AFMOff)
        terrain.generate()

        return Map(terrainNP,node)
开发者ID:Williangalvani,项目名称:panda_robot_thing_again,代码行数:22,代码来源:ModelCreator.py

示例12: __loadSpritePair__

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
  def __loadSpritePair__(sprite_details):  
    
    image_file = sprite_details.im_file
    img_head = PNMImageHeader()
    if not img_head.readHeader(image_file ):
        logging.error( "PNMImageHeader could not read file %s. Try using absolute filepaths"%(image_file))
        return (None,None)

    # Load the right side image as a PNMImage
    right_img = PNMImage(img_head.getXSize(),img_head.getYSize())
    right_img.alphaFill(0)
    right_img.read(image_file)
    
    # Flip to get the left side image
    left_img = PNMImage(right_img.getXSize(),right_img.getYSize())  
    left_img.copyFrom(right_img)        
    left_img.flip(True ,False,False) 
    
    images = [(right_img,False),(left_img,True)]
    sprites = []
    
    for entry in images:      
       
      img = entry[0]
      flip = entry[1]        
      sprite = Sprite()     
      sprite.setXSize(img.getXSize())
      sprite.setYSize(img.getYSize())
      sprite.setZSize(1)    
      sprite.axisx = -sprite_details.axisx if (not flip ) else sprite_details.axisx
      sprite.axisy = sprite_details.axisy
      sprite.group = sprite_details.group_no
      sprite.no = sprite_details.image_no
      sprite.load(img)
      sprite.setWrapU(Texture.WM_border_color) # gets rid of odd black edges around image
      sprite.setWrapV(Texture.WM_border_color)
      sprite.setBorderColor(LColor(0,0,0,0))
      
      sprites.append(sprite)
    
    return (sprites[0],sprites[1])
开发者ID:jrgnicho,项目名称:platformer_games_project,代码行数:43,代码来源:ffe_loader.py

示例13: __init__

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
    def __init__(self, image_path, name=None,\
                  rows=1, cols=1, scale=1.0,\
                  twoSided=True, alpha=TRANS_ALPHA,\
                  repeatX=1, repeatY=1,\
                  anchorX=ALIGN_LEFT, anchorY=ALIGN_BOTTOM):
        """
        Create a card textured with an image. The card is sized so that the ratio between the
        card and image is the same.
        """
       
        scale *= self.PIXEL_SCALE
       
        self.animations = {}
       
        self.scale = scale
        self.repeatX = repeatX
        self.repeatY = repeatY
        self.flip = {'x':False,'y':False}
        self.rows = rows
        self.cols = cols
       
        self.currentFrame = 0
        self.currentAnim = None
        self.loopAnim = False
        self.frameInterrupt = True
       
        # Create the NodePath
        if name:
            self.node = NodePath("Sprite2d:%s" % name)
        else:
            self.node = NodePath("Sprite2d:%s" % image_path)
       
        # Set the attribute for transparency/twosided
        self.node.node().setAttrib(TransparencyAttrib.make(alpha))
        if twoSided:
            self.node.setTwoSided(True)
       
        # Make a filepath
        self.imgFile = Filename(image_path)
        if self.imgFile.empty():
            raise IOError("File not found")
       
        # Instead of loading it outright, check with the PNMImageHeader if we can open
        # the file.
        imgHead = PNMImageHeader()
        if not imgHead.readHeader(self.imgFile):
            raise IOError("PNMImageHeader could not read file. Try using absolute filepaths")
       
        # Load the image with a PNMImage
        image = PNMImage()
        image.read(self.imgFile)
       
        self.sizeX = image.getXSize()
        self.sizeY = image.getYSize()
       
        self.frames = []
        for rowIdx in range(self.rows):
            for colIdx in range(self.cols):
                self.frames.append(Sprite2d.Cell(colIdx, rowIdx))
       
        # We need to find the power of two size for the another PNMImage
        # so that the texture thats loaded on the geometry won't have artifacts
        textureSizeX = self.nextsize(self.sizeX)
        textureSizeY = self.nextsize(self.sizeY)
       
        # The actual size of the texture in memory
        self.realSizeX = textureSizeX
        self.realSizeY = textureSizeY
       
        self.paddedImg = PNMImage(textureSizeX, textureSizeY)
        if image.hasAlpha():
            self.paddedImg.alphaFill(0)
        # Copy the source image to the image we're actually using
        self.paddedImg.blendSubImage(image, 0, 0)
        # We're done with source image, clear it
        image.clear()
       
        # The pixel sizes for each cell
        self.colSize = self.sizeX/self.cols
        self.rowSize = self.sizeY/self.rows
       
        # How much padding the texture has
        self.paddingX = textureSizeX - self.sizeX
        self.paddingY = textureSizeY - self.sizeY
       
        # Set UV padding
        self.uPad = float(self.paddingX)/textureSizeX
        self.vPad = float(self.paddingY)/textureSizeY
       
        # The UV dimensions for each cell
        self.uSize = (1.0 - self.uPad) / self.cols
        self.vSize = (1.0 - self.vPad) / self.rows
       
        card = CardMaker("Sprite2d-Geom")

        # The positions to create the card at
        if anchorX == self.ALIGN_LEFT:
            posLeft = 0
            posRight = (self.colSize/scale)*repeatX
        elif anchorX == self.ALIGN_CENTER:
#.........这里部分代码省略.........
开发者ID:gaconkzk,项目名称:tethical,代码行数:103,代码来源:Sprite2d.py

示例14: PlayerBase

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]

#.........这里部分代码省略.........
        self.currentHits = 0
        self.isOut = False

        self.TorsorControl = self.player.controlJoint(None,"modelRoot","Torsor")

        # setup the collision detection
        # wall and object collision
        self.playerSphere = CollisionSphere(0, 0, 1, 1)
        self.playerCollision = self.player.attachNewNode(CollisionNode("playerCollision%d"%id(self)))
        self.playerCollision.node().addSolid(self.playerSphere)
        base.pusher.addCollider(self.playerCollision, self.player)
        base.cTrav.addCollider(self.playerCollision, base.pusher)
        # foot (walk) collision
        self.playerFootRay = self.player.attachNewNode(CollisionNode("playerFootCollision%d"%id(self)))
        self.playerFootRay.node().addSolid(CollisionRay(0, 0, 2, 0, 0, -1))
        self.playerFootRay.node().setIntoCollideMask(0)
        self.lifter = CollisionHandlerFloor()
        self.lifter.addCollider(self.playerFootRay, self.player)
        base.cTrav.addCollider(self.playerFootRay, self.lifter)

        # Player weapon setup
        self.gunAttach = self.player.exposeJoint(None, "modelRoot", "WeaponSlot_R")
        self.color = LPoint3f(1, 1, 1)
        self.gun = Gun(id(self))
        self.gun.reparentTo(self.gunAttach)
        self.gun.hide()
        self.gun.setColor(self.color)

        self.hud = None

        # Player controls setup
        self.keyMap = {"left":0, "right":0, "forward":0, "backward":0}
        # screen sizes
        self.winXhalf = base.win.getXSize() / 2
        self.winYhalf = base.win.getYSize() / 2
        self.mouseSpeedX = 0.1
        self.mouseSpeedY = 0.1
        # AI controllable variables
        self.AIP = 0.0
        self.AIH = 0.0

        self.movespeed = 5.0

        self.userControlled = False

        self.accept("Bulet-hit-playerCollision%d" % id(self), self.hit)
        self.accept("window-event", self.recalcAspectRatio)

    def runBase(self):
        self.player.show()
        self.gun.show()
        taskMgr.add(self.move, "moveTask%d"%id(self), priority=-4)

    def stopBase(self):
        taskMgr.remove("moveTask%d"%id(self))
        self.ignoreAll()
        self.gun.remove()
        self.footstep.stop()
        base.audio3d.detachSound(self.footstep)
        self.player.delete()

    def setKey(self, key, value):
        self.keyMap[key] = value

    def setPos(self, pos):
        self.player.setPos(pos)
开发者ID:grimfang,项目名称:Paintball,代码行数:70,代码来源:playerBase.py

示例15: Application

# 需要导入模块: from panda3d.core import PNMImage [as 别名]
# 或者: from panda3d.core.PNMImage import getXSize [as 别名]
class Application(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.world = BulletWorld()
        self.world.setGravity(Vec3(0, 0, -9.81))
        
        self.height = 85.0
        self.img = PNMImage(Filename('height1.png'))
        self.shape = BulletHeightfieldShape(self.img, self.height, ZUp)
        self.offset = self.img.getXSize() / 2.0 - 0.5
        self.terrain = GeoMipTerrain('terrain')
        self.terrain.setHeightfield(self.img)
        self.terrain.setColorMap("grass.png")
        self.terrainNP = self.terrain.getRoot()
        self.terrainNP.setSz(self.height)
        self.terrainNP.setPos(-self.offset, -self.offset, -self.height / 2.0)   
        self.terrain.getRoot().reparentTo(render)
        self.terrain.generate()

        self.node = BulletRigidBodyNode('Ground')
        self.node.addShape(self.shape)
        self.np = render.attachNewNode(self.node)
        self.np.setPos(0, 0, 0)
        self.world.attachRigidBody(self.node)

        self.info = self.world.getWorldInfo()
        self.info.setAirDensity(1.2)
        self.info.setWaterDensity(0)
        self.info.setWaterOffset(0)
        self.info.setWaterNormal(Vec3(0, 0, 0))
        
        self.cam.setPos(20, 20, 20)
        self.cam.setHpr(0, 0, 0)
        
        self.model = loader.loadModel('out6.egg')
        #self.model.setPos(0.0, 0.0, 0.0)
        self.model.flattenLight()
        min, max = self.model.getTightBounds()
        size = max
        mmax = size[0]
        if size[1] > mmax:
            mmax = size[1]
        if size[2] > mmax:
            mmax = size[2]
        self.rocketScale = 20.0/mmax / 2
        
        shape = BulletBoxShape(Vec3(size[0]*self.rocketScale, size[1]*self.rocketScale, size[2]*self.rocketScale))
        
        
        self.ghostshape = BulletBoxShape(Vec3(size[0]*self.rocketScale, size[1]*self.rocketScale, size[2]*self.rocketScale))
 
        self.ghost = BulletRigidBodyNode('Ghost')
        self.ghost.addShape(self.ghostshape)
        self.ghostNP = render.attachNewNode(self.ghost)
        self.ghostNP.setPos(19.2220401046, 17.5158313723, 35.2665607047  )
        #self.ghostNP.setCollideMask(BitMask32(0x0f))
        self.model.setScale(self.rocketScale) 
        self.world.attachRigidBody(self.ghost)
        self.model.copyTo(self.ghostNP)
        
        self.rocketnode = BulletRigidBodyNode('rocketBox')
        self.rocketnode.setMass(1.0)
        self.rocketnode.addShape(shape)

        self.rocketnp = render.attachNewNode(self.rocketnode)
        self.rocketnp.setPos(0.0, 0.0, 40.0)
        tex = loader.loadTexture('crate.jpg')
        self.model.find('**/Line001').setTexture(tex, 1)
        #self.rocketnp.setTexture(tex)

        self.model.setScale(self.rocketScale)
        self.world.attachRigidBody(self.rocketnode)
        self.model.copyTo(self.rocketnp)
        self.hh = 35.0
        
        print self.ghostNP.getPos()
        
        self.accept('w', self.eventKeyW)
        self.accept('r', self.eventKeyR)
        self.taskMgr.add(self.update, 'update')
        self.massive = self.getdata('data.txt')
        self.massiveResampled = self.resample(self.massive)
        self.posInArray = 0
        self.x = 0.0
        self.y = 0.0
        self.z = 0.0
        self.timerNow = 0.0
        self.taskMgr.add(self.timerTask, 'timerTask')
    
    def checkGhost(self):
        '''
        ghost = self.ghostNP.node()
        if ghost.getNumOverlappingNodes() > 1:
            print ghost.getNumOverlappingNodes()
            for node in ghost.getOverlappingNodes():
                print node
        '''
        result = self.world.contactTest(self.ghost)
        
        for contact in result.getContacts():
#.........这里部分代码省略.........
开发者ID:Sorrowkun,项目名称:testPanda,代码行数:103,代码来源:Application.py


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