def addRalph(self, pos):
        ralphStartPos = pos
        self.ralph = Actor("models/ralph",
                                 {"run":"models/ralph-run",
                                  "walk":"models/ralph-walk"})
        self.ralph.reparentTo(render)
        self.ralph.setScale(.2)
        self.ralph.setPos(ralphStartPos)
        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)
Exemple #2
0
    def __init__(self):
        self.accept('mouse1', self.onMouse1Down, [])  # Left click
        self.accept('mouse1-up', self.onMouse1Up, [])
        self.accept('mouse3', self.onMouse3Down, [])  # Right click

        self.showCollisions = False

        pickerNode = CollisionNode('mouseRay')
        pickerNP = camera.attachNewNode(pickerNode)
        pickerNode.setFromCollideMask(cardBuilder.cardCollisionMask)
        self.pickerRay = CollisionRay()
        pickerNode.addSolid(self.pickerRay)
        base.cTrav.addCollider(pickerNP, base.handler)
        if self.showCollisions:
            base.cTrav.showCollisions(render)
        base.disableMouse()

        self.activeCard = None
        self._targeting = False

        self._dragging = None

        # Counts down between clicks to detect double click
        self.doubleClickTimer = -1.0
        self.doubleClickInterval = 1.0

        self.line = attackLine.Line()
Exemple #3
0
 def createPlayerCollisions(self):
     """ create a collision solid and ray for the player """
     cn = CollisionNode('player')
     cn.setFromCollideMask(COLLISIONMASKS['geometry'])
     cn.setIntoCollideMask(COLLISIONMASKS['portals'] | COLLISIONMASKS['exit'] | COLLISIONMASKS['lava'])
     cn.addSolid(CollisionSphere(0,0,0,3))
     solid = self.node.attachNewNode(cn)
     # TODO : find a way to remove that, it's the cause of the little
     # "push me left" effect we see sometime when exiting a portal
     self.base.cTrav.addCollider(solid,self.base.pusher)
     self.base.pusher.addCollider(solid,self.node, self.base.drive.node())
     # init players floor collisions
     ray = CollisionRay()
     ray.setOrigin(0,0,-.2)
     ray.setDirection(0,0,-1)
     cn = CollisionNode('playerRay')
     cn.setFromCollideMask(COLLISIONMASKS['player'])
     cn.setIntoCollideMask(BitMask32.allOff())
     cn.addSolid(ray)
     solid = self.node.attachNewNode(cn)
     self.nodeGroundHandler = CollisionHandlerQueue()
     self.base.cTrav.addCollider(solid, self.nodeGroundHandler)
     # init players ceil collisions
     ray = CollisionRay()
     ray.setOrigin(0,0,.2)
     ray.setDirection(0,0,1)
     cn = CollisionNode('playerUpRay')
     cn.setFromCollideMask(COLLISIONMASKS['player'])
     cn.setIntoCollideMask(BitMask32.allOff())
     cn.addSolid(ray)
     solid = self.node.attachNewNode(cn)
     self.ceilGroundHandler = CollisionHandlerQueue()
     self.base.cTrav.addCollider(solid, self.ceilGroundHandler)
 def startSeeking(self):
     if not self.avatar: return
     self.cleanupShadow()
     self.buildShadow()
     
     # Let's increase the distance if the shadow is smaller than expected.
     scale = self.dropShadow.getScale()
     if scale < 1.0:
         self.maxDistance += 40
         
     # Let's setup the drop shadow's initial position.
     x, y, z = self.avatar.getPos(render)
     self.dropShadow.reparentTo(render)
     self.dropShadow.setPos(x, y + 5, z + 2)
     
     # Let's setup the collisions for the mouse.
     self.cameraNode = CollisionNode('coll_camera')
     self.cameraNode.setFromCollideMask(CIGlobals.WallBitmask)
     self.cameraRay = CollisionRay()
     self.cameraNode.addSolid(self.cameraRay)
     self.cameraNP = camera.attachNewNode(self.cameraNode)
     base.cTrav.addCollider(self.cameraNP, CollisionHandlerQueue())
     
     if not self.legacyMode:
         # Let's setup the collisions for the shadow.
         shadowNode = CollisionNode('coll_shadow')
         self.shadowRay = CollisionRay(0, 0, 6, 0, 0, -1)
         shadowNode.addSolid(self.shadowRay)
         shadowNode.setFromCollideMask(CIGlobals.FloorBitmask)
         self.shadowNP = self.dropShadow.attachNewNode(shadowNode)
         base.cTrav.addCollider(self.shadowNP, self.collHdlFl)
     
     # Finally, let's start moving the shadow with the mouse and accept left mouse clicks.
     base.taskMgr.add(self.__moveShadow, self.moveShadowTaskName)
     self.avatar.acceptOnce('mouse1', self.locationChosen)
Exemple #5
0
    def __init__(self):
        self.enabled = False
        self.locked = False
        self.position = Vec3(0, 0, 0)
        self.delta = Vec3(0, 0, 0)
        self.prev_x = 0
        self.prev_y = 0
        self.start_x = 0
        self.start_y = 0
        self.velocity = Vec3(0, 0, 0)
        self.prev_click_time = time.time()
        self.double_click_distance = .5

        self.hovered_entity = None
        self.left = False
        self.right = False
        self.middle = False
        self.delta_drag = Vec3(0, 0, 0)

        self.update_step = 1
        self._i = 0
        self._mouse_watcher = None
        self._picker = CollisionTraverser()  # Make a traverser
        self._pq = CollisionHandlerQueue()  # Make a handler
        self._pickerNode = CollisionNode('mouseRay')
        self._pickerNP = camera.attach_new_node(self._pickerNode)
        self._pickerRay = CollisionRay()  # Make our ray
        self._pickerNode.addSolid(self._pickerRay)
        self._picker.addCollider(self._pickerNP, self._pq)
        self._pickerNode.set_into_collide_mask(0)

        self.raycast = True
        self.collision = None
        self.collisions = list()
        self.enabled = True
Exemple #6
0
    def __init__(self, render, objid, start_pos, gameclient):
        self.client = gameclient
        self.id = objid
        self.motion_controller = None
        self.is_player = False

        # state  management
        self.isAnimating = False
        self.state = state.IDLE

        self.render = render  # scene graph root

        #  create the panda3d actor: just load a default model for now
        self.actor = Actor("models/ralph", {
            "run": "models/ralph-run",
            "walk": "models/ralph-walk"
        })

        self.actor.reparentTo(render)
        self.actor.setScale(.2)
        self.actor.setPos(start_pos)

        # prepare collision handling
        self.cTrav = CollisionTraverser()
        self.GroundRay = CollisionRay()
        self.GroundRay.setOrigin(0, 0, 1000)
        self.GroundRay.setDirection(0, 0, -1)
        self.GroundCol = CollisionNode('actorRay')
        self.GroundCol.addSolid(self.GroundRay)
        self.GroundCol.setFromCollideMask(BitMask32.bit(0))
        self.GroundCol.setIntoCollideMask(BitMask32.allOff())
        self.GroundColNp = self.actor.attachNewNode(self.GroundCol)
        self.GroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.GroundColNp, self.GroundHandler)
 def startSeeking(self):
     if not self.avatar:
         return
     self.cleanupShadow()
     self.buildShadow()
     scale = self.dropShadow.getScale()
     if scale < 1.0:
         self.maxDistance += 40
     x, y, z = self.avatar.getPos(render)
     self.dropShadow.reparentTo(render)
     self.dropShadow.setPos(x, y + 5, z + 2)
     self.cameraNode = CollisionNode('coll_camera')
     self.cameraNode.setFromCollideMask(CIGlobals.WallBitmask)
     self.cameraRay = CollisionRay()
     self.cameraNode.addSolid(self.cameraRay)
     self.cameraNP = camera.attachNewNode(self.cameraNode)
     base.cTrav.addCollider(self.cameraNP, CollisionHandlerQueue())
     if not self.legacyMode:
         shadowNode = CollisionNode('coll_shadow')
         self.shadowRay = CollisionRay(0, 0, 6, 0, 0, -1)
         shadowNode.addSolid(self.shadowRay)
         shadowNode.setFromCollideMask(CIGlobals.FloorBitmask)
         self.shadowNP = self.dropShadow.attachNewNode(shadowNode)
         base.cTrav.addCollider(self.shadowNP, self.collHdlFl)
     base.taskMgr.add(self.__moveShadow, self.moveShadowTaskName)
     self.avatar.acceptOnce('mouse1', self.locationChosen)
Exemple #8
0
    def __init__(self):
        #selection detection
        self.picker = CollisionTraverser()
        self.pq = CollisionHandlerQueue()
        self.pickerNode = CollisionNode('mouseRay')
        self.pickerNP = camera.attachNewNode(self.pickerNode)
        #self.pickerNode.setFromCollideMask(GeomNode.getDefaultCollideMask()) #TODO WOW geometry collision is SUPER slow...
        self.pickerNode.setFromCollideMask(BitMask32.bit(BITMASK_COLL_CLICK))
        #render.find('**selectable').node().setIntoCollideMask(BitMask32.bit(1))
        self.pickerRay = CollisionRay()
        self.pickerNode.addSolid(self.pickerRay)
        self.picker.addCollider(self.pickerNP, self.pq)
        #self.picker.showCollisions(render)

        #box selection detection HINT: start with drawing the 2d thing yo!

        self.__shift__ = False
        self.accept("shift", self.shiftOn)
        self.accept("shift-up", self.shiftOff)

        self.__ctrl__ = False
        self.accept("control", self.ctrlOn)
        self.accept("control-up", self.ctrlOff)

        #mouse handling
        self.accept("mouse1", self.clickHandler)
        self.accept("shift-mouse1", self.clickHandler)
        self.accept("mouse1-up", self.releaseHandler)

        #dragging
        self.dragTask = taskMgr.add(self.dragTask, 'dragTask')
Exemple #9
0
    def __init__(self, parent: NodePath):
        super().__init__()
        self.parent = parent

        self.mouse_np = p3d.camera.attach_new_node(PandaNode('mouse'))
        self.mouse_np.set_y(p3d.lens.get_near())

        picker_node = CollisionNode('mouse_ray')
        picker_np = p3d.camera.attach_new_node(picker_node)
        self._picker_ray = CollisionRay()
        picker_node.add_solid(self._picker_ray)
        self._collision_handler = CollisionHandlerQueue()
        self._traverser = CollisionTraverser('mouse_traverser')
        self._traverser.add_collider(picker_np, self._collision_handler)

        self.actor = Actor(
            resource_filename('tsim', 'data/models/cursor'),
            {'spin': resource_filename('tsim', 'data/models/cursor-spin')})
        self.actor.loop('spin')
        self.actor.reparent_to(parent)
        self.actor.set_pos(0.0, 0.0, 0.0)
        self.actor.set_shader_off()

        self._position = Point(0.0, 0.0)
        self.last_position = self._position
        self.moved = False
        self.pointed_at = None

        self._tool: Optional[Tool] = None
        self._register_events()
Exemple #10
0
 def setUpCarCollider(self):
     self.carCollideTrav = CollisionTraverser()
     base.cTrav = self.carCollideTrav
     self.handler = CollisionHandlerQueue()
     self.carRay = CollisionRay(self.carPositionX, self.carPositionY,
                                self.carPositionZ, 0, 0, -1)
     self.carForwardHandler = CollisionHandlerQueue()
     # so that it doesn't collide with things forward and backward.
     degToRad = math.pi / 180
     (xDir, yDir, zDir) = self.findCarFrontDir()
     self.carRayForward = CollisionRay(self.carPositionX, self.carPositionY,
                                       self.carPositionZ, xDir, yDir, zDir)
     self.carForwardCollision = CollisionNode("forwardCollision")
     self.carForwardCollision.addSolid(self.carRayForward)
     self.carForwardCollision.setIntoCollideMask(CollideMask.allOff())
     self.carForwardCollisionNode = self.car.attachNewNode(
         self.carForwardCollision)
     (centerX,
      centerY) = self.findActualCenter(0, 0, self.adjustedXForCenter,
                                       self.adjustedYForCenter, self.carYaw)
     self.carRayForward.setOrigin(5, 10, 5)
     self.carCollision = CollisionNode("groundCollision")
     self.carCollision.addSolid(self.carRay)
     self.carCollision.setIntoCollideMask(CollideMask.allOff())
     self.carCollisionNode = self.car.attachNewNode(self.carCollision)
     self.carCollideTrav.addCollider(self.carCollisionNode, self.handler)
     self.carCollideTrav.addCollider(self.carForwardCollisionNode,
                                     self.carForwardHandler)
     self.carForwardCollisionNode.show()
Exemple #11
0
    def __init__(self, cr):
        DistributedObject.__init__(self, cr)
        #self.model = loader.loadModel('environment')
        #self.model.setZ(0)
        #self.builder = Builder(self, "map.txt", "development")

        plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
        cnode = CollisionNode('cnode')
        cnode.setIntoCollideMask(BitMask32.bit(1))
        cnode.setFromCollideMask(BitMask32.bit(1))
        cnode.addSolid(plane)
        self.planeNP = self.model.attachNewNode(cnode)
        self.planeNP.show()

        # Setup a traverser for the picking collisions
        self.picker = CollisionTraverser()
        # Setup mouse ray
        self.pq = CollisionHandlerQueue()
        # Create a collision Node
        pickerNode = CollisionNode('MouseRay')
        # set the nodes collision bitmask
        pickerNode.setFromCollideMask(BitMask32.bit(1))
        # create a collision ray
        self.pickerRay = CollisionRay()
        # add the ray as a solid to the picker node
        pickerNode.addSolid(self.pickerRay)
        # create a nodepath with the camera to the picker node
        self.pickerNP = base.camera.attachNewNode(pickerNode)
        # add the nodepath to the base traverser
        self.picker.addCollider(self.pickerNP, self.pq)

        print "model loaded"
        #TODO: check how to load multiple levels and set players in specific levels!
        self.accept("mouse1", self.mouseClick)
    def __init__(self, services: Services, base: ShowBase, map_data: MapData, name: Optional[str] = None):
        self.__services = services
        self.__services.ev_manager.register_listener(self)
        self.__base = base
        self.__name = name if name is not None else (map_data.name + "_picker")
        self.__map = map_data
        self.__data = map_data.data

        # collision traverser & queue
        self.__ctrav = CollisionTraverser(self.name + '_ctrav')
        self.__cqueue = CollisionHandlerQueue()

        # collision boxes
        self.__cn = CollisionNode(self.name + '_cn')
        self.__cn.set_collide_mask(MapPicker.COLLIDE_MASK)
        self.__cnp = self.__map.root.attach_new_node(self.__cn)
        self.__ctrav.add_collider(self.__cnp, self.__cqueue)
        self.__points = []

        z_offset = 1 if self.__map.dim == 3 else self.__map.depth
        for idx in np.ndindex(self.__data.shape):
            if bool(self.__data[idx] & MapData.TRAVERSABLE_MASK):
                p = Point(*idx)
                self.__points.append(p)
                idx = self.__cn.add_solid(CollisionBox(idx, Point3(p.x+1, p.y+1, p.z-z_offset)))
                assert idx == (len(self.__points) - 1)

        # mouse picker
        self.__pn = CollisionNode(self.name + '_pray')
        self.__pnp = self.__base.cam.attach_new_node(self.__pn)
        self.__pn.set_from_collide_mask(MapPicker.COLLIDE_MASK)

        self.__pray = CollisionRay()
        self.__pn.add_solid(self.__pray)
        self.__ctrav.add_collider(self.__pnp, self.__cqueue)
    def __init__(self):
        GameObject.__init__(self,
                            Vec3(0, 0, 0),
                            "Models/PandaChan/act_p3d_chan",
                              {
                                  "stand" : "Models/PandaChan/a_p3d_chan_idle",
                                  "walk" : "Models/PandaChan/a_p3d_chan_run"
                              },
                            5,
                            10,
                            "player")
        self.actor.getChild(0).setH(180)

        mask = BitMask32()
        mask.setBit(1)

        self.collider.node().setIntoCollideMask(mask)

        mask = BitMask32()
        mask.setBit(1)

        self.collider.node().setFromCollideMask(mask)

        base.pusher.addCollider(self.collider, self.actor)
        base.cTrav.addCollider(self.collider, base.pusher)

        self.lastMousePos = Vec2(0, 0)

        self.groundPlane = Plane(Vec3(0, 0, 1), Vec3(0, 0, 0))

        self.ray = CollisionRay(0, 0, 0, 0, 1, 0)

        rayNode = CollisionNode("playerRay")
        rayNode.addSolid(self.ray)

        mask = BitMask32()

        mask.setBit(2)
        rayNode.setFromCollideMask(mask)

        mask = BitMask32()
        rayNode.setIntoCollideMask(mask)

        self.rayNodePath = render.attachNewNode(rayNode)
        self.rayQueue = CollisionHandlerQueue()

        base.cTrav.addCollider(self.rayNodePath, self.rayQueue)

        self.beamModel = loader.loadModel("Models/Misc/bambooLaser")
        self.beamModel.reparentTo(self.actor)
        self.beamModel.setZ(1.5)
        self.beamModel.setLightOff()
        self.beamModel.hide()

        self.damagePerSecond = -5.0

        self.yVector = Vec2(0, 1)

        self.actor.loop("stand")
 def initializeSmartCameraCollisions(self):
     if self.initialized:
         return
     self.ccTrav = CollisionTraverser('LocalAvatar.ccTrav')
     self.ccLine = CollisionSegment(0.0, 0.0, 0.0, 1.0, 0.0, 0.0)
     self.ccLineNode = CollisionNode('ccLineNode')
     self.ccLineNode.addSolid(self.ccLine)
     self.ccLineNodePath = base.localAvatar.attachNewNode(self.ccLineNode)
     self.ccLineBitMask = CIGlobals.CameraBitmask
     self.ccLineNode.setFromCollideMask(self.ccLineBitMask)
     self.ccLineNode.setIntoCollideMask(BitMask32.allOff())
     self.camCollisionQueue = CollisionHandlerQueue()
     self.ccTrav.addCollider(self.ccLineNodePath, self.camCollisionQueue)
     self.ccSphere = CollisionSphere(0, 0, 0, 1)
     self.ccSphereNode = CollisionNode('ccSphereNode')
     self.ccSphereNode.addSolid(self.ccSphere)
     self.ccSphereNodePath = base.camera.attachNewNode(self.ccSphereNode)
     self.ccSphereNode.setFromCollideMask(CIGlobals.CameraBitmask)
     self.ccSphereNode.setIntoCollideMask(BitMask32.allOff())
     self.camPusher = CollisionHandlerPusher()
     self.camPusher.addCollider(self.ccSphereNodePath, base.camera)
     self.camPusher.setCenter(base.localAvatar)
     self.ccPusherTrav = CollisionTraverser('LocalAvatar.ccPusherTrav')
     self.ccSphere2 = self.ccSphere
     self.ccSphereNode2 = CollisionNode('ccSphereNode2')
     self.ccSphereNode2.addSolid(self.ccSphere2)
     self.ccSphereNodePath2 = base.camera.attachNewNode(self.ccSphereNode2)
     self.ccSphereNode2.setFromCollideMask(CIGlobals.CameraBitmask)
     self.ccSphereNode2.setIntoCollideMask(BitMask32.allOff())
     self.camPusher2 = CollisionHandlerPusher()
     self.ccPusherTrav.addCollider(self.ccSphereNodePath2, self.camPusher2)
     self.camPusher2.addCollider(self.ccSphereNodePath2, base.camera)
     self.camPusher2.setCenter(base.localAvatar)
     self.camFloorRayNode = base.localAvatar.attachNewNode('camFloorRayNode')
     self.ccRay = CollisionRay(0.0, 0.0, 0.0, 0.0, 0.0, -1.0)
     self.ccRayNode = CollisionNode('ccRayNode')
     self.ccRayNode.addSolid(self.ccRay)
     self.ccRayNodePath = self.camFloorRayNode.attachNewNode(self.ccRayNode)
     self.ccRayBitMask = CIGlobals.FloorBitmask
     self.ccRayNode.setFromCollideMask(self.ccRayBitMask)
     self.ccRayNode.setIntoCollideMask(BitMask32.allOff())
     self.ccTravFloor = CollisionTraverser('LocalAvatar.ccTravFloor')
     self.camFloorCollisionQueue = CollisionHandlerQueue()
     self.ccTravFloor.addCollider(self.ccRayNodePath, self.camFloorCollisionQueue)
     self.ccTravOnFloor = CollisionTraverser('LocalAvatar.ccTravOnFloor')
     self.ccRay2 = CollisionRay(0.0, 0.0, 0.0, 0.0, 0.0, -1.0)
     self.ccRay2Node = CollisionNode('ccRay2Node')
     self.ccRay2Node.addSolid(self.ccRay2)
     self.ccRay2NodePath = self.camFloorRayNode.attachNewNode(self.ccRay2Node)
     self.ccRay2BitMask = CIGlobals.FloorBitmask
     self.ccRay2Node.setFromCollideMask(self.ccRay2BitMask)
     self.ccRay2Node.setIntoCollideMask(BitMask32.allOff())
     self.ccRay2MoveNodePath = hidden.attachNewNode('ccRay2MoveNode')
     self.camFloorCollisionBroadcaster = CollisionHandlerFloor()
     self.camFloorCollisionBroadcaster.setInPattern('on-floor')
     self.camFloorCollisionBroadcaster.setOutPattern('off-floor')
     self.camFloorCollisionBroadcaster.addCollider(self.ccRay2NodePath, self.ccRay2MoveNodePath)
     self.cTrav.addCollider(self.ccRay2NodePath, self.camFloorCollisionBroadcaster)
     self.initialized = True
class DPlayer(DistributedObject):
    def __init__(self, cr):
        DistributedObject.__init__(self, cr)
        self.name = "Player"
        self.piece = None

        self.pickerQueue = CollisionHandlerQueue()
        self.pickerRay = CollisionRay()
        pickerNode = CollisionNode('mouseRay')
        pickerNode.setFromCollideMask(BitMask32(0x80))
        pickerNode.addSolid(self.pickerRay)
        self.pickerNP = base.camera.attachNewNode(pickerNode)
        base.cTrav.addCollider(self.pickerNP, self.pickerQueue)

        self.accept("mouse1", self.checkClick)

    def delete(self):
        """Cleanup just before the object gets deleted"""
        self.ignoreAll()
        base.cTrav.removeCollider(self.pickerNP)
        self.pickerNP.removeNode()

        if self.piece is not None:
            self.piece.sendDeleteMsg()

        DistributedObject.delete(self)

    def d_getName(self):
        self.sendUpdate("requestName")

    def setName(self, newName):
        self.name = newName
        base.messenger.send(self.cr.uniqueName("setPlayerName"), [self.name])

    def setPiece(self, piece):
        self.piece = piece

    def checkClick(self):
        """Check if the player has clicked on a field and send a request to move
        to it to the server."""
        if base.mouseWatcherNode.hasMouse():
            mpos = base.mouseWatcherNode.getMouse()
            self.pickerRay.setFromLens(base.camNode, mpos.x, mpos.y)

            base.cTrav.traverse(render)
            if self.pickerQueue.getNumEntries() > 0:
                self.pickerQueue.sortEntries()
                pickedObj = self.pickerQueue.getEntry(0).getIntoNodePath()
                fieldName = pickedObj.getParent().getName()
                base.messenger.send("requestMoveToField", [fieldName])

    def d_updateInventory(self):
        self.sendUpdate("updateInventory")

    def doUpdateInventory(self, level, inventoryDir):
        base.messenger.send("updateInventory", [level, inventoryDir])

    def doUpdatePotions(self, numPotions):
        base.messenger.send("updateHealthPotions", [numPotions])
Exemple #16
0
	def setupMouseCollision(self):
		self.mouseTraverser = CollisionTraverser()
		self.mouseCollisionQueue    = CollisionHandlerQueue()
		self.mouseRay = CollisionRay()
		self.mouseRay.setOrigin(self.pandaScene.camera.getPos(self.pandaScene.render))
		self.mouseRay.setDirection(self.pandaScene.render.getRelativeVector(self.pandaScene.camera, Vec3(0,1,0)))
		self.mouseNode = CollisionNode('mouseRay')
		self.mouseNode.addSolid(self.mouseRay)
		self.mouseNodePath = self.pandaScene.camera.attachNewNode(self.mouseNode)
		self.mouseNode.setFromCollideMask(GeomNode.getDefaultCollideMask())
		self.mouseTraverser.addCollider(self.mouseNodePath, self.mouseCollisionQueue)
Exemple #17
0
 def __init__(self, camera, level):
     self.camera = camera
     self.level = level
     self.handler = CollisionHandlerQueue()
     self.traverser = CollisionTraverser('traverser')
     pickerNode = CollisionNode('mouseRay')
     pickerNP = self.camera.attachNewNode(pickerNode)
     pickerNode.setFromCollideMask(GeomNode.getDefaultCollideMask())
     self.pickerRay = CollisionRay()
     pickerNode.addSolid(self.pickerRay)
     self.traverser.addCollider(pickerNP, self.handler)
Exemple #18
0
 def setup_interactiongeometries(self):
     """
     set up collision rays, spheres, and planes for mouse manipulation
     :return: None
     author: weiwei
     date: 20161110
     """
     # create a trackball ray and set its bitmask to 8
     # the trackball ray must be a subnode of cam since we will
     # transform the clicked point (in the view of the cam) to the world coordinate system
     # using the ray
     self.tracker_cn = CollisionNode("tracker")
     self.tracker_ray = CollisionRay()
     self.tracker_cn.addSolid(self.tracker_ray)
     self.tracker_cn.setFromCollideMask(BitMask32.bit(8))
     self.tracker_cn.setIntoCollideMask(BitMask32.allOff())
     self.tracker_np = self.base.cam.attachNewNode(self.tracker_cn)
     # create an inverted collision sphere and puts it into a collision node
     # its bitmask is set to 8, and it will be the only collidable object at bit 8
     self.trackball_cn = CollisionNode("trackball")
     self.trackball_cn.addSolid(
         CollisionSphere(self.lookatpos_pdv3[0], self.lookatpos_pdv3[1],
                         self.lookatpos_pdv3[2], self.camdist))
     self.trackball_cn.setFromCollideMask(BitMask32.allOff())
     self.trackball_cn.setIntoCollideMask(BitMask32.bit(8))
     self.trackball_np = self.base.render.attachNewNode(self.trackball_cn)
     # self.trackball_np.show()
     # This creates a collision plane for mouse track
     self.trackplane_cn = CollisionNode("trackplane")
     self.trackplane_cn.addSolid(
         CollisionPlane(
             Plane(
                 Point3(-self.base.cam.getMat().getRow3(1)),
                 Point3(self.lookatpos_pdv3[0], self.lookatpos_pdv3[1],
                        0.0))))
     self.trackplane_cn.setFromCollideMask(BitMask32.allOff())
     self.trackplane_cn.setIntoCollideMask(BitMask32.bit(8))
     self.trackplane_np = self.base.render.attachNewNode(self.trackplane_cn)
     # self.trackplane_np.show()
     # creates a traverser to do collision testing
     self.ctrav = CollisionTraverser()
     # creates a queue type handler to receive the collision event info
     self.chandler = CollisionHandlerQueue()
     # register the ray as a collider with the traverser,
     # and register the handler queue as the handler to be used for the collisions.
     self.ctrav.addCollider(self.tracker_np, self.chandler)
     # create a pickerray
     self.picker_cn = CollisionNode('picker')
     self.picker_ray = CollisionRay()
     self.picker_cn.addSolid(self.picker_ray)
     self.picker_cn.setFromCollideMask(BitMask32.bit(7))
     self.picker_cn.setIntoCollideMask(BitMask32.allOff())
     self.picker_np = self.base.cam.attachNewNode(self.picker_cn)
     self.ctrav.addCollider(self.picker_np, self.chandler)
Exemple #19
0
 def createMouseCollisions(self):
     # Fire the portals
     firingNode = CollisionNode('mouseRay')
     firingNP = self.base.camera.attachNewNode(firingNode)
     firingNode.setFromCollideMask(COLLISIONMASKS['geometry'])
     firingNode.setIntoCollideMask(BitMask32.allOff())
     firingRay = CollisionRay()
     firingRay.setOrigin(0,0,0)
     firingRay.setDirection(0,1,0)
     firingNode.addSolid(firingRay)
     self.firingHandler = CollisionHandlerQueue()
     self.base.cTrav.addCollider(firingNP, self.firingHandler)
Exemple #20
0
  def initMouseToWorldCoordConversion(self):
    self.picker = CollisionTraverser()
    self.pq = CollisionHandlerQueue()

    self.pickerNode = CollisionNode('mouseRay')
    self.pickerNP = self.showBase.camera.attachNewNode(self.pickerNode)

    self.pickerNode.setFromCollideMask(BitMask32.bit(1))
    self.pickerRay = CollisionRay()

    self.pickerNode.addSolid(self.pickerRay)
    self.picker.addCollider(self.pickerNP, self.pq)
Exemple #21
0
class Mouse(DirectObject):
    def __init__(self, levelNP):
        self.setCursor()
        # store the nodepath to the level collisions
        # will be used to check for intersections with the mouse ray
        self.levelNP = levelNP
        # Setup a traverser for the picking collisions
        self.picker = CollisionTraverser()
        # Setup mouse ray
        self.pq = CollisionHandlerQueue()
        # Create a collision Node
        pickerNode = CollisionNode('MouseRay')
        # set the nodes collision bitmask
        pickerNode.setFromCollideMask(BitMask32.bit(1))#GeomNode.getDefaultCollideMask())
        # create a collision ray
        self.pickerRay = CollisionRay()
        # add the ray as a solid to the picker node
        pickerNode.addSolid(self.pickerRay)
        # create a nodepath with the camera to the picker node
        self.pickerNP = base.camera.attachNewNode(pickerNode)
        # add the nodepath to the base traverser
        self.picker.addCollider(self.pickerNP, self.pq)

    def setCursor(self):
        base.win.clearRejectedProperties()
        props = WindowProperties()
        if sys.platform.startswith('linux'):
            props.setCursorFilename("./assets/cursor.x11")
        else:
            props.setCursorFilename("./assets/cursor.ico")
        base.win.requestProperties(props)

    def getMousePos(self):
        # check if we have a mouse on the window
        if base.mouseWatcherNode.hasMouse():
            # get the mouse position on the screen
            mpos = base.mouseWatcherNode.getMouse()
            # set the ray's position
            self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())
            # Now call the traverse function to let the traverser check for collisions
            # with the added colliders and the levelNP
            self.picker.traverse(self.levelNP)
            # check if we have a collision
            if self.pq.getNumEntries() > 0:
                # sort the entries to get the closest first
                self.pq.sortEntries()
                # This is the point at where the mouse ray and the level plane intersect
                hitPos = self.pq.getEntry(0).getSurfacePoint(render)
                return hitPos
        return Point3(0, 0, 0)

        task.cont
Exemple #22
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.traverser = CollisionTraverser()
        self.queue = CollisionHandlerQueue()

        self.picker_ray = CollisionRay()
        self.picker_node = CollisionNode('mouse ray')
        self.picker_node.add_solid(self.picker_ray)
        self.picker_node.set_from_collide_mask(MOUSEOVER_MASK)
        self.picker_node.set_into_collide_mask(0x0)
        self.picker_node_path = NodePath(self.picker_node)

        self.traverser.add_collider(self.picker_node_path, self.queue)
Exemple #23
0
 def __init__(self):
     super().__init__(
         name = 'raycaster',
         eternal = True
         )
     self._picker = CollisionTraverser()  # Make a traverser
     self._pq = CollisionHandlerQueue()  # Make a handler
     self._pickerNode = CollisionNode('raycaster')
     self._pickerNP = self.attach_new_node(self._pickerNode)
     self._collision_ray = CollisionRay()  # Make our ray
     self._pickerNode.addSolid(self._collision_ray)
     self._picker.addCollider(self._pickerNP, self._pq)
     self._pickerNP.show()
Exemple #24
0
    def create(self):
        self.mPickerTraverser = CollisionTraverser()
        self.mCollisionQue = CollisionHandlerQueue()

        self.mPickRay = CollisionRay()
        self.mPickRay.setOrigin(base.camera.getPos(base.render))
        self.mPickRay.setDirection(
            base.render.getRelativeVector(base.camera, Vec3(0, 1, 0)))

        #create our collison Node to hold the ray
        self.mPickNode = CollisionNode(self.nodeName)
        self.mPickNode.addSolid(self.mPickRay)

        #Attach that node to the camera since the ray will need to be positioned
        #relative to it, returns a new nodepath
        #well use the default geometry mask
        #this is inefficent but its for mouse picking only

        self.mPickNP = base.camera.attachNewNode(self.mPickNode)

        #we'll use what panda calls the "from" node.  This is reall a silly convention
        #but from nodes are nodes that are active, while into nodes are usually passive environments
        #this isnt a hard rule, but following it usually reduces processing

        #Everything to be picked will use bit 1. This way if we were doing other
        #collision we could seperate it, we use bitmasks to determine what we check other objects against
        #if they dont have a bitmask for bit 1 well skip them!
        self.mPickNode.setFromCollideMask(BitMask32(1))

        #Register the ray as something that can cause collisions
        self.mPickerTraverser.addCollider(self.mPickNP, self.mCollisionQue)

        #Setup 2D picker
        self.mPickerTraverser2D = CollisionTraverser()
        self.mCollisionQue2D = CollisionHandlerQueue()

        self.mPickNode2D = CollisionNode('2D PickNode')
        self.mPickNode2D.setFromCollideMask(BitMask32(1))
        self.mPickNode2D.setIntoCollideMask(BitMask32.allOff())

        self.mPick2DNP = base.camera2d.attachNewNode(self.mPickNode2D)

        self.mPickRay2D = CollisionRay()
        self.mPickNode2D.addSolid(self.mPickRay2D)

        self.mPickerTraverser2D.addCollider(self.mPick2DNP,
                                            self.mCollisionQue2D)

        if self.showCollisions:
            self.mPickerTraverser.showCollisions(base.render)
            self.mPickerTraverser2D.showCollisions(base.aspect2d)
Exemple #25
0
    def __init__(self, camera_gear, tq_render, mousewatchernode,
                 dragAndDropObjectsManager):
        """ """
        self.dragAndDropObjectsManager = dragAndDropObjectsManager

        # -- things that are needed to do picking from different camera orientations
        self.camera_gear = camera_gear  # e.g. the orbiter class is a camera_gear
        self.tq_render = tq_render

        self.mouse_watcher_node = mousewatchernode

        # -- things that are needed for collision detection by picking a 3d object
        self.pick_traverser = CollisionTraverser()
        self.collision_queue = CollisionHandlerQueue()

        # ---- build the CollisionRay
        self.pick_collision_ray = CollisionRay(
        )  # the pick ray is apparently a 'Solid'

        # -- a ray is a half-inifinite straight line
        # it is supposed to shoot out orthogonally to the view plane and hit an object
        self.pick_collision_ray.setOrigin(
            self.camera_gear.p3d_camera.getPos(
                self.tq_render.get_p3d_nodepath()))

        # -- TODO: update this every time the orbiter camera position changes
        # first, transform the (0,1,0) vector into render's coordinate system

        self.pick_collision_ray.setDirection(
            engine.tq_graphics_basics.tq_render.getRelativeVector(
                camera, Vec3(0, 1, 0)))

        # ---- build the CollisionNode
        self.pick_collision_node = CollisionNode('pick_collision_ray')
        self.pick_collision_node.addSolid(
            self.pick_collision_ray)  # the pick ray is actually a 3d object

        # attach the CollisionNode to the camera (not the CollisionRay)
        self.pick_collision_node_nodepath = self.camera_gear.p3d_camera.attachNewNode(
            self.pick_collision_node)

        # set a collide mask to the pick_collision_node, 2 objects that should be able to collide must have the same collide mask!
        self.pick_collision_node.setFromCollideMask(
            GeomNode.getDefaultCollideMask()
            # DragDropObject.dragMask
        )  # set bit 20 (Default) to the ray

        # add the ray as sth. that can cause collisions, and tell it to fill up our collision queue object when traversing and detecting
        self.pick_traverser.addCollider(self.pick_collision_node_nodepath,
                                        self.collision_queue)
Exemple #26
0
    def __setup_collision(self):
        #Colisao
        self.ralphGroundRay = CollisionRay()
        self.ralphGroundRay.setOrigin(0, 0, 5)
        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.__modelo.attachNewNode(
            self.ralphGroundCol)
        self.ralphGroundHandler = CollisionHandlerQueue()

        base.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)
Exemple #27
0
class Mouse(object):
    def __init__(self, base):
        self.base = base
        if settings.mouse_over:
            taskMgr.add(self.mouse_task, 'mouse-task')
        self.picker = CollisionTraverser()
        self.pq = CollisionHandlerQueue()
        self.pickerNode = CollisionNode('mouseRay')
        self.pickerNP = self.base.cam.attachNewNode(self.pickerNode)
        self.pickerNode.setFromCollideMask(
            CollisionNode.getDefaultCollideMask()
            | GeomNode.getDefaultCollideMask())
        self.pickerRay = CollisionRay()
        self.pickerNode.addSolid(self.pickerRay)
        self.picker.addCollider(self.pickerNP, self.pq)
        #self.picker.showCollisions(render)
        self.over = None

    def find_over(self):
        over = None
        if self.base.mouseWatcherNode.hasMouse():
            mpos = self.base.mouseWatcherNode.getMouse()
            self.pickerRay.setFromLens(self.base.camNode, mpos.getX(),
                                       mpos.getY())
            self.picker.traverse(render)
            if self.pq.getNumEntries() > 0:
                self.pq.sortEntries()
                np = self.pq.getEntry(0).getIntoNodePath().findNetPythonTag(
                    'owner')
                owner = np.getPythonTag('owner')
                over = owner
                np = self.pq.getEntry(0).getIntoNodePath().findNetPythonTag(
                    'patch')
                if np is not None:
                    self.patch = np.getPythonTag('patch')
                else:
                    self.patch = None
        return over

    def get_over(self):
        if settings.mouse_over:
            over = self.over
        else:
            over = self.find_over()
        return over

    def mouse_task(self, task):
        if self.mouseWatcherNode.hasMouse():
            self.over = self.find_over()
        return Task.cont
    def __init__(self, cr):
        DistributedObject.__init__(self, cr)
        self.name = "Player"
        self.piece = None

        self.pickerQueue = CollisionHandlerQueue()
        self.pickerRay = CollisionRay()
        pickerNode = CollisionNode('mouseRay')
        pickerNode.setFromCollideMask(BitMask32(0x80))
        pickerNode.addSolid(self.pickerRay)
        self.pickerNP = base.camera.attachNewNode(pickerNode)
        base.cTrav.addCollider(self.pickerNP, self.pickerQueue)

        self.accept("mouse1", self.checkClick)
Exemple #29
0
    def create(self):
        self.mPickerTraverser = CollisionTraverser()
        self.mCollisionQue = CollisionHandlerQueue()

        self.mPickRay = CollisionRay()
        self.mPickRay.setOrigin(base.camera.getPos(base.render))
        self.mPickRay.setDirection(base.render.getRelativeVector(base.camera, Vec3(0, 1, 0)))

        # create our collison Node to hold the ray
        self.mPickNode = CollisionNode(self.nodeName)
        self.mPickNode.addSolid(self.mPickRay)

        # Attach that node to the camera since the ray will need to be positioned
        # relative to it, returns a new nodepath
        # well use the default geometry mask
        # this is inefficent but its for mouse picking only

        self.mPickNP = base.camera.attachNewNode(self.mPickNode)

        # we'll use what panda calls the "from" node.  This is reall a silly convention
        # but from nodes are nodes that are active, while into nodes are usually passive environments
        # this isnt a hard rule, but following it usually reduces processing

        # Everything to be picked will use bit 1. This way if we were doing other
        # collision we could seperate it, we use bitmasks to determine what we check other objects against
        # if they dont have a bitmask for bit 1 well skip them!
        self.mPickNode.setFromCollideMask(BitMask32(1))

        # Register the ray as something that can cause collisions
        self.mPickerTraverser.addCollider(self.mPickNP, self.mCollisionQue)

        # Setup 2D picker
        self.mPickerTraverser2D = CollisionTraverser()
        self.mCollisionQue2D = CollisionHandlerQueue()

        self.mPickNode2D = CollisionNode("2D PickNode")
        self.mPickNode2D.setFromCollideMask(BitMask32(1))
        self.mPickNode2D.setIntoCollideMask(BitMask32.allOff())

        self.mPick2DNP = base.camera2d.attachNewNode(self.mPickNode2D)

        self.mPickRay2D = CollisionRay()
        self.mPickNode2D.addSolid(self.mPickRay2D)

        self.mPickerTraverser2D.addCollider(self.mPick2DNP, self.mCollisionQue2D)

        if self.showCollisions:
            self.mPickerTraverser.showCollisions(base.render)
            self.mPickerTraverser2D.showCollisions(base.aspect2d)
Exemple #30
0
 def __init__(self, game):
     self.game = game
     self.cells = {}
     self.cells_by_collider = {}
     self.cell_picker_world = NodePath('cell_picker_world')
     self.ray = CollisionRay()
     self.ray.setDirection(LVector3.down())
     cnode = CollisionNode('cell_raycast_cnode')
     self.ray_nodepath = self.cell_picker_world.attachNewNode(cnode)
     self.ray_nodepath.node().addSolid(self.ray)
     self.ray_nodepath.node().setIntoCollideMask(
         0)  # not for colliding into
     self.ray_nodepath.node().setFromCollideMask(1)
     self.traverser = CollisionTraverser('traverser')
     self.last_known_cell = None
Exemple #31
0
class PlayerObject():
	def __init__(self, render, player):
		self.username = player.getUsername()
		self.isMoving = False
		self.render = render

		self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}

		self.actor = Actor("models/ralph", {"run":"models/ralph-run", "walk":"models/ralph-walk"})
		self.actor.reparentTo(render)
		self.actor.setScale(0.2)
		self.actor.setPos(player.getX(), player.getY(), player.getZ())
		self.actor.setH(player.getH())

		self.cTrav = CollisionTraverser()
		self.GroundRay = CollisionRay()
		self.GroundRay.setOrigin(0,0,1000)
		self.GroundRay.setDirection(0,0,-1)
		self.GroundCol = CollisionNode('actorRay')
		self.GroundCol.addSolid(self.GroundRay)
		self.GroundCol.setFromCollideMask(BitMask32.bit(0))
		self.GroundCol.setIntoCollideMask(BitMask32.allOff())
		self.GroundColNp = self.actor.attachNewNode(self.GroundCol)
		self.GroundHandler = CollisionHandlerQueue()
		self.cTrav.addCollider(self.GroundColNp, self.GroundHandler)

# 	def getUsername(self):
# 		return self.username
	
	def getActor(self):
		return self.actor
	
	def setPos(self, x, y, z):
		self.actor.setPos(x, y, z)
		
	def setH(self, h):
		self.actor.setH(h)

	def move(self, isActorMove):
		if isActorMove == "True":
			if self.isMoving is False:
				self.actor.loop("run")
				self.isMoving = True
		else:
			if self.isMoving:
				self.actor.stop()
				self.actor.pose("walk",5)
				self.isMoving = False
Exemple #32
0
    def __init__(self, render, objid, start_pos, gameclient):
        self.client = gameclient
        self.id = objid
        self.motion_controller = None
        self.is_player = False
        
        # state  management
        self.isAnimating = False
        self.state = state.IDLE
        
        self.render = render    # scene graph root
        
        #  create the panda3d actor: just load a default model for now
        self.actor = Actor("models/ralph",
                            {"run":"models/ralph-run",
                             "walk":"models/ralph-walk"})
                             
        self.actor.reparentTo(render)
        self.actor.setScale(.2)
        self.actor.setPos(start_pos)

        # prepare collision handling
        self.cTrav = CollisionTraverser()
        self.GroundRay = CollisionRay()
        self.GroundRay.setOrigin(0,0,1000)
        self.GroundRay.setDirection(0,0,-1)
        self.GroundCol = CollisionNode('actorRay')
        self.GroundCol.addSolid(self.GroundRay)
        self.GroundCol.setFromCollideMask(BitMask32.bit(0))
        self.GroundCol.setIntoCollideMask(BitMask32.allOff())
        self.GroundColNp = self.actor.attachNewNode(self.GroundCol)
        self.GroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.GroundColNp, self.GroundHandler)
Exemple #33
0
    def __init__(self, nick):
        self.player = player.Player(nick=nick)
        self.controller = controller.ClientController(self.player)
        self.handgui = hand.HandGUI(self.player.hand)
        camera.setPos(0, -20, 0)
        self.accept("turn_time_changed", self.update_turn_time)
        self.turn_timer = TurnTimer()

        # Mouse detection:
        base.cTrav = CollisionTraverser()
        self.mouse_ray_handler = CollisionHandlerQueue()
        mouse_ray_node = CollisionNode('mouse_ray')
        mouse_ray_np = camera.attachNewNode(mouse_ray_node)
        mouse_ray_node.setFromCollideMask(GeomNode.getDefaultCollideMask())
        mouse_ray_node.setIntoCollideMask(0)
        self.mouse_ray = CollisionRay()
        mouse_ray_node.addSolid(self.mouse_ray)
        base.cTrav.addCollider(mouse_ray_np, self.mouse_ray_handler)

        self.mouse_overed_entry = None

        self.accept("mouse_enter", self.enlarge_entry)
        self.accept("mouse_leave", self.shrink_entry)

        self.accept("p-up", self.change_card_picture)

        taskMgr.doMethodLater(0.1, self.check_mouse_over, "check_mouse_over")
Exemple #34
0
    def __init__(self):
        #selection detection
        self.picker = CollisionTraverser()
        self.pq = CollisionHandlerQueue()
        self.pickerNode = CollisionNode('mouseRay')
        self.pickerNP = camera.attachNewNode(self.pickerNode)
        #self.pickerNode.setFromCollideMask(GeomNode.getDefaultCollideMask()) #TODO WOW geometry collision is SUPER slow...
        self.pickerNode.setFromCollideMask(BitMask32.bit(BITMASK_COLL_CLICK))
        #render.find('**selectable').node().setIntoCollideMask(BitMask32.bit(1))
        self.pickerRay = CollisionRay()
        self.pickerNode.addSolid(self.pickerRay)
        self.picker.addCollider(self.pickerNP, self.pq)
        #self.picker.showCollisions(render)

        #box selection detection HINT: start with drawing the 2d thing yo!

        self.__shift__ = False
        self.accept("shift", self.shiftOn)
        self.accept("shift-up", self.shiftOff)

        self.__ctrl__ = False
        self.accept("control", self.ctrlOn)
        self.accept("control-up", self.ctrlOff)

        #mouse handling
        self.accept("mouse1", self.clickHandler)
        self.accept("shift-mouse1", self.clickHandler)
        self.accept("mouse1-up", self.releaseHandler)

        #dragging
        self.dragTask = taskMgr.add(self.dragTask, 'dragTask')
Exemple #35
0
	def __init__(self, render, player):
		self.username = player.getUsername()
		self.isMoving = False
		self.render = render

		self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}

		#self.actor = Actor("models/ralph", {"run":"models/ralph-run", "walk":"models/ralph-walk"})
		self.actor = Actor("models/panda-model",
                                {"walk": "models/panda-walk4"})
		self.actor.reparentTo(render)
		self.actor.setScale(0.002, 0.002, 0.002)
		self.actor.setPos(player.getX(), player.getY(), player.getZ())
		self.actor.setH(player.getH())	
		
		#self.actor.loop("walk")
		
		self.cTrav = CollisionTraverser()
		self.GroundRay = CollisionRay()
		self.GroundRay.setOrigin(0,0,1000)
		self.GroundRay.setDirection(0,0,-1)
		self.GroundCol = CollisionNode('actorRay')
		self.GroundCol.addSolid(self.GroundRay)
		self.GroundCol.setFromCollideMask(BitMask32.bit(0))
		self.GroundCol.setIntoCollideMask(BitMask32.allOff())
		self.GroundColNp = self.actor.attachNewNode(self.GroundCol)
		self.GroundHandler = CollisionHandlerQueue()
		self.cTrav.addCollider(self.GroundColNp, self.GroundHandler)
Exemple #36
0
 def __init__(self,gmap,gaming_zone):
    DirectObject.__init__(self)
    #gaming zone (used for mouse movement), as a tools.Rectangle
    self.gaming_zone=gaming_zone
    #actual camera node
    self.p3dcam=base.camera
    #what the cam is oriented to
    self._target=base.render.attachNewNode('GaminCam.target')
    #range=[0,1] between min and max closeness to ground
    self.level=.7
    #
    #keys_down acts as a pool containing keys (+mouse buttons) currently down
    self.keys_down=[]
    update_list.append(self.update)
    #setup for mouse picking
    picker_node=CollisionNode('gcam_to_mouse_ray')#general collision node
    picker_node.setFromCollideMask(GeomNode.getDefaultCollideMask())
    self.picker_ray=CollisionRay()#solid ray to attach to coll node
    picker_node.addSolid(self.picker_ray)
    self.picker_np=self.p3dcam.attachNewNode(picker_node)#attach this node to gcam
    self.collision_queue=CollisionHandlerQueue()#stores collisions
    self.collision_traverser=CollisionTraverser('gcam_traverser')#actual computer
    self.collision_traverser.addCollider(self.picker_np,self.collision_queue)
    base.cTrav=self.collision_traverser
    self.gmap=gmap
    #stack of states (state=pos+zoom)
    self.states_stack=[]
    #enable the cam to move according to keyboard and mouse
    self.move_enabled=True
    def __init__(self, cr):
        DistributedObject.__init__(self, cr)
        #self.model = loader.loadModel('environment')
        #self.model.setZ(0)
        #self.builder = Builder(self, "map.txt", "development")


        plane = CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0)))
        cnode = CollisionNode('cnode')
        cnode.setIntoCollideMask(BitMask32.bit(1))
        cnode.setFromCollideMask(BitMask32.bit(1))
        cnode.addSolid(plane)
        self.planeNP = self.model.attachNewNode(cnode)
        self.planeNP.show()

        # Setup a traverser for the picking collisions
        self.picker = CollisionTraverser()
        # Setup mouse ray
        self.pq = CollisionHandlerQueue()
        # Create a collision Node
        pickerNode = CollisionNode('MouseRay')
        # set the nodes collision bitmask
        pickerNode.setFromCollideMask(BitMask32.bit(1))
        # create a collision ray
        self.pickerRay = CollisionRay()
        # add the ray as a solid to the picker node
        pickerNode.addSolid(self.pickerRay)
        # create a nodepath with the camera to the picker node
        self.pickerNP = base.camera.attachNewNode(pickerNode)
        # add the nodepath to the base traverser
        self.picker.addCollider(self.pickerNP, self.pq)

        print "model loaded"
        #TODO: check how to load multiple levels and set players in specific levels!
        self.accept("mouse1", self.mouseClick)
 def start(self):
     self.fullyChargedSound = base.loadSfx('phase_4/audio/sfx/MG_pairing_match.mp3')
     self.rechargeSound = base.loadSfx('phase_4/audio/sfx/MG_sfx_travel_game_blue_arrow.mp3')
     self.batteryFrame = DirectFrame(parent=base.a2dBottomRight, pos=(-0.2, 0, 0.1), scale=(0.8, 0, 1))
     self.batteryBg = OnscreenImage(image='phase_4/maps/battery_charge_frame.png', parent=self.batteryFrame)
     self.batteryBg.setTransparency(1)
     self.batteryBg.setX(0.03)
     self.batteryBg.setScale(0.17, 0, 0.05)
     self.batteryBar = DirectWaitBar(value=0, range=5, barColor=(1, 1, 1, 1), relief=None, scale=(0.12, 0.0, 0.3), parent=self.batteryFrame)
     self.cameraFocus = loader.loadModel('phase_4/models/minigames/photo_game_viewfinder.bam')
     self.cameraFocus.reparentTo(base.aspect2d)
     self.focusCollHandler = CollisionHandlerEvent()
     self.focusCollHandler.setInPattern('%fn-into')
     self.focusCollHandler.setOutPattern('%fn-out')
     self.focusCollNode = CollisionNode('mouseRay')
     self.focusCollNP = base.camera.attachNewNode(self.focusCollNode)
     self.focusCollNode.setCollideMask(BitMask32(0))
     self.focusCollNode.setFromCollideMask(CIGlobals.WallBitmask)
     self.focusRay = CollisionRay()
     self.focusRay.setFromLens(base.camNode, 0.0, 0.0)
     self.focusCollNode.addSolid(self.focusRay)
     base.cTrav.addCollider(self.focusCollNP, self.focusCollHandler)
     base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, 0.0, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed)
     FirstPerson.start(self)
     return
Exemple #39
0
 def __init__(self, base):
     self.base = base
     if settings.mouse_over:
         taskMgr.add(self.mouse_task, 'mouse-task')
     self.picker = CollisionTraverser()
     self.pq = CollisionHandlerQueue()
     self.pickerNode = CollisionNode('mouseRay')
     self.pickerNP = self.base.cam.attachNewNode(self.pickerNode)
     self.pickerNode.setFromCollideMask(
         CollisionNode.getDefaultCollideMask()
         | GeomNode.getDefaultCollideMask())
     self.pickerRay = CollisionRay()
     self.pickerNode.addSolid(self.pickerRay)
     self.picker.addCollider(self.pickerNP, self.pq)
     #self.picker.showCollisions(render)
     self.over = None
Exemple #40
0
 def init_picker(self):
     # Collision traverser
     self.traverser = CollisionTraverser("traverser")
     # Collision handler
     self.handler = CollisionHandlerQueue()
     # Initialize and set up picker ray node and NodePath
     self.picker = CollisionNode("mouse_ray")
     self.pickerNP = self.camera.attachNewNode(self.picker)
     self.picker.setFromCollideMask(GeomNode.getDefaultCollideMask())
     self.picker_ray = CollisionRay()
     self.picker.addSolid(self.picker_ray)
     self.traverser.addCollider(self.pickerNP, self.handler)
     mark_color = (1, 1, 1, 0.3)
     self.base_mark = self.create_mark(color=mark_color)
     connector_color = (1, 1, 1, 1)
     self.base_connector = self.create_connector(color=connector_color)
Exemple #41
0
    def player_init(self):
        self.base.pusher.addCollider(self.collider, self.actor)
        self.base.cTrav.addCollider(self.collider, self.base.pusher)
        self.collider.setPythonTag("player", self)

        self.score = 0
        self.score_string = str(self.score)

        # self.base.camLens.setFov(150) #----------------------------------------------
        # self.base.camLens.setFov(5)

        self.textObject = OnscreenText(text='Score:' + self.score_string,
                                       pos=(-1.15, -0.95),
                                       scale=0.1)

        self.ray = CollisionRay(0, 0, 0, 0, -1, 0)

        rayNode = CollisionNode("playerRay")
        rayNode.addSolid(self.ray)

        self.rayNodePath = self.actor.attachNewNode(rayNode)
        self.rayQueue = CollisionHandlerQueue()

        self.base.cTrav.addCollider(self.rayNodePath, self.rayQueue)

        # self.damagePerSecond = -5.0
        self.beamModel = self.base.loader.loadModel("models/frowney")
        self.beamModel.reparentTo(self.actor)
        self.beamModel.setZ(10)

        self.beamModel.setLightOff()
        self.beamModel.hide()
Exemple #42
0
 def generate(self):
     data = CIGlobals.SuitBodyData[self.SUIT]
     type = data[0]
     team = data[1]
     self.team = team
     self.level = 12
     self.suit = type
     Suit.generate(self, SuitBank.MrHollywood, 0, hideFirst=False)
     self.suit = type
     base.taskMgr.add(self.__viewDistance, self.viewDistanceTaskName)
     self.setPythonTag('guard', self)
     self.eyeLight = Spotlight('eyes')
     self.eyeLens = PerspectiveLens()
     self.eyeLens.setMinFov(90.0 / (4.0 / 3.0))
     self.eyeLight.setLens(self.eyeLens)
     self.eyeNode = self.headModel.attachNewNode(self.eyeLight)
     self.eyeNode.setZ(-5)
     self.eyeNode.setY(-4.5)
     self.trav = CollisionTraverser(self.uniqueName('eyeTrav'))
     ray = CollisionRay(0, 0, 0, 0, 1, 0)
     rayNode = CollisionNode('ToonFPS.rayNode')
     rayNode.addSolid(ray)
     rayNode.setFromCollideMask(CGG.GuardBitmask | CIGlobals.WallBitmask)
     rayNode.setIntoCollideMask(BitMask32.allOff())
     self.rayNP = base.camera.attachNewNode(rayNode)
     self.rayNP.setZ(3)
     self.queue = CollisionHandlerQueue()
     self.trav.addCollider(self.rayNP, self.queue)
     self.trav.addCollider(self.gameWorld.mg.avatarBody, self.queue)
     self.request('Guard')
Exemple #43
0
    def __init__(self):

        colliderNode = CollisionNode(self.colliderName + "WallCollider")
        colliderNode.addSolid(CollisionSphere(0, 0, 0, 0.3))
        self.collider = self.root.attachNewNode(colliderNode)
        self.collider.setPythonTag(TAG_OWNER, self)
        colliderNode.setFromCollideMask(MASK_WALLS)
        colliderNode.setIntoCollideMask(0)

        self.collider.setZ(self.height * 0.5)

        base.pusher.addCollider(self.collider, self.root)
        base.traverser.addCollider(self.collider, base.pusher)

        self.ray = CollisionRay(0, 0, self.height / 2, 0, 0, -1)

        rayNode = CollisionNode(self.colliderName + "Ray")
        rayNode.addSolid(self.ray)

        rayNode.setFromCollideMask(MASK_FLOORS)
        rayNode.setIntoCollideMask(0)

        self.rayNodePath = self.root.attachNewNode(rayNode)
        self.rayQueue = CollisionHandlerQueue()

        base.traverser.addCollider(self.rayNodePath, self.rayQueue)
Exemple #44
0
 def placeItem(self, item):
     # Add ground collision detector to the health item
     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(0))
     self.collectGroundCol.setIntoCollideMask(BitMask32.allOff())
     self.collectGroundColNp = item.attachNewNode(self.collectGroundCol)
     self.collectGroundHandler = CollisionHandlerQueue()
     base.cTrav.addCollider(self.collectGroundColNp, self.collectGroundHandler)
     
     placed = False;
     while placed == False:
         # re-randomize position
         item.setPos(-random.randint(0,140),-random.randint(0,40),0)
         
         base.cTrav.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()+1)
             placed = True
             
     # remove placement collider
     self.collectGroundColNp.removeNode()
Exemple #45
0
    def setupMouseCollision(self):
        """ """
        # Since we are using collision detection to do picking, we set it up
        # any other collision detection system with a traverser and a handler
        self.mPickerTraverser = CollisionTraverser()  # Make a traverser
        self.mCollisionQue = CollisionHandlerQueue()

        # create a collision solid ray to detect against
        self.mPickRay = CollisionRay()
        self.mPickRay.setOrigin(self.camera.getPos(self.render))
        self.mPickRay.setDirection(render.getRelativeVector(camera, Vec3(0, 1, 0)))

        # create our collison Node to hold the ray
        self.mPickNode = CollisionNode("pickRay")
        self.mPickNode.addSolid(self.mPickRay)

        # Attach that node to the camera since the ray will need to be positioned
        # relative to it, returns a new nodepath
        # well use the default geometry mask
        # this is inefficent but its for mouse picking only

        self.mPickNP = self.camera.attachNewNode(self.mPickNode)

        # well use what panda calls the "from" node.  This is reall a silly convention
        # but from nodes are nodes that are active, while into nodes are usually passive environments
        # this isnt a hard rule, but following it usually reduces processing

        # Everything to be picked will use bit 1. This way if we were doing other
        # collision we could seperate it, we use bitmasks to determine what we check other objects against
        # if they dont have a bitmask for bit 1 well skip them!
        self.mPickNode.setFromCollideMask(GeomNode.getDefaultCollideMask())

        # Register the ray as something that can cause collisions
        self.mPickerTraverser.addCollider(self.mPickNP, self.mCollisionQue)
Exemple #46
0
 def startSeeking(self):
     if not self.avatar:
         return
     self.cleanupShadow()
     self.buildShadow()
     scale = self.dropShadow.getScale()
     if scale < 1.0:
         self.maxDistance += 40
     x, y, z = self.avatar.getPos(render)
     self.dropShadow.reparentTo(render)
     self.dropShadow.setPos(x, y + 5, z + 2)
     self.cameraNode = CollisionNode('coll_camera')
     self.cameraNode.setFromCollideMask(CIGlobals.WallBitmask)
     self.cameraRay = CollisionRay()
     self.cameraNode.addSolid(self.cameraRay)
     self.cameraNP = camera.attachNewNode(self.cameraNode)
     base.cTrav.addCollider(self.cameraNP, CollisionHandlerQueue())
     if not self.legacyMode:
         shadowNode = CollisionNode('coll_shadow')
         self.shadowRay = CollisionRay(0, 0, 6, 0, 0, -1)
         shadowNode.addSolid(self.shadowRay)
         shadowNode.setFromCollideMask(CIGlobals.FloorBitmask)
         self.shadowNP = self.dropShadow.attachNewNode(shadowNode)
         base.cTrav.addCollider(self.shadowNP, self.collHdlFl)
     base.taskMgr.add(self.__moveShadow, self.moveShadowTaskName)
     self.avatar.acceptOnce('mouse1', self.locationChosen)
 def loadCursorPicker(self):
     self.picker = CollisionTraverser()
     self.pq     = CollisionHandlerQueue()
     self.pickerNode = CollisionNode('mouseRay')
     self.pickerNP = camera.attachNewNode(self.pickerNode)
     self.pickerNode.setFromCollideMask(BitMask32.bit(1))
     self.pickerRay = CollisionRay()
     self.pickerNode.addSolid(self.pickerRay)
     self.picker.addCollider(self.pickerNP, self.pq)
Exemple #48
0
    def setUpCamera(self):
        """ puts camera behind the player in third person """
        
        
        # Set up the camera
        # Adding the camera to actor is a simple way to keep the camera locked
        # in behind actor regardless of actor's movement.
        base.camera.reparentTo(self.actor)
        # We don't actually want to point the camera at actors's feet.
        # This value will serve as a vertical offset so we can look over the actor
        self.cameraTargetHeight = 0.5
        # How far should the camera be from the actor
        self.cameraDistance = 10
        # Initialize the pitch of the camera
        self.cameraPitch = 45
        
        # The mouse moves rotates the camera so lets get rid of the cursor
        props = WindowProperties()
        props.setCursorHidden(True)
        base.win.requestProperties(props)
        
        #set up FOV
        pl =  base.cam.node().getLens()
        pl.setFov(70)
        base.cam.node().setLens(pl)
        
        # 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.
        """
TODO::        This will need to be changed to bullet
        """
        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)
        
        # We will detect anything obstructing the camera's view of the player

        self.cameraRay = CollisionSegment((0,0,self.cameraTargetHeight),(0,5,5))
        self.cameraCol = CollisionNode('cameraRay')
        self.cameraCol.addSolid(self.cameraRay)
        self.cameraCol.setFromCollideMask(BitMask32.bit(0))
        self.cameraCol.setIntoCollideMask(BitMask32.allOff())
        self.cameraColNp = self.actor.attachNewNode(self.cameraCol)
        self.cameraColHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.cameraColNp, self.cameraColHandler)
Exemple #49
0
 def setupPicker(self):
     self.pickerTrav = CollisionTraverser('LT.pickerTrav')
     self.pickerRay = CollisionRay()
     rayNode = CollisionNode('LT.pickerNode')
     rayNode.addSolid(self.pickerRay)
     rayNode.setCollideMask(BitMask32(0))
     rayNode.setFromCollideMask(CIGlobals.WallBitmask)
     self.pickerRayNode = base.camera.attachNewNode(rayNode)
     self.pickerHandler = CollisionHandlerQueue()
     self.pickerTrav.addCollider(self.pickerRayNode, self.pickerHandler)
    def _get_collision(self, node, debug=False):
        mx = self.mouseWatcherNode.getMouseX()
        my = self.mouseWatcherNode.getMouseY()
        if debug:
            print "mouse:", (mx, my)

        # get the origin and direction of the ray extending from the
        # camera to the mouse pointer
        cm = np.array(self.cam.getNetTransform().getMat())
        cr = CollisionRay()
        cr.setFromLens(self.cam.node(), (mx, my))
        cp = np.hstack([cr.getOrigin(), 1])
        cd = np.hstack([cr.getDirection(), 0])
        cp = np.dot(cm.T, cp)[:3]
        cd = np.dot(cm.T, cd)[:3]
        if cd[2] > -1:
            cd[2] = -1
        if debug:
            print "direction:", cd
            print "origin:", cp

        # point on the plane, z-axis
        pz = node.getPos(self.render)[2]
        sz = node.getScale(self.render)[2] / 2.0
        p0 = np.array([0, 0, pz + sz])
        if debug:
            print "p0:", p0

        # this is the intersection equation that we want to solve,
        # where s is the point on the line that intersects
        #     e_z(cp + s*cd - p0) = 0
        s = (p0[2] - cp[2]) / cd[2]
        if debug:
            print "s:", s

        # transform the collision point from line coordinates to world
        # coordinates
        cv = cp + s * cd
        if debug:
            print "collision:", cv

        return cv
Exemple #51
0
 def addCollisionOnMainChar(self):
     self.mainCharGroundRay = CollisionRay()
     self.mainCharGroundRay.setOrigin(0,0,1000)
     self.mainCharGroundRay.setDirection(0,0,-1)
     self.mainCharGroundCol = CollisionNode('mainChar')
     self.mainCharGroundCol.addSolid(self.mainCharGroundRay)
     self.mainCharGroundCol.setFromCollideMask(BitMask32.bit(0))
     self.mainCharGroundCol.setIntoCollideMask(BitMask32.allOff())
     self.mainCharGroundColNp = self.mainChar.attachNewNode(self.mainCharGroundCol)
     self.mainCharGroundHandler = CollisionHandlerQueue()
     self.cTrav.addCollider(self.mainCharGroundColNp, self.mainCharGroundHandler)
Exemple #52
0
 def addCollisionOnCam(self):
     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)
Exemple #53
0
 def setupPicking(self):
     self.picker = CollisionTraverser()
     self.pq     = CollisionHandlerQueue()
     self.pickerNode = CollisionNode('mouseRay')
     self.pickerNP = camera.attachNewNode(self.pickerNode)
     self.pickerNode.setFromCollideMask(BitMask32.bit(1))
     self.pickerRay = CollisionRay()
     self.pickerNode.addSolid(self.pickerRay)
     self.picker.addCollider(self.pickerNP, self.pq)
     
     self.targetRoot = render.attachNewNode('targetRoot')
     self.mouseTask = taskMgr.add(self.mouseTask, 'mouseTask')
Exemple #54
0
    def collisionInit(self):
        # Kollisionserkennung, um auf dem Boden zu laufen. Der Collisionray
        # erkennt die Hoehe des Gelaendes und wenn ein Objekt da ist, wird 
        # die Bewegung als illegal gewertet.

        self.cTrav = CollisionTraverser()

        self.spielerGroundRay = CollisionRay()
        self.spielerGroundRay.setOrigin(0,0,1000)
        self.spielerGroundRay.setDirection(0,0,-1)
        self.spielerGroundCol = CollisionNode('spielerRay')
        self.spielerGroundCol.addSolid(self.spielerGroundRay)
        self.spielerGroundCol.setFromCollideMask(BitMask32.bit(0))
        self.spielerGroundCol.setIntoCollideMask(BitMask32.allOff())
        self.spielerGroundColNp = self.spieler.actor.attachNewNode(self.spielerGroundCol)
        self.spielerGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.spielerGroundColNp, self.spielerGroundHandler)

        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)

        self.gegnerGroundRay = CollisionRay()
        self.gegnerGroundRay.setOrigin(0,0,1000)
        self.gegnerGroundRay.setDirection(0,0,-1)
        self.gegnerGroundCol = CollisionNode('gegnerRay')
        self.gegnerGroundCol.addSolid(self.gegnerGroundRay)
        self.gegnerGroundCol.setFromCollideMask(BitMask32.bit(0))
        self.gegnerGroundCol.setIntoCollideMask(BitMask32.allOff())
        self.gegnerGroundColNp = self.gegner.actor.attachNewNode(self.gegnerGroundCol)
        self.gegnerGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.gegnerGroundColNp, self.gegnerGroundHandler)
Exemple #55
0
 def __setup_collision(self):
     #Colisao        
     self.ralphGroundRay = CollisionRay()
     self.ralphGroundRay.setOrigin(0,0,5)
     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.__modelo.attachNewNode(self.ralphGroundCol)
     self.ralphGroundHandler = CollisionHandlerQueue()
             
     base.cTrav.addCollider(self.ralphGroundColNp, self.ralphGroundHandler)
 def __init__(self, game):
     self.game = game
     self.cells = {}
     self.cells_by_collider = {}
     self.cell_picker_world = NodePath('cell_picker_world')
     self.ray = CollisionRay()
     self.ray.setDirection(LVector3.down())
     cnode = CollisionNode('cell_raycast_cnode')
     self.ray_nodepath = self.cell_picker_world.attachNewNode(cnode)
     self.ray_nodepath.node().addSolid(self.ray)
     self.ray_nodepath.node().setIntoCollideMask(0) # not for colliding into
     self.ray_nodepath.node().setFromCollideMask(1)
     self.traverser = CollisionTraverser('traverser')
     self.last_known_cell = None
Exemple #57
0
 def init_picker(self):
     # Collision traverser
     self.traverser = CollisionTraverser("traverser")
     # Collision handler
     self.handler = CollisionHandlerQueue()
     # Initialize and set up picker ray node and NodePath
     self.picker = CollisionNode("mouse_ray")
     self.pickerNP = self.camera.attachNewNode(self.picker)
     self.picker.setFromCollideMask(GeomNode.getDefaultCollideMask())
     self.picker_ray = CollisionRay()
     self.picker.addSolid(self.picker_ray)
     self.traverser.addCollider(self.pickerNP, self.handler)
     mark_color = (1, 1, 1, 0.3)
     self.base_mark = self.create_mark(color=mark_color)
     connector_color = (1, 1, 1, 1)
     self.base_connector = self.create_connector(color=connector_color)
    def __init__(self):
        ShowBase.__init__(self)

        # Create a traverser and a handler
        self.cTrav = CollisionTraverser()
        self.cQueue = CollisionHandlerQueue()

        # Create the collision node that will store the collision
        # ray solid 
        self.pickerNode = CollisionNode('mouseRay')
        # Set bitmask for efficiency, only hit from objects with same mask
        self.pickerNode.setFromCollideMask(BitMask32.bit(1))
        # Attach collision node to camera, since that is the source
        self.pickerNP = camera.attachNewNode(self.pickerNode)

        # Add collision solid(ray) to collision node
        self.pickerRay = CollisionRay()
        self.pickerNode.addSolid(self.pickerRay)
        # Add collidable node(pickerNP) to the traverser
        # Collisions detected when traversed will go to cQueue
        self.cTrav.addCollider(self.pickerNP, self.cQueue)

        # Create visible sphere
        self.tmpSphere = self.loader.loadModel("models/misc/sphere")
        self.tmpSphere.reparentTo(self.render)
        self.tmpSphere.setColor(1, 1, 1, 1)
        self.tmpSphere.setPos(0, 100, 0)
        
        # Create collision sphere and attach to tmpSphere
        cSphere = CollisionSphere(0, 0, 0, 3)
        cnodePath = self.tmpSphere.attachNewNode(CollisionNode('cnode'))
        # Add collision solid(sphere) to collision node
        # Because tmpSphere/cSphere is child of render, which we traverse
        # later, it becomes a from collider automatically, we don't
        # need to addCollider since that is only for from collision nodes
        cnodePath.node().addSolid(cSphere)
        # Set bitmask to match the from collisionnode mask for efficiency
        cnodePath.setCollideMask(BitMask32.bit(1))
        # Show the collision sphere visibly, for debugging.
        cnodePath.show()
        # Set a custom tag on the collision node which becomes available
        # inside the collision event stored in the collision handler
        cnodePath.setTag('someTag', '1')

        # Add task to run every frame - set collision solid(ray)
        # to start at the current camera position, 
        self.mouseTask = taskMgr.add(self.mouseTask, 'mouseTask')
	def setupMouseCollision(self):

		self.mClicker = CollisionTraverser()          
		self.mCollisionQue    = CollisionHandlerQueue()

		self.mClickRay = CollisionRay()
		self.mClickRay.setOrigin(self.camera.getPos(self.render))
		self.mClickRay.setDirection(render.getRelativeVector(camera, Vec3(0,1,0)))

		self.mClickNode = CollisionNode('clickRay')
		self.mClickNode.addSolid(self.mClickRay)

		self.mClickNP = self.camera.attachNewNode(self.mClickNode)

		self.mClickNode.setFromCollideMask(GeomNode.getDefaultCollideMask())

		self.mClicker.addCollider(self.mClickNP, self.mCollisionQue)