本文整理汇总了Python中pandac.PandaModules.BitMask32类的典型用法代码示例。如果您正苦于以下问题:Python BitMask32类的具体用法?Python BitMask32怎么用?Python BitMask32使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BitMask32类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, parserClass, mainClass, mapLoaderClass, modelLoaderClass):
self.switchState = False
# self.t = Timer()
self.keyMap = {"left": 0, "right": 0, "forward": 0, "backward": 0}
self.ralph = Actor(
"data/models/units/ralph/ralph",
{"run": "data/models/units/ralph/ralph-run", "walk": "data/models/units/ralph/ralph-walk"},
)
self.ralph.reparentTo(render)
# self.ralph.setPos(42, 30, 0)
self.ralph.setPos(6, 10, 0)
self.ralph.setScale(0.1)
self.accept("escape", sys.exit)
self.accept("arrow_left", self.setKey, ["left", 1])
self.accept("arrow_left-up", self.setKey, ["left", 0])
self.accept("arrow_right", self.setKey, ["right", 1])
self.accept("arrow_right-up", self.setKey, ["right", 0])
self.accept("arrow_up", self.setKey, ["forward", 1])
self.accept("arrow_up-up", self.setKey, ["forward", 0])
self.accept("arrow_down", self.setKey, ["backward", 1])
self.accept("arrow_down-up", self.setKey, ["backward", 0])
self.isMoving = False
self.cTrav = CollisionTraverser()
self.ralphGroundRay = CollisionRay()
self.ralphGroundRay.setOrigin(0, 0, 1000)
self.ralphGroundRay.setDirection(0, 0, -1)
self.ralphGroundCol = CollisionNode("ralphRay")
self.ralphGroundCol.addSolid(self.ralphGroundRay)
self.ralphGroundCol.setFromCollideMask(BitMask32.bit(0))
self.ralphGroundCol.setIntoCollideMask(BitMask32.allOff())
self.ralphGroundColNp = self.ralph.attachNewNode(self.ralphGroundCol)
self.ralphGroundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)
# self.ralphGroundCol.show()
base.cam.reparentTo(self.ralph)
base.cam.setPos(0, 9, 7)
self.floater2 = NodePath(PandaNode("floater2"))
self.floater2.reparentTo(self.ralph)
self.floater2.setZ(self.floater2.getZ() + 6)
base.cam.lookAt(self.floater2)
# Uncomment this line to see the collision rays
# self.ralphGroundColNp.show()
# self.camGroundColNp.show()
# Uncomment this line to show a visual representation of the
# collisions occuring
# self.cTrav.showCollisions(render)
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
taskMgr.add(self.move, "movingTask", extraArgs=[mainClass, parserClass, mapLoaderClass, modelLoaderClass])
示例2: placeItem
def placeItem(self, item):
# Add ground collision detector to the health item
self.cTrav1 = CollisionTraverser()
self.collectGroundRay = CollisionRay()
self.collectGroundRay.setOrigin(0,0,300)
self.collectGroundRay.setDirection(0,0,-1)
self.collectGroundCol = CollisionNode('colRay')
self.collectGroundCol.addSolid(self.collectGroundRay)
self.collectGroundCol.setFromCollideMask(BitMask32.bit(1))
self.collectGroundCol.setIntoCollideMask(BitMask32.allOff())
self.collectGroundColNp = item.attachNewNode(self.collectGroundCol)
self.collectGroundHandler = CollisionHandlerQueue()
base.cTrav1.addCollider(self.collectGroundColNp, self.collectGroundHandler)
placed = False;
while placed == False:
# re-randomize position
item.setPos(-random.randint(-350,300),-random.randint(-100,150),0)
base.cTrav1.traverse(render)
# Get Z position from terrain collision
entries = []
for j in range(self.collectGroundHandler.getNumEntries()):
entry = self.collectGroundHandler.getEntry(j)
entries.append(entry)
entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
x.getSurfacePoint(render).getZ()))
if (len(entries)>0) and (entries[0].getIntoNode().getName() == "terrain"):
item.setZ(entries[0].getSurfacePoint(render).getZ()+4)
placed = True
示例3: __init__
def __init__(self,actor):
self.actor = actor
self.prevtime = 0
self.controlMap = {"left":0, "right":0}
taskMgr.add(self.move,"cameraMoveTask")
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
base.disableMouse()
#base.camera.setPos(self.actor.getX(),self.actor.getY()+10,2)
base.camera.setPos(self.actor.getX()-30,self.actor.getY()-10,self.actor.getZ()+7)
camera.setHpr(-60,0,0)
self.cTrav = CollisionTraverser()
self.groundRay = CollisionRay()
self.groundRay.setOrigin(0,0,1000)
self.groundRay.setDirection(0,0,-1)
self.groundCol = CollisionNode('camRay')
self.groundCol.addSolid(self.groundRay)
self.groundCol.setFromCollideMask(BitMask32.bit(1))
self.groundCol.setIntoCollideMask(BitMask32.allOff())
self.groundColNp = base.camera.attachNewNode(self.groundCol)
self.groundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.groundColNp, self.groundHandler)
self.groundColNp.show()
示例4: handle_collisions
def handle_collisions(self):
self.collision_handling_mutex.acquire()
self.groundCol.setIntoCollideMask(BitMask32.bit(0))
self.groundCol.setFromCollideMask(BitMask32.bit(1))
# Now check for collisions.
self.cTrav.traverse(render)
# Adjust the character's Z coordinate. If the character's ray hit terrain,
# update his Z. If it hit anything else, or didn't hit anything, put
# him back where he was last frame.
entries = []
for i in range(self.groundHandler.getNumEntries()):
entry = self.groundHandler.getEntry(i)
entries.append(entry)
entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
x.getSurfacePoint(render).getZ()))
if (len(entries)>0) and (entries[0].getIntoNode().getName() == "terrain"):
self.actor.setZ(entries[0].getSurfacePoint(render).getZ())
else:
self.actor.setPos(self.startpos)
self.groundCol.setIntoCollideMask(BitMask32.bit(0))
self.groundCol.setFromCollideMask(BitMask32.bit(0))
self.collision_handling_mutex.release()
示例5: makeNew
def makeNew(self, pos, nor, parent = None):
"""Makes a new bullet hole."""
if parent == None:
parent = self.container
else:
# Add a subnode to the parent, if it's not already there
child = parent.find('bullet-holes')
if child.isEmpty():
parent = parent.attachNewNode('bullet-holes')
else:
parent = child
newhole = NodePath(self.card.generate())
newhole.reparentTo(parent)
newhole.lookAt(render, Point3(newhole.getPos(render) - nor))
newhole.setR(newhole, random() * 360.0)
newhole.setPos(render, pos)
# Offset it a little to avoid z-fighting
# Increase this value if you still see it.
newhole.setY(newhole, -.001 - random() * 0.01)
del newhole
# We don't want one batch per bullet hole, so flatten it.
# This could be made smarter to preserve culling, but
# I have yet to see a performance loss.
# The clearTexture() is a necessary hack.
parent.clearTexture()
parent.flattenStrong()
parent.setTexture(self.texture)
parent.setTransparency(TransparencyAttrib.MDual)
parent.setShaderOff(1)
parent.hide(BitMask32.bit(2)) # Invisible to volumetric lighting camera (speedup)
parent.hide(BitMask32.bit(3)) # Invisible to shadow cameras (speedup)
示例6: __init__
def __init__(self, ywn):
'''
Constructor
'''
Thing.__init__(self, "Lightswitch", ywn)
self.model = loader.loadModel('models/Lightswitch')
self.model.find("**/Piattina").node().setIntoCollideMask(BitMask32.bit(1))
self.model.find("**/Piattina").node().setTag('ID', self.Id)
self.model.find("**/Piattina").node().setTag('nodeId', "Piattina")
self.model.find("**/Switch").node().setIntoCollideMask(BitMask32.bit(1))
self.model.find("**/Switch").node().setTag('ID', self.Id)
self.model.find("**/Switch").node().setTag('nodeId', "Switch")
self.model.find("**/Switch").setP(332)
self.model.find("**/TopScrew").node().setIntoCollideMask(BitMask32.bit(1))
self.model.find("**/TopScrew").node().setTag('ID', self.Id)
self.model.find("**/TopScrew").node().setTag('nodeId', "TopScrew")
self.model.find("**/BottomScrew").node().setIntoCollideMask(BitMask32.bit(1))
self.model.find("**/BottomScrew").node().setTag('ID', self.Id)
self.model.find("**/BottomScrew").node().setTag('nodeId', "BottomScrew")
self.model.setTag('ID', self.Id)
self.status = Lightswitch.SWITCH_OFF
示例7: setupCollisions
def setupCollisions(self):
#player sphere
cPlayerSphere = CollisionSphere(Point3(0, 0, .5), 10)
cPlayerNode = CollisionNode("Player")
cPlayerNode.addSolid(cPlayerSphere)
cPlayerNode.setFromCollideMask(BitMask32.bit(4))
cPlayerNode.setIntoCollideMask(BitMask32(20))
cPlayerNP = self.player.attachNewNode(cPlayerNode)
self.cTrav.addCollider(cPlayerNP, self.playerGroundHandler)
#self.cTrav.addCollider(cPlayerNP, self.cRocketHandler)
#cPlayerNP.show()
#enemy sphere
cEnemySphere = CollisionSphere(Point3(0, 0, .5), 10)
cEnemyNode = CollisionNode("Enemy")
cEnemyNode.addSolid(cEnemySphere)
cEnemyNode.setFromCollideMask(BitMask32.bit(4))
cEnemyNode.setIntoCollideMask(BitMask32(18))
cEnemyNP = self.enemy.attachNewNode(cEnemyNode)
self.cTrav.addCollider(cEnemyNP, self.enemyGroundHandler)
示例8: start
def start(self):
if self.bgColour!=None: base.setBackgroundColor(self.bgColour)
if self.model!=None:
self.model.show()
self.model.hide(BitMask32.bit(1)) # Hide from the reflection camera
self.model.hide(BitMask32.bit(2)) # Hide from the volumetric lighting camera
self.model.hide(BitMask32.bit(3)) # Hide from the shadow camera(s), if any
示例9: __init__
def __init__(self):
self.picker = CollisionTraverser()
self.pickerQ = CollisionHandlerQueue()
pickerCollN = CollisionNode('heightChecker')
self.pickerNode = render.attachNewNode(pickerCollN)
pickerCollN.setFromCollideMask(BitMask32.bit(1))
pickerCollN.setIntoCollideMask(BitMask32.allOff())
self.pickerRay = CollisionRay(0,0,300,0,0,-1)
pickerCollN.addSolid(self.pickerRay)
self.picker.addCollider(self.pickerNode, self.pickerQ)
示例10: __init__
def __init__(self, model, run, walk, startPos, scale):
"""Initialise the character.
Arguments:
model -- The path to the character's model file (string)
run : The path to the model's run animation (string)
walk : The path to the model's walk animation (string)
startPos : Where in the world the character will begin (pos)
scale : The amount by which the size of the model will be scaled
(float)
"""
self.controlMap = {"left":0, "right":0, "up":0, "down":0}
self.actor = Actor(Config.MYDIR+model,
{"run":Config.MYDIR+run,
"walk":Config.MYDIR+walk})
self.actor.reparentTo(render)
self.actor.setScale(scale)
self.actor.setPos(startPos)
self.controller = Controller.LocalController(self)
taskMgr.add(self.move,"moveTask") # Note: deriving classes DO NOT need
# to add their own move tasks to the
# task manager. If they override
# self.move, then their own self.move
# function will get called by the
# task manager (they must then
# explicitly call Character.move in
# that function if they want it).
self.prevtime = 0
self.isMoving = False
# We will detect the height of the terrain by creating a collision
# ray and casting it downward toward the terrain. One ray will
# start above ralph's head, and the other will start above the camera.
# A ray may hit the terrain, or it may hit a rock or a tree. If it
# hits the terrain, we can detect the height. If it hits anything
# else, we rule that the move is illegal.
self.cTrav = CollisionTraverser()
self.groundRay = CollisionRay()
self.groundRay.setOrigin(0,0,1000)
self.groundRay.setDirection(0,0,-1)
self.groundCol = CollisionNode('ralphRay')
self.groundCol.addSolid(self.groundRay)
self.groundCol.setFromCollideMask(BitMask32.bit(1))
self.groundCol.setIntoCollideMask(BitMask32.allOff())
self.groundColNp = self.actor.attachNewNode(self.groundCol)
self.groundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.groundColNp, self.groundHandler)
示例11: __init__
def __init__(self,actor):
"""Initialise the camera, setting it to follow 'actor'.
Arguments:
actor -- The Actor that the camera will initially follow.
"""
self.actor = actor
self.prevtime = 0
# The camera's controls:
# "left" = move the camera left, 0 = off, 1 = on
# "right" = move the camera right, 0 = off, 1 = on
self.controlMap = {"left":0, "right":0}
taskMgr.add(self.move,"cameraMoveTask")
# Create a "floater" object. It is used to orient the camera above the
# target actor's head.
self.floater = NodePath(PandaNode("floater"))
self.floater.reparentTo(render)
# Set up the camera.
base.disableMouse()
base.camera.setPos(self.actor.getX(),self.actor.getY()+2, 2)
# uncomment for topdown
#base.camera.setPos(self.actor.getX(),self.actor.getY()+10,2)
#base.camera.setHpr(180, -50, 0)
# A CollisionRay beginning above the camera and going down toward the
# ground is used to detect camera collisions and the height of the
# camera above the ground. A ray may hit the terrain, or it may hit a
# rock or a tree. If it hits the terrain, we detect the camera's
# height. If it hits anything else, the camera is in an illegal
# position.
self.cTrav = CollisionTraverser()
self.groundRay = CollisionRay()
self.groundRay.setOrigin(0,0,1000)
self.groundRay.setDirection(0,0,-1)
self.groundCol = CollisionNode('camRay')
self.groundCol.addSolid(self.groundRay)
self.groundCol.setFromCollideMask(BitMask32.bit(1))
self.groundCol.setIntoCollideMask(BitMask32.allOff())
self.groundColNp = base.camera.attachNewNode(self.groundCol)
self.groundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.groundColNp, self.groundHandler)
示例12: initialize_collision_handling
def initialize_collision_handling(self):
self.collision_handling_mutex = Lock()
self.cTrav = CollisionTraverser()
self.groundRay = CollisionRay()
self.groundRay.setOrigin(0,0,1000)
self.groundRay.setDirection(0,0,-1)
self.groundCol = CollisionNode(self.attach_object.name + "_collision_node")
self.groundCol.setIntoCollideMask(BitMask32.bit(0))
self.groundCol.setFromCollideMask(BitMask32.bit(0))
self.groundCol.addSolid(self.groundRay)
self.groundColNp = self.attach_object.render_model.attachNewNode(self.groundCol)
self.groundHandler = CollisionHandlerQueue()
self.cTrav.addCollider(self.groundColNp, self.groundHandler)
示例13: addDropCollision
def addDropCollision(self, drop):
collSph = drop.attachNewNode(CollisionNode('coll_drop'))
collSph.node().addSolid(CollisionSphere(0, 0, 0, 1))
collSph.node().setIntoCollideMask(BitMask32.allOff())
collSph.node().setFromCollideMask(Globals.DropBitmask)
collGround = drop.attachNewNode(CollisionNode('coll_drop_ground'))
collGround.node().addSolid(CollisionRay(0, 0, 0, 0, 0, -1))
collGround.node().setIntoCollideMask(BitMask32.allOff())
collGround.node().setFromCollideMask(Globals.WallBitmask)
collGround.show()
collHdlF.addCollider(collGround, drop)
base.cTrav.addCollider(collSph, collHdl)
base.cTrav.addCollider(collGround, collHdlF)
self.accept("coll_drop-into", self.handleDropCollision)
self.accept("coll_drop-out", self.completeCollision)
示例14: createBallColliderModel
def createBallColliderModel(self):
#creates the collider sphere around the ball
cSphereRad = 9.9
self.cTrav = CollisionTraverser() #moves over all possible collisions
self.ballModelSphere = CollisionSphere(0, 0, 0, cSphereRad)
#collision mesh around ball is a simple sphere
self.ballModelCol = CollisionNode('ballModelSphere')
self.ballModelCol.addSolid(self.ballModelSphere)
self.ballModelCol.setFromCollideMask(BitMask32.bit(0))
self.ballModelCol.setIntoCollideMask(BitMask32.allOff())
self.ballModelColNp = self.ballModel.attachNewNode(self.ballModelCol)
self.ballModelGroundHandler = CollisionHandlerQueue()
#collision handler queue stores all collision points
self.cTrav.addCollider(self.ballModelColNp, self.ballModelGroundHandler)
示例15: __init__
def __init__(self, x, y, z):
self.model = loader.loadModel("models/circle")
self.model.reparentTo(render)
self.model.setPos(x, y, z)
self.model.setHpr(0, 0, 0)
self.model.setColor(1, 1, 1, 1)
self.model.setTexture(loader.loadTexture('textures/spiral.png'))
self.glow = loader.loadModel("models/tube")
self.glow.reparentTo(render)
self.glow.setShaderOff()
self.glow.setLightOff()
self.glow.hide(BitMask32.allOn())
self.glow.show(BitMask32(0x01))
self.glow.setPos(x, y, z + 0.05)
self.glow.setHpr(0, 0, 0)
self.glow.setColor(1, 1, 1, 1)
texture = loader.loadTexture('textures/green_glow.png')
texture.setWrapU(Texture.WMClamp)
texture.setWrapV(Texture.WMClamp)
self.glow.setTexture(texture)
self.glow.setTransparency(TransparencyAttrib.MAlpha)
self._active = False
self.visibility = 0
taskMgr.add(self._update_task, "AcceleratorUpdateTask")