Esempio n. 1
0
    def makeNodeLocator(self, environment):
        meshNode = CollisionNode("NavMeshNodeLocator")
        meshNode.setFromCollideMask(BitMask32.allOff())
        meshNode.setIntoCollideMask(OTPGlobals.PathFindingBitmask)

        self.polyHashToPID = {}

        for pId in self.polyToAngles:
            vertCount = 0
            corners = []
            for angle in self.polyToAngles[pId]:
                if angle != 180:
                    # It's a corner
                    corners.append(vertCount)
                vertCount += 1

            # XXX this code only works for square nodes at present
            # Unfortunately we can only make triangle or square CollisionPolygons on the fly
            assert len(corners) == 4

            #import pdb
            #pdb.set_trace()

            verts = []

            for vert in corners:
                verts.append(
                    (self.vertexCoords[self.polyToVerts[pId][vert]][0],
                     self.vertexCoords[self.polyToVerts[pId][vert]][1], 0))

            #import pdb
            #pdb.set_trace()

            poly = CollisionPolygon(verts[0], verts[1], verts[2], verts[3])

            assert poly not in self.polyHashToPID

            self.polyHashToPID[poly] = pId

            meshNode.addSolid(poly)

        ray = CollisionRay()
        ray.setDirection(0, 0, -1)
        ray.setOrigin(0, 0, 0)

        rayNode = CollisionNode("NavMeshRay")
        rayNode.setFromCollideMask(OTPGlobals.PathFindingBitmask)
        rayNode.setIntoCollideMask(BitMask32.allOff())
        rayNode.addSolid(ray)

        self.meshNodePath = environment.attachNewNode(meshNode)
        self.rayNodePath = environment.attachNewNode(rayNode)

        self.meshNodePath.setTwoSided(True)

        self.chq = CollisionHandlerQueue()
        self.traverser = CollisionTraverser()
        self.traverser.addCollider(self.rayNodePath, self.chq)
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
    def _getEnvironmentHash(self, env):
        '''
        Accepts an environment object and returns the MD5 hash of a string representing all collision geometry therein.
        This value should change whenever the layout of your collisions changes.
        Use to determine whether derived data still reflects reality.

        Base method assumes env is a NodePath, but you can override this to handle whatever you like.
        '''
        allCNs = env.findAllMatches('**/+CollisionNode')
        monsterData = []

        for np in allCNs:
            #monsterData.append( str(np) )
            #monsterData.append( str(np.getTransform(env)) )
            #monsterData.append( str(np.getCollideMask()) )
            monsterData.append("cn")

            node = np.node()

            if node.getIntoCollideMask(
            ) & OTPGlobals.WallBitmask != BitMask32.allOff():
                for i in xrange(node.getNumSolids()):
                    s = node.getSolid(i)

                    monsterData.append(str(s))

        monsterData = string.join(monsterData, "")

        hash = md5.new(monsterData)

        return hash.digest()
Esempio n. 5
0
File: fpsTest.py Progetto: croza/RR2
    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])
Esempio n. 6
0
    def changeModel(self, changeToKey):
        """ Given, changeToKey, containing the key of the self.models dict, this loads
        the activeModel.
        
        TODO: improve so that models can have their own scale. Generalize with separate Models class."""
        if self.models.has_key(changeToKey):
            # TODO: blend or play animation depending on kind of transition
            if hasattr(self, 'activeModel') and self.activeModel:
                #self.activeModel.detachNode()
                self.activeModel.remove()
            self.activeModel = loader.loadModel("media/models/" +
                                                self.models[changeToKey])
            self.activeModel.setScale(self.scale)
            self.activeModel.setPosHpr(*self.offsetVec)
            self.activeModel.setCollideMask(BitMask32.allOff())
            self.activeModel.reparentTo(self)

            # when models are scaled down dramatically (e.g < 1% of original size), Panda3D represents
            # the geometry non-uniformly, which means scaling occurs every render step and collision
            # handling is buggy.  flattenLight()  circumvents this.
            self.activeModel.flattenLight()
        else:
            raise Exception(
                "Error in %s.changeModel() -- cannot find model %s" %
                (self.name, changeToKey))
Esempio n. 7
0
    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()
Esempio n. 8
0
    def __init__(self, model, run, walk, startPos, scale, select,ralph,saysome):

        self.actor = Actor(model, {"run":run, "walk":walk})
        self.actor.reparentTo(render)
        self.actor.setScale(scale)
        self.actor.setPos(startPos)
        self.actor.setHpr(90,0,0)
        self.playerGUI = saysome
        self.myralph = ralph
        self.setAI()

        self.cTrav = CollisionTraverser()

        self.groundRay = CollisionRay(0,0,1000,0,0,-1)  
        self.groundCol = CollisionNode('dinoRay')
        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)

        self.sphere = CollisionSphere(0,0,5,13)
        self.spherecol = CollisionNode('dinoSphere')
        self.spherecol.addSolid(self.sphere)
        self.spherecol.setCollideMask(BitMask32.bit(1))
        self.dinocolhs = self.actor.attachNewNode(self.spherecol)
Esempio n. 9
0
    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
Esempio n. 10
0
 def __init__( self, name, camera=None, rootNp=None, fromCollideMask=None, pickTag=None ):
     gizmo_core.Object.__init__( self, name, camera, rootNp )
     
     self.fromCollideMask = fromCollideMask
     self.pickTag = pickTag
     
     self.selection = []
     self.node = None
     self.collEntry = None
     
     # Create a marquee
     self.marquee = gizmo_core.Marquee( '%sMarquee' % self.name )
     
     # Create collision nodes
     self.collTrav = CollisionTraverser()
     #self.collTrav.showCollisions( render )
     self.collHandler = CollisionHandlerQueue()
     self.pickerRay = CollisionRay()
     
     # Create collision ray
     pickerNode = CollisionNode( self.name )
     pickerNode.addSolid( self.pickerRay )
     pickerNode.setIntoCollideMask( BitMask32.allOff() )
     pickerNp = camera.attachNewNode( pickerNode )
     self.collTrav.addCollider( pickerNp, self.collHandler )
     
     # Create collision mask for the ray if one is specified
     if self.fromCollideMask is not None:
         pickerNode.setFromCollideMask( self.fromCollideMask )
     
     # Bind mouse button events
     eventNames = ['mouse1', 'control-mouse1', 'mouse1-up']
     for eventName in eventNames:
         self.accept( eventName, self.FireEvent, [eventName] )
Esempio n. 11
0
 def addToonCollision(self):
     toon = render.find('**/Toon')
     collTube = toon.attachNewNode(CollisionNode('coll_toon'))
     collTube.node().addSolid(CollisionTube(0, 0, 0.5, 0, 0, 8, 2))
     collTube.node().setIntoCollideMask(Globals.DropBitmask | Globals.ProjBitmask)
     collTube.node().setFromCollideMask(BitMask32.allOff())
     base.cTrav.addCollider(collTube, collHdl)
Esempio n. 12
0
    def __init__(self, *args, **kwargs):
        p3d.SingleTask.__init__(self, *args, **kwargs)

        self.fromCollideMask = kwargs.pop('fromCollideMask', None)

        self.node = None
        self.collEntry = None

        # Create collision nodes
        self.collTrav = CollisionTraverser()
        #self.collTrav.showCollisions( render )
        self.collHandler = CollisionHandlerQueue()
        self.pickerRay = CollisionRay()

        # Create collision ray
        pickerNode = CollisionNode(self.name)
        pickerNode.addSolid(self.pickerRay)
        pickerNode.setIntoCollideMask(BitMask32.allOff())
        pickerNp = self.camera.attachNewNode(pickerNode)
        self.collTrav.addCollider(pickerNp, self.collHandler)

        # Create collision mask for the ray if one is specified
        if self.fromCollideMask is not None:
            pickerNode.setFromCollideMask(self.fromCollideMask)

        # Bind mouse button events
        eventNames = ['mouse1', 'control-mouse1', 'mouse1-up']
        for eventName in eventNames:
            self.accept(eventName, self.FireEvent, [eventName])
Esempio n. 13
0
 def __init__( self, *args, **kwargs ):
     p3d.SingleTask.__init__( self, *args, **kwargs )
     
     self.fromCollideMask = kwargs.pop( 'fromCollideMask', None )
     
     self.node = None
     self.collEntry = None
     
     # Create collision nodes
     self.collTrav = CollisionTraverser()
     #self.collTrav.showCollisions( render )
     self.collHandler = CollisionHandlerQueue()
     self.pickerRay = CollisionRay()
     
     # Create collision ray
     pickerNode = CollisionNode( self.name )
     pickerNode.addSolid( self.pickerRay )
     pickerNode.setIntoCollideMask( BitMask32.allOff() )
     pickerNp = self.camera.attachNewNode( pickerNode )
     self.collTrav.addCollider( pickerNp, self.collHandler )
     
     # Create collision mask for the ray if one is specified
     if self.fromCollideMask is not None:
         pickerNode.setFromCollideMask( self.fromCollideMask )
     
     # Bind mouse button events
     eventNames = ['mouse1', 'control-mouse1', 'mouse1-up']
     for eventName in eventNames:
         self.accept( eventName, self.FireEvent, [eventName] )
Esempio n. 14
0
 def addAttackCollision(self, proj):
     collSph = proj.attachNewNode(CollisionNode('coll_attack'))
     collSph.node().addSolid(CollisionSphere(0, 0, 0, 1))
     collSph.node().setIntoCollideMask(BitMask32.allOff())
     collSph.node().setFromCollideMask(Globals.ProjBitmask)
     base.cTrav.addCollider(collSph, collHdl)
     self.accept("coll_attack-into", self.handleAttackCollision)
     self.accept("coll_attack-out", self.completeAttackCollision)
Esempio n. 15
0
 def addToonCollision(self):
     toon = render.find('**/Toon')
     collTube = toon.attachNewNode(CollisionNode('coll_toon'))
     collTube.node().addSolid(CollisionTube(0, 0, 0.5, 0, 0, 8, 2))
     collTube.node().setIntoCollideMask(Globals.DropBitmask
                                        | Globals.ProjBitmask)
     collTube.node().setFromCollideMask(BitMask32.allOff())
     base.cTrav.addCollider(collTube, collHdl)
Esempio n. 16
0
 def addAttackCollision(self, proj):
     collSph = proj.attachNewNode(CollisionNode('coll_attack'))
     collSph.node().addSolid(CollisionSphere(0, 0, 0, 1))
     collSph.node().setIntoCollideMask(BitMask32.allOff())
     collSph.node().setFromCollideMask(Globals.ProjBitmask)
     base.cTrav.addCollider(collSph, collHdl)
     self.accept("coll_attack-into", self.handleAttackCollision)
     self.accept("coll_attack-out", self.completeAttackCollision)
Esempio n. 17
0
    def setCollisions(self):
        # Add physical collision object to player
        self.playerCollider = self.player.attachNewNode(CollisionNode('playercnode'))
        self.playerCollider.node().addSolid(CollisionSphere(0, 0, 0, 1))
        # Adding to trav turns it into a from object( moving object )
        #base.cTrav.addCollider(self.playerCollider, self.collisionHandler)
        self.playerCollider.node().setFromCollideMask(WALL_MASK)
        self.playerCollider.node().setIntoCollideMask(BitMask32.allOff())

        # Sensor collision
        self.playerSensor = self.player.attachNewNode(CollisionNode('playersensor'))
        cs=CollisionSphere(0, 0, 0, 1.2)
        self.playerSensor.node().addSolid(cs)
        self.playerSensor.node().setFromCollideMask(DOOR_MASK)
        self.playerSensor.node().setIntoCollideMask(BitMask32.allOff())
        # as said above, to act correctly we need to make clear to the system that this is just a sensor, with no solid parts
        cs.setTangible(0)
Esempio n. 18
0
 def addCogGroundCollision(self, cog = None, ent = None):
     if ent == None:
         ent = cog.getCog()
     collGround = ent.attachNewNode(CollisionNode('coll_ground'))
     collGround.node().addSolid(CollisionRay(0, 0, 2, 0, 0, -1))
     collGround.node().setIntoCollideMask(BitMask32.allOff())
     collGround.node().setFromCollideMask(Globals.WallBitmask)
     collHdlF.addCollider(collGround, ent)
     base.cTrav.addCollider(collGround, collHdlF)
Esempio n. 19
0
 def addCogGroundCollision(self, cog=None, ent=None):
     if ent == None:
         ent = cog.getCog()
     collGround = ent.attachNewNode(CollisionNode('coll_ground'))
     collGround.node().addSolid(CollisionRay(0, 0, 2, 0, 0, -1))
     collGround.node().setIntoCollideMask(BitMask32.allOff())
     collGround.node().setFromCollideMask(Globals.WallBitmask)
     collHdlF.addCollider(collGround, ent)
     base.cTrav.addCollider(collGround, collHdlF)
Esempio n. 20
0
    def setCollisions(self):
        # Add physical collision object to player
        self.playerCollider = self.player.attachNewNode(
            CollisionNode('playercnode'))
        self.playerCollider.node().addSolid(CollisionSphere(0, 0, 0, 1))
        # Adding to trav turns it into a from object( moving object )
        #base.cTrav.addCollider(self.playerCollider, self.collisionHandler)
        self.playerCollider.node().setFromCollideMask(WALL_MASK)
        self.playerCollider.node().setIntoCollideMask(BitMask32.allOff())

        # Sensor collision
        self.playerSensor = self.player.attachNewNode(
            CollisionNode('playersensor'))
        cs = CollisionSphere(0, 0, 0, 1.2)
        self.playerSensor.node().addSolid(cs)
        self.playerSensor.node().setFromCollideMask(DOOR_MASK)
        self.playerSensor.node().setIntoCollideMask(BitMask32.allOff())
        # as said above, to act correctly we need to make clear to the system that this is just a sensor, with no solid parts
        cs.setTangible(0)
Esempio n. 21
0
 def addGagCollision(self, gag):
     collNode = gag.attachNewNode(CollisionNode('coll_gag'))
     collNode.node().addSolid(CollisionSphere(0, 0, 0, 2))
     collNode.node().setIntoCollideMask(BitMask32.allOff())
     collNode.node().setFromCollideMask(Globals.GagBitmask | Globals.WallBitmask | Globals.FloorBitmask)
     base.cTrav.addCollider(collNode, collHdl)
     collHdl.addInPattern('%fn-into')
     collHdl.addOutPattern('%fn-out')
     self.accept("coll_gag-into", self.handleInCollisions)
     self.accept("coll_gag-out", self.completeCollision)
Esempio n. 22
0
 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)
Esempio n. 23
0
    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) 
Esempio n. 24
0
 def __init__(self):
     self.picker         = CollisionTraverser()            
     self.pickerQ        = CollisionHandlerQueue()         
     pickerCollN         = CollisionNode('mouseRay')       
     pickerCamN          = base.camera.attachNewNode(pickerCollN) 
     pickerCollN.setFromCollideMask(BitMask32.bit(1))         
     pickerCollN.setIntoCollideMask(BitMask32.allOff())         
     self.pickerRay      = CollisionRay()                
     pickerCollN.addSolid(self.pickerRay)      
     self.picker.addCollider(pickerCamN, self.pickerQ) 
     self.accept('mouse1',self.pick)                
Esempio n. 25
0
 def getFlyBallBubble(self):
     if self.__flyBallBubble == None:
         bubble = CollisionSphere(0, 0, 0, GolfGlobals.GOLF_BALL_RADIUS)
         node = CollisionNode('flyBallBubble')
         node.addSolid(bubble)
         node.setFromCollideMask(ToontownGlobals.PieBitmask | ToontownGlobals.CameraBitmask | ToontownGlobals.FloorBitmask)
         node.setIntoCollideMask(BitMask32.allOff())
         self.__flyBallBubble = NodePath(node)
         self.flyBallHandler = CollisionHandlerEvent()
         self.flyBallHandler.addInPattern('flyBallHit-%d' % self.index)
     return self.__flyBallBubble
 def getFlyBallBubble(self):
     if self.__flyBallBubble == None:
         bubble = CollisionSphere(0, 0, 0, GolfGlobals.GOLF_BALL_RADIUS)
         node = CollisionNode('flyBallBubble')
         node.addSolid(bubble)
         node.setFromCollideMask(ToontownGlobals.PieBitmask | ToontownGlobals.CameraBitmask | ToontownGlobals.FloorBitmask)
         node.setIntoCollideMask(BitMask32.allOff())
         self.__flyBallBubble = NodePath(node)
         self.flyBallHandler = CollisionHandlerEvent()
         self.flyBallHandler.addInPattern('flyBallHit-%d' % self.index)
     return self.__flyBallBubble
Esempio n. 27
0
 def addGagCollision(self, gag):
     collNode = gag.attachNewNode(CollisionNode('coll_gag'))
     collNode.node().addSolid(CollisionSphere(0, 0, 0, 2))
     collNode.node().setIntoCollideMask(BitMask32.allOff())
     collNode.node().setFromCollideMask(Globals.GagBitmask
                                        | Globals.WallBitmask
                                        | Globals.FloorBitmask)
     base.cTrav.addCollider(collNode, collHdl)
     collHdl.addInPattern('%fn-into')
     collHdl.addOutPattern('%fn-out')
     self.accept("coll_gag-into", self.handleInCollisions)
     self.accept("coll_gag-out", self.completeCollision)
 def setupEventSphere(self, bitmask, avatarRadius):
     self.avatarRadius = avatarRadius
     cSphere = CollisionSphere(0.0, 0.0, self.avatarRadius + 0.75, self.avatarRadius * 1.04)
     cSphere.setTangible(0)
     cSphereNode = CollisionNode('Flyer.cEventSphereNode')
     cSphereNode.addSolid(cSphere)
     cSphereNodePath = self.avatarNodePath.attachNewNode(cSphereNode)
     cSphereNode.setFromCollideMask(bitmask)
     cSphereNode.setIntoCollideMask(BitMask32.allOff())
     self.event = CollisionHandlerEvent()
     self.event.addInPattern('enter%in')
     self.event.addOutPattern('exit%in')
     self.cEventSphereNodePath = cSphereNodePath
 def setupFloorEventSphere(self, avatarNodePath, bitmask, avatarRadius):
     cSphere = CollisionSphere(0.0, 0.0, 0.0, 0.75)
     cSphereNode = CollisionNode('Flyer.cFloorEventSphere')
     cSphereNode.addSolid(cSphere)
     cSphereNodePath = avatarNodePath.attachNewNode(cSphereNode)
     cSphereNode.setFromCollideMask(bitmask)
     cSphereNode.setIntoCollideMask(BitMask32.allOff())
     self.floorCollisionEvent = CollisionHandlerEvent()
     self.floorCollisionEvent.addInPattern('%fn-enter-%in')
     self.floorCollisionEvent.addAgainPattern('%fn-again-%in')
     self.floorCollisionEvent.addOutPattern('%fn-exit-%in')
     base.cTrav.addCollider(cSphereNodePath, self.floorCollisionEvent)
     self.cFloorEventSphereNodePath = cSphereNodePath
 def setupHeadSphere(self, avatarNodePath):
     collSphere = CollisionSphere(0, 0, 0, 1)
     collSphere.setTangible(1)
     collNode = CollisionNode('Flyer.cHeadCollSphere')
     collNode.setFromCollideMask(ToontownGlobals.CeilingBitmask)
     collNode.setIntoCollideMask(BitMask32.allOff())
     collNode.addSolid(collSphere)
     self.cHeadSphereNodePath = avatarNodePath.attachNewNode(collNode)
     self.cHeadSphereNodePath.setZ(base.localAvatar.getHeight() + 1.0)
     self.headCollisionEvent = CollisionHandlerEvent()
     self.headCollisionEvent.addInPattern('%fn-enter-%in')
     self.headCollisionEvent.addOutPattern('%fn-exit-%in')
     base.cTrav.addCollider(self.cHeadSphereNodePath, self.headCollisionEvent)
Esempio n. 31
0
    def __init__(self,model):
        # 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.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.camGroundRay = CollisionRay()
        self.camGroundRay.setOrigin(0,0,1000)
        self.camGroundRay.setDirection(0,0,-1)
        self.camGroundCol = CollisionNode('camRay')
        self.camGroundCol.addSolid(self.camGroundRay)
        self.camGroundCol.setFromCollideMask(BitMask32.bit(0))
        self.camGroundCol.setIntoCollideMask(BitMask32.allOff())
        self.camGroundColNp = base.camera.attachNewNode(self.camGroundCol)
        self.camGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.camGroundColNp, self.camGroundHandler)

        # 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)
 def setupFloorEventSphere(self, avatarNodePath, bitmask, avatarRadius):
     cSphere = CollisionSphere(0.0, 0.0, 0.0, 0.75)
     cSphereNode = CollisionNode('Flyer.cFloorEventSphere')
     cSphereNode.addSolid(cSphere)
     cSphereNodePath = avatarNodePath.attachNewNode(cSphereNode)
     cSphereNode.setFromCollideMask(bitmask)
     cSphereNode.setIntoCollideMask(BitMask32.allOff())
     self.floorCollisionEvent = CollisionHandlerEvent()
     self.floorCollisionEvent.addInPattern('%fn-enter-%in')
     self.floorCollisionEvent.addAgainPattern('%fn-again-%in')
     self.floorCollisionEvent.addOutPattern('%fn-exit-%in')
     base.cTrav.addCollider(cSphereNodePath, self.floorCollisionEvent)
     self.cFloorEventSphereNodePath = cSphereNodePath
Esempio n. 33
0
    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)
 def setupEventSphere(self, bitmask, avatarRadius):
     self.avatarRadius = avatarRadius
     cSphere = CollisionSphere(0.0, 0.0, self.avatarRadius + 0.75,
                               self.avatarRadius * 1.04)
     cSphere.setTangible(0)
     cSphereNode = CollisionNode('Flyer.cEventSphereNode')
     cSphereNode.addSolid(cSphere)
     cSphereNodePath = self.avatarNodePath.attachNewNode(cSphereNode)
     cSphereNode.setFromCollideMask(bitmask)
     cSphereNode.setIntoCollideMask(BitMask32.allOff())
     self.event = CollisionHandlerEvent()
     self.event.addInPattern('enter%in')
     self.event.addOutPattern('exit%in')
     self.cEventSphereNodePath = cSphereNodePath
 def setupWallSphere(self, bitmask, avatarRadius):
     self.avatarRadius = avatarRadius
     cSphere = CollisionSphere(0.0, 0.0, self.avatarRadius + 0.75, self.avatarRadius)
     cSphereNode = CollisionNode('Flyer.cWallSphereNode')
     cSphereNode.addSolid(cSphere)
     cSphereNodePath = self.avatarNodePath.attachNewNode(cSphereNode)
     cSphereNode.setFromCollideMask(bitmask)
     cSphereNode.setIntoCollideMask(BitMask32.allOff())
     if config.GetBool('want-fluid-pusher', 0):
         self.pusher = CollisionHandlerFluidPusher()
     else:
         self.pusher = CollisionHandlerPusher()
     self.pusher.addCollider(cSphereNodePath, self.avatarNodePath)
     self.cWallSphereNodePath = cSphereNodePath
 def setupHeadSphere(self, avatarNodePath):
     collSphere = CollisionSphere(0, 0, 0, 1)
     collSphere.setTangible(1)
     collNode = CollisionNode('Flyer.cHeadCollSphere')
     collNode.setFromCollideMask(ToontownGlobals.CeilingBitmask)
     collNode.setIntoCollideMask(BitMask32.allOff())
     collNode.addSolid(collSphere)
     self.cHeadSphereNodePath = avatarNodePath.attachNewNode(collNode)
     self.cHeadSphereNodePath.setZ(base.localAvatar.getHeight() + 1.0)
     self.headCollisionEvent = CollisionHandlerEvent()
     self.headCollisionEvent.addInPattern('%fn-enter-%in')
     self.headCollisionEvent.addOutPattern('%fn-exit-%in')
     base.cTrav.addCollider(self.cHeadSphereNodePath,
                            self.headCollisionEvent)
Esempio n. 37
0
 def __init__(self,rootNode,trav,id):
     self.GroundRay=CollisionRay(0,0,10,0,0,-1)
     self.GroundCol = CollisionNode('colDown_'+str(id))
     self.GroundCol.addSolid(self.GroundRay)
     self.GroundCol.setFromCollideMask(BitMask32.bit(1))
     self.GroundCol.setIntoCollideMask(BitMask32.allOff())
     self.GroundColNp = rootNode.attachNewNode(self.GroundCol)
     #self.GroundColNp.show()
     self.GroundHandler = CollisionHandlerQueue()
     trav.addCollider(self.GroundColNp, self.GroundHandler)
     
     self.EnvDetector=CollisionSphere(0, 0, 1, 0.8)
     self.EnvCol = CollisionNode('colEnv_'+str(id))
     self.EnvCol.addSolid(self.EnvDetector)
     self.EnvCol.setFromCollideMask(BitMask32.bit(2))
     self.EnvCol.setIntoCollideMask(BitMask32.allOff())
     self.EnvColNp = rootNode.attachNewNode(self.EnvCol)
     #self.EnvColNp.show()
     self.pusher = CollisionHandlerPusher()
     self.pusher.addCollider(self.EnvColNp, rootNode)
     trav.addCollider(self.EnvColNp, self.pusher)
         
     self.trav=trav
 def __init__(
     self,
     modelStanding,
     modelAnimationDict,
     turnRate,
     speed,
     agentList,
     name="",
     rangeFinderCount=13,
     collisionMask=BitMask32.allOff(),
     adjacencySensorThreshold=0,
     radarSlices=0,
     radarLength=0.0,
     scale=1.0,
     brain=None,
     massKg=0.1,
     collisionHandler=None,
     collisionTraverser=None,
     waypoints=None,
 ):
     Agent.__init__(
         self,
         modelStanding,
         modelAnimationDict,
         turnRate,
         speed,
         agentList,
         massKg,
         collisionMask,
         name,
         collisionHandler,
         collisionTraverser,
     )
     self.collisionMask = collisionMask
     self.adjacencySensorThreshold = adjacencySensorThreshold
     self.radarSlices = radarSlices
     self.radarLength = radarLength
     self.scale = scale
     self.brain = brain
     self.npcState = "retriveKey"
     self.waypoints = waypoints
     self.targetReached = False
     self.setScale(self.scale)
     self.currentTarget = None
     self.player = None
     self.bestPath = None
     self.key = None
     self.keyInHand = False
     self.hasFallen = False
     self.pathSmoothening = True
Esempio n. 39
0
    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) 
Esempio n. 40
0
def yolkySensorIn(entry):
    global last_spawn
    np_into = entry.getIntoNodePath()
    # the lever trigger
    if np_into.getName().find('trigger_lev1') >= 0:
        if rope_stair.getSz() < 1.:
            np_into.getParent().setR(20)
            scale = rope_stair.getScale()
            LerpScaleInterval(rope_stair,
                              2, (scale[0], scale[1], .42),
                              blendType='easeOut').start()
    # the balancing wooden surface
    elif np_into.getName().find('trigger_balance') >= 0:
        model = np_into.getParent()
        LerpHprInterval(model, 3, (0, 0, 0), blendType='easeIn').start()
    # touching the rope stair
    elif np_into.getName().find('trigger_ropest') >= 0:
        setgodmode(True)
    # reaching the end of the level
    elif np_into.getName().find('trigger_eol') >= 0:
        end_of_level()
    # touching the next spawn point - will be shut off the former and stored the new one
    elif np_into.getName().find('spawn') >= 0:
        if last_spawn != np_into:
            last_spawn.node().setIntoCollideMask(BitMask32.allOff())
            last_spawn = np_into
    # the sensor touch the floor, therefore we'll test if yolky is hitting it too hard
    else:

        def yolkyHitTheGround(task):
            if avatarFloorHandler.isOnGround():
                # Getting the impact speed - if that will be more than a certain value we'll consider yolky dead.
                iv = abs(avatarFloorHandler.getImpactVelocity())
                if iv > 35:
                    t = "Oh No, I guess is dead! Respawning..."
                    Sequence(
                        Func(snipstuff.infotext['message'].setText, t),
                        Func(splat, 1),
                        Wait(3),
                        Func(splat, 0),
                        Func(avatar.setHpr, (0, 0, 0)),
                        Func(snipstuff.infotext['message'].setText, ""),
                        Func(respawn),
                    ).start()
                task.remove()
            else:
                return task.cont

        tsk = taskMgr.add(yolkyHitTheGround, "yolky_hit_g")
Esempio n. 41
0
    def __init__(self, model, run, walk, startPos, scale,select,saysome):
        
        self.playerGUI = saysome
        print(self.playerGUI.getpausevalue())
        self.controlMap = {"left":0, "right":0, "forward":0}
        self.select = select
        self.actor = Actor(model, {"run":run, "walk":walk})
        self.actor.reparentTo(render)
        self.actor.setScale(scale)
        self.actor.setPos(startPos)
        self.actor.setHpr(90,0,0)

        taskMgr.add(self.move,"moveTask")

        self.prevtime = 0
        self.isMoving = False
        
        self.cTrav = CollisionTraverser()

        self.groundRay = CollisionRay(0,0,1000,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)

        self.sphere = CollisionSphere(0,0,0,3)
        self.spherecol = CollisionNode('ralphSphere')
        self.spherecol.addSolid(self.sphere)
        self.spherecol.setFromCollideMask(BitMask32.bit(1))
        self.spherecol.setIntoCollideMask(BitMask32.allOff())
        self.ralphcolhs = self.actor.attachNewNode(self.spherecol)
        self.ralphcolhandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.ralphcolhs , self.ralphcolhandler)
Esempio n. 42
0
    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)
 def setupWallSphere(self, bitmask, avatarRadius):
     self.avatarRadius = avatarRadius
     cSphere = CollisionSphere(0.0, 0.0, self.avatarRadius + 0.75,
                               self.avatarRadius)
     cSphereNode = CollisionNode('Flyer.cWallSphereNode')
     cSphereNode.addSolid(cSphere)
     cSphereNodePath = self.avatarNodePath.attachNewNode(cSphereNode)
     cSphereNode.setFromCollideMask(bitmask)
     cSphereNode.setIntoCollideMask(BitMask32.allOff())
     if config.GetBool('want-fluid-pusher', 0):
         self.pusher = CollisionHandlerFluidPusher()
     else:
         self.pusher = CollisionHandlerPusher()
     self.pusher.addCollider(cSphereNodePath, self.avatarNodePath)
     self.cWallSphereNodePath = cSphereNodePath
    def __setupCollisionHandling(self, collisionHandler, collisionTraverser):
        if not collisionTraverser.getRespectPrevTransform():
            collisionTraverser.setRespectPrevTransform(True)

        # We do this so we don't take into account the actual model, but the collision sphere
        self.actor.setCollideMask(BitMask32.allOff())

        self.node().getPhysicsObject().setMass(self.massKg)
        base.physicsMgr.attachPhysicalNode(self.node())
        fromObject = self.attachNewNode(CollisionNode(self.name + " collision node"))
        fromObject.node().setIntoCollideMask(fromObject.node().getIntoCollideMask() & ~GeomNode.getDefaultCollideMask())
        fromObject.node().setFromCollideMask(self.collisionMask)
        fromObject.node().addSolid(CollisionSphere(0, 0, 2.5, 2.5))

        collisionHandler.addCollider(fromObject, self)
        collisionTraverser.addCollider(fromObject, collisionHandler)
Esempio n. 45
0
 def addCogCollision(self, cog):
     ent = cog.getCog()
     head = cog.getHead()
     if(head != None):
         sphPos = cog.getHead().getZ(render) + 0.5
     else:
         sphPos = ent.find('**/joint_head').getPos(render).getZ() + 0.8        
     collTube = ent.attachNewNode(CollisionNode('coll_body'))
     collTube.node().addSolid(CollisionTube(0, 0, 0.5, 0, 0, cog.getHeight() - 2, 2))
     collTube.node().setIntoCollideMask(Globals.GagBitmask)
     collTube.node().setFromCollideMask(BitMask32.allOff())
     collSph = ent.attachNewNode(CollisionNode('coll_crit'))
     collSph.node().addSolid(CollisionSphere(0, 0, sphPos, 2))
     collSph.node().setIntoCollideMask(Globals.GagBitmask)
     base.cTrav.addCollider(collTube, collHdl)
     base.cTrav.addCollider(collSph, collHdl)
 def setupRay(self, bitmask, floorOffset, reach):
     cRay = CollisionRay(0.0, 0.0, 3.0, 0.0, 0.0, -1.0)
     cRayNode = CollisionNode('Flyer.cRayNode')
     cRayNode.addSolid(cRay)
     self.cRayNodePath = self.avatarNodePath.attachNewNode(cRayNode)
     cRayNode.setFromCollideMask(bitmask)
     cRayNode.setIntoCollideMask(BitMask32.allOff())
     self.lifter = CollisionHandlerGravity()
     self.lifter.setLegacyMode(self._legacyLifter)
     self.lifter.setGravity(self.getGravity(0))
     self.lifter.addInPattern('%fn-enter-%in')
     self.lifter.addAgainPattern('%fn-again-%in')
     self.lifter.addOutPattern('%fn-exit-%in')
     self.lifter.setOffset(floorOffset)
     self.lifter.setReach(reach)
     self.lifter.addCollider(self.cRayNodePath, self.avatarNodePath)
Esempio n. 47
0
    def createDoor(self):
        # Tell DNANode to create the dummy node now
        self.createDummy()

        # Set the collision geometry; we need first a CollisionNode
        sensor = self.node.attachNewNode(CollisionNode(self.name))
        # We add that to our CollisionSphere geometry primitive
        sensor.node().addSolid(CollisionTube(-14, 0, 0, 14, 0, 0, 1.5))
        sensor.node().setFromCollideMask(BitMask32.allOff())
        sensor.node().setIntoCollideMask(DOOR_MASK)
        sensor.show()

        # Collision logic
        self.DNAParser.main.accept('playersensor-into-' + self.name,
                                   self.DNAParser.main.transition,
                                   [self.nextroom, self.exit])
 def setupRay(self, bitmask, floorOffset, reach):
     cRay = CollisionRay(0.0, 0.0, 3.0, 0.0, 0.0, -1.0)
     cRayNode = CollisionNode('Flyer.cRayNode')
     cRayNode.addSolid(cRay)
     self.cRayNodePath = self.avatarNodePath.attachNewNode(cRayNode)
     cRayNode.setFromCollideMask(bitmask)
     cRayNode.setIntoCollideMask(BitMask32.allOff())
     self.lifter = CollisionHandlerGravity()
     self.lifter.setLegacyMode(self._legacyLifter)
     self.lifter.setGravity(self.getGravity(0))
     self.lifter.addInPattern('%fn-enter-%in')
     self.lifter.addAgainPattern('%fn-again-%in')
     self.lifter.addOutPattern('%fn-exit-%in')
     self.lifter.setOffset(floorOffset)
     self.lifter.setReach(reach)
     self.lifter.addCollider(self.cRayNodePath, self.avatarNodePath)
    def _DistributedBanquetTable__endFireWater(self):
        if self.aimStart == None:
            return None

        if not self.state == "Controlled":
            return None

        if not self.avId == localAvatar.doId:
            return None

        taskMgr.remove(self.waterPowerTaskName)
        messenger.send("wakeup")
        self.aimStart = None
        origin = self.nozzle.getPos(render)
        target = self.boss.getPos(render)
        angle = deg2Rad(self.waterPitcherNode.getH() + 90)
        x = math.cos(angle)
        y = math.sin(angle)
        fireVector = Point3(x, y, 0)
        if self.power < 0.001:
            self.power = 0.001

        self.lastPowerFired = self.power
        fireVector *= self.fireLength * self.power
        target = origin + fireVector
        segment = CollisionSegment(origin[0], origin[1], origin[2], target[0], target[1], target[2])
        fromObject = render.attachNewNode(CollisionNode("pitcherColNode"))
        fromObject.node().addSolid(segment)
        fromObject.node().setFromCollideMask(
            ToontownGlobals.PieBitmask | ToontownGlobals.CameraBitmask | ToontownGlobals.FloorBitmask
        )
        fromObject.node().setIntoCollideMask(BitMask32.allOff())
        queue = CollisionHandlerQueue()
        base.cTrav.addCollider(fromObject, queue)
        base.cTrav.traverse(render)
        queue.sortEntries()
        self.hitObject = None
        if queue.getNumEntries():
            entry = queue.getEntry(0)
            target = entry.getSurfacePoint(render)
            self.hitObject = entry.getIntoNodePath()

        base.cTrav.removeCollider(fromObject)
        fromObject.removeNode()
        self.d_firingWater(origin, target)
        self.fireWater(origin, target)
        self.resetPowerBar()
Esempio n. 50
0
 def __init__(self,
              modelStanding,
              modelAnimationDict,
              turnRate,
              speed,
              agentList,
              name="",
              massKg=0.1,
              collisionMask=BitMask32.allOff(),
              scale=1.0,
              collisionHandler=None,
              collisionTraverser=None):
     Agent.__init__(self, modelStanding, modelAnimationDict, turnRate,
                    speed, agentList, massKg, collisionMask, name,
                    collisionHandler, collisionTraverser)
     self.rightHand = self.actor.exposeJoint(None, 'modelRoot', 'RightHand')
     self.currentKey = None
Esempio n. 51
0
    def __setupCollisionHandling(self, collisionHandler, collisionTraverser):
        if not collisionTraverser.getRespectPrevTransform():
            collisionTraverser.setRespectPrevTransform(True)
            
        # We do this so we don't take into account the actual model, but the collision sphere
        self.actor.setCollideMask(BitMask32.allOff())
            
        self.node().getPhysicsObject().setMass(self.massKg) 
        base.physicsMgr.attachPhysicalNode(self.node())
        fromObject = self.attachNewNode(CollisionNode(self.name + " collision node"))
        fromObject.node().setIntoCollideMask(fromObject.node().getIntoCollideMask() & ~GeomNode.getDefaultCollideMask())
        fromObject.node().setFromCollideMask(self.collisionMask)
        fromObject.node().addSolid(CollisionSphere(0, 0, 2.5, 2.5))
        

        collisionHandler.addCollider(fromObject, self)
        collisionTraverser.addCollider(fromObject, collisionHandler)
Esempio n. 52
0
 def addCogCollision(self, cog):
     ent = cog.getCog()
     head = cog.getHead()
     if (head != None):
         sphPos = cog.getHead().getZ(render) + 0.5
     else:
         sphPos = ent.find('**/joint_head').getPos(render).getZ() + 0.8
     collTube = ent.attachNewNode(CollisionNode('coll_body'))
     collTube.node().addSolid(
         CollisionTube(0, 0, 0.5, 0, 0,
                       cog.getHeight() - 2, 2))
     collTube.node().setIntoCollideMask(Globals.GagBitmask)
     collTube.node().setFromCollideMask(BitMask32.allOff())
     collSph = ent.attachNewNode(CollisionNode('coll_crit'))
     collSph.node().addSolid(CollisionSphere(0, 0, sphPos, 2))
     collSph.node().setIntoCollideMask(Globals.GagBitmask)
     base.cTrav.addCollider(collTube, collHdl)
     base.cTrav.addCollider(collSph, collHdl)
Esempio n. 53
0
 def __endFireWater(self):
     if self.aimStart == None:
         return
     if not self.state == 'Controlled':
         return
     if not self.avId == localAvatar.doId:
         return
     taskMgr.remove(self.waterPowerTaskName)
     messenger.send('wakeup')
     self.aimStart = None
     origin = self.nozzle.getPos(render)
     target = self.boss.getPos(render)
     angle = deg2Rad(self.waterPitcherNode.getH() + 90)
     x = math.cos(angle)
     y = math.sin(angle)
     fireVector = Point3(x, y, 0)
     if self.power < 0.001:
         self.power = 0.001
     self.lastPowerFired = self.power
     fireVector *= self.fireLength * self.power
     target = origin + fireVector
     segment = CollisionSegment(origin[0], origin[1], origin[2], target[0],
                                target[1], target[2])
     fromObject = render.attachNewNode(CollisionNode('pitcherColNode'))
     fromObject.node().addSolid(segment)
     fromObject.node().setFromCollideMask(ToontownGlobals.PieBitmask
                                          | ToontownGlobals.CameraBitmask
                                          | ToontownGlobals.FloorBitmask)
     fromObject.node().setIntoCollideMask(BitMask32.allOff())
     queue = CollisionHandlerQueue()
     base.cTrav.addCollider(fromObject, queue)
     base.cTrav.traverse(render)
     queue.sortEntries()
     self.hitObject = None
     if queue.getNumEntries():
         entry = queue.getEntry(0)
         target = entry.getSurfacePoint(render)
         self.hitObject = entry.getIntoNodePath()
     base.cTrav.removeCollider(fromObject)
     fromObject.removeNode()
     self.d_firingWater(origin, target)
     self.fireWater(origin, target)
     self.resetPowerBar()
     return
Esempio n. 54
0
    def createCollisionHandlers(self):
        # Create a new collision traverser instance. We will use this to determine
        # if any collisions occurred after performing movement.
        self.cTrav = CollisionTraverser()

        camGroundRay = CollisionRay()
        camGroundRay.setOrigin(0, 0, 1000)
        camGroundRay.setDirection(0, 0, -1)
        camGroundCol = CollisionNode('camRay')
        camGroundCol.addSolid(camGroundRay)
        camGroundCol.setFromCollideMask(BitMask32.bit(0))
        camGroundCol.setIntoCollideMask(BitMask32.allOff())
        camGroundColNp = base.camera.attachNewNode(camGroundCol)
        self.camGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(camGroundColNp, self.camGroundHandler)

        # register the collision pusher
        self.pusher = CollisionHandlerPusher()

        # register collision event pattern names
        self.pusher.addInPattern('col-%fn-into')
Esempio n. 55
0
 def __init__(self,
              modelStanding,
              modelAnimationDict,
              turnRate,
              speed,
              agentList,
              name="",
              rangeFinderCount=13,
              collisionMask=BitMask32.allOff(),
              adjacencySensorThreshold=0,
              radarSlices=0,
              radarLength=0.0,
              scale=1.0,
              brain=None,
              massKg=0.1,
              collisionHandler=None,
              collisionTraverser=None,
              waypoints=None):
     Agent.__init__(self, modelStanding, modelAnimationDict, turnRate,
                    speed, agentList, massKg, collisionMask, name,
                    collisionHandler, collisionTraverser)
     self.collisionMask = collisionMask
     self.adjacencySensorThreshold = adjacencySensorThreshold
     self.radarSlices = radarSlices
     self.radarLength = radarLength
     self.scale = scale
     self.brain = brain
     self.npcState = "retriveKey"
     self.waypoints = waypoints
     self.targetReached = False
     self.setScale(self.scale)
     self.currentTarget = None
     self.player = None
     self.bestPath = None
     self.key = None
     self.keyInHand = False
     self.hasFallen = False
     self.pathSmoothening = True
Esempio n. 56
0
    def loadWallModel(self):
        #loads the wall model (the maze) 
        wallScale = 0.3
        wallModelName = self.randomWallModel()
            #randomly select a maze

        self.wallModel = loader.loadModel(wallModelName)
        self.wallModel.setScale(wallScale)
        self.wallModel.setPos(0, 0, 0)
        self.wallModel.setCollideMask(BitMask32.allOff())
        self.wallModel.reparentTo(render)

        ### Setting Texture ###
        texScale = 0.08
        self.wallModel.setTexGen(TextureStage.getDefault(),
                                   TexGenAttrib.MWorldNormal)
        self.wallModel.setTexProjector(TextureStage.getDefault(),
                                         render, self.wallModel)
        self.wallModel.setTexScale(TextureStage.getDefault(), texScale)
        tex = loader.load3DTexture('/Users/jianwei/Documents/School/Freshman/Semester1/15-112/TERMPROJECT/Project/wallTex/wallTex_#.png')
        self.wallModel.setTexture(tex)

        #creating visual geometry collision
        self.wallModel.setCollideMask(BitMask32.bit(0))
Esempio n. 57
0
    def __init__(self, name, world, pos):
        ActorNode.__init__(self, name)

        self.nodePath = NodePath(self)

        self.world = world

        # init the model or the Actor
        self.model = self.getModel()
        self.model.reparentTo(self.nodePath)

        self.nodePath.setPos(*pos)

        self.prevPos = self.nodePath.getPos()

        # collision detection
        fromObject = self.nodePath.attachNewNode(CollisionNode(name))
        self.addSolids(fromObject)
        fromObject.show()

        # setup the ground ray, needed for detecting the ground
        groundRay = CollisionRay()
        groundRay.setOrigin(0, 0, 1000)
        groundRay.setDirection(0, 0, -1)
        groundCol = CollisionNode('groundRay')
        groundCol.addSolid(groundRay)
        groundCol.setFromCollideMask(BitMask32.bit(0))
        groundCol.setIntoCollideMask(BitMask32.allOff())
        groundColNp = base.camera.attachNewNode(groundCol)
        self.groundHandler = CollisionHandlerQueue()
        self.world.cTrav.addCollider(groundColNp, self.groundHandler)

        #        self.world.cTrav.addCollider(fromObject, self.world.pusher)
        #        self.world.pusher.addCollider(fromObject, self.nodePath)

        self.postInit()
Esempio n. 58
0
#** Collision masks - this time there is a new one: the TRIGGER_MASK is used to detect certain collision geometry to act as a trigger, therefore we need to distinguish'em from floor and walls.
FLOOR_MASK = BitMask32.bit(1)
WALL_MASK = BitMask32.bit(2)
TRIGGER_MASK = BitMask32.bit(3)

#** Our steering avatar
avatarNP = base.render.attachNewNode(ActorNode('yolkyNP'))
avatarNP.reparentTo(base.render)
# by the way: this time we wont use the same old smiley but a 2d guy for this snippet purposes only - it is just a plane with a texture glued on, a so 2d object then.
avatar = loader.loadModel('yolky')
avatar.reparentTo(avatarNP)
# why this? this is to have our flat puppet rendered always on top of all objects in the scene, either 2d and 3d.
avatar.setDepthWrite(True, 100)
# the rest of the stuff is as usual...
avatar.setPos(0, 0, 1)
avatar.setCollideMask(BitMask32.allOff())
avatarNP.setPos(0, 0, 15)
# The yolky collision sphere used to detect when yolky hits walls
avatarCollider = avatar.attachNewNode(CollisionNode('yolkycnode'))
avatarCollider.node().addSolid(CollisionSphere(0, 0, 0, 1))
avatarCollider.node().setFromCollideMask(WALL_MASK)
avatarCollider.node().setIntoCollideMask(BitMask32.allOff())

#** the avatar's fallout sensor - stuff already seen in former snippets, but this time we'll use it for more that to detect the fallout impact force, so we'll add another mask to look out
avatarSensor = avatarNP.attachNewNode(CollisionNode('yolkysensor'))
cs = CollisionSphere(0, 0, 0, 1.2)
avatarSensor.node().addSolid(cs)
# here the masking: note that this sensor will look for floor bashing but also for other geometries masked with TRIGGER_MASK.
avatarSensor.node().setFromCollideMask(FLOOR_MASK | TRIGGER_MASK)
avatarSensor.node().setIntoCollideMask(BitMask32.allOff())
cs.setTangible(0)