Exemplo n.º 1
0
    def __init__(self, rootParent=None):

        self.btnEndTurn = DirectButton(
            borderWidth=(0.0, 0.0),
            frameColor=(0.8, 0.8, 0.8, 0.0),
            frameSize=(-3.0, 3.0, -1.0, 1.0),
            hpr=LVecBase3f(0, 0, 0),
            image='./assets/Turn/EndTurn.png',
            pos=LPoint3f(0, 0, 0.1),
            relief=1,
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='End Turn',
            image_scale=LVecBase3f(3, 0, 1),
            image_pos=LPoint3f(0, 0, 0),
            text_align=TextNode.A_center,
            text_scale=(1.0, 1.0),
            text_pos=(0.0, -0.3),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=rootParent,
            command=base.messenger.send,
            extraArgs=["endTurn"],
            pressEffect=0,
        )
        self.btnEndTurn.setTransparency(1)
    def camera_move(self, task):
        """
        Moves the camera about the quadcopter
        """

        keys_vs_moves = {'k': i,
                         'h': -i,
                         'i': j,
                         'y': -j,
                         'u': k,
                         'j': -k
                         }

        mat = np.array(self.cam.getMat())[0:3, 0:3]
        move_total = LPoint3f(0, 0, 0)

        for key, move in keys_vs_moves.items():
            pressed_key = self.mouseWatcherNode.is_button_down(KeyboardButton.asciiKey(key))
            if pressed_key:
                move = LPoint3f(move)
                move_total += move

        # if any([abs(coordinate) > 0 for coordinate in move_total]):
        # ROTATE COORDINATE SYSTEM (TO CAMERA)
        move_total = LPoint3f(*tuple(np.dot(mat.T, np.array(move_total))))
        proportionality_constant = 0.05
        cam_pos = self.cam.getPos() + move_total * proportionality_constant
        self.cam.setPos(cam_pos)
        self.cam.lookAt(self.quad_model)

        return task.cont
Exemplo n.º 3
0
 def setWalkable(self, value):
     if value == False:
         self.collisionTube = CollisionBox(LPoint3f(0,0,0),LPoint3f(1,1,1))
         
         self.collisionNode = CollisionNode('unwalkable')
         self.collisionNode.addSolid(self.collisionTube)
         self.collisionNodeNp = self.groundnode.attachNewNode(self.collisionNode)
Exemplo n.º 4
0
    def __init__(self, rootParent=None):

        self.overlay = DirectFrame(
            frameColor=(1.0, 1.0, 1.0, 0.0),
            frameSize=(-1, 1, -1, 1),
            hpr=LVecBase3f(0, 0, 0),
            image='chapter4/overlay.png',
            pos=LPoint3f(0, 0, 0),
            sortOrder=200,
            image_scale=LVecBase3f(0.8, 1, 0.8),
            image_pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.overlay.setTransparency(1)

        self.newspaper = DirectFrame(
            frameColor=(1.0, 1.0, 1.0, 0.0),
            frameSize=(-1, 1, -1, 1),
            hpr=LVecBase3f(0, 0, 0),
            image='chapter4/newspaperA.png',
            pos=LPoint3f(0, 0, 0),
            sortOrder=200,
            image_scale=LVecBase3f(0.5, 1, 0.5),
            image_pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.newspaper.setTransparency(1)
Exemplo n.º 5
0
    def __init__(self, rootParent=None):

        self.frmMain = DirectFrame(
            frameColor=(0.0, 0.0, 0.0, 0.5),
            frameSize=(-1, 1, -1, 1),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.frmMain.setTransparency(0)

        self.lblVictory = DirectLabel(
            frameColor=(0.0, 0.0, 0.0, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0),
            scale=LVecBase3f(0.2, 0.2, 0.2),
            text='Won Fight',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.lblVictory.setTransparency(0)
Exemplo n.º 6
0
    def __init__(self, rootParent=None):

        self.frmMain = DirectFrame(
            frameColor=(1, 1, 1, 1),
            frameSize=(-1, 1, -1, 1),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.frmMain.setTransparency(0)

        self.waitbar = DirectWaitBar(
            barColor=(0.0, 0.0, 1.0, 1.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0),
            state='normal',
            text='0%',
            value=50.0,
            text_align=TextNode.A_center,
            text_scale=(0.1, 0.1),
            text_pos=(0, -0.025),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.waitbar.setTransparency(0)
Exemplo n.º 7
0
    def _movePickedBody(self, task):
        # handle picked body if any
        if self.pickedBody and self.dragging:
            # check mouse position
            if self.mouseWatcher.has_mouse():
                # Get to and from pos in camera coordinates
                pMouse = self.mouseWatcher.get_mouse()
                #
                pFrom = LPoint3f()
                pTo = LPoint3f()
                if self.camLens.extrude(pMouse, pFrom, pTo):
                    # Transform to global coordinates
                    rayFromWorld = self.render.get_relative_point(
                        self.camera, pFrom)
                    rayToWorld = self.render.get_relative_point(
                        self.camera, pTo)
                    # keep it at the same picking distance
                    direction = (rayToWorld - rayFromWorld).normalized()
                    direction *= self.oldPickingDist
                    self.pickedBody.set_pos(
                        self.render, rayFromWorld + direction + self.deltaDist)
                    #self.pickedBody.reparentTo(np)
                    #self.pickedBody.setMass(10.0)

        #
        return task.cont
def getCollisionEntryFromCamera():
    """throws a ray and returns the first collision entry or nullptr"""

    global app
    # get nav mesh manager
    navMeshMgr = RNNavMeshManager.get_global_ptr()
    # get the mouse watcher
    mwatcher = app.mouseWatcherNode
    if mwatcher.has_mouse():
        # Get to and from pos in camera coordinates
        pMouse = mwatcher.get_mouse()
        #
        pFrom, pTo = (LPoint3f(), LPoint3f())
        if app.camLens.extrude(pMouse, pFrom, pTo):
            # Transform to global coordinates
            pFrom = app.render.get_relative_point(app.cam, pFrom)
            pTo = app.render.get_relative_point(app.cam, pTo)
            direction = (pTo - pFrom).normalized()
            navMeshMgr.get_collision_ray().set_origin(pFrom)
            navMeshMgr.get_collision_ray().set_direction(direction)
            navMeshMgr.get_collision_traverser().traverse(app.render)
            # check collisions
            if navMeshMgr.get_collision_handler().get_num_entries() > 0:
                # Get the closest entry
                navMeshMgr.get_collision_handler().sort_entries()
                return navMeshMgr.get_collision_handler().get_entry(0)
    return None
Exemplo n.º 9
0
    def __init__(self, rootParent=None):
        
        self.frmMain = DirectFrame(
            frameColor=(0.25, 0.25, 0.25, 1.0),
            frameSize=(0.0, 2.0, -0.1, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.frmMain.setTransparency(0)

        self.btnLeave = DirectButton(
            hpr=LVecBase3f(0, 0, 0),
            pad=(0.1, 0.1),
            pos=LPoint3f(0.115, 0, -0.075),
            relief=1,
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Leave',
            text_align=TextNode.A_center,
            text_scale=(0.75, 0.75),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
            command=base.messenger.send,
            extraArgs=["leaveRoom"],
        )
        self.btnLeave.setTransparency(0)

        self.lblPlayerName = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.55, 0, -0.075),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Label',
            text_align=TextNode.A_left,
            text_scale=(0.75, 0.75),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0.8, 0.8, 0.8, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.lblPlayerName.setTransparency(0)

        self.pg1983 = DirectLabel(
            frameColor=(0.8, 0.8, 0.8, 0.0),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0.42, 0, -0.075),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Name:',
            text_align=TextNode.A_center,
            text_scale=(0.75, 0.75),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0.6, 0.6, 0.6, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.pg1983.setTransparency(0)
Exemplo n.º 10
0
    def _pickBody(self, event):
        # handle body picking
        if event == self.pickKeyOn:
            # check mouse position
            if self.mouseWatcher.has_mouse():
                # Get to and from pos in camera coordinates
                pMouse = self.mouseWatcher.get_mouse()
                #
                pFrom = LPoint3f()
                pTo = LPoint3f()
                if self.camLens.extrude(pMouse, pFrom, pTo):
                    # Transform to global coordinates
                    rayFromWorld = self.render.get_relative_point(
                        self.camera, pFrom)
                    rayToWorld = self.render.get_relative_point(
                        self.camera, pTo)
                    # cast a ray to detect a body
                    # traverse downward starting at rayOrigin
                    self.pickerRay.set_direction(rayToWorld - rayFromWorld)
                    self.pickerRay.set_origin(rayFromWorld)
                    self.cTrav.traverse(self.render)
                    if self.collisionHandler.get_num_entries() > 0:
                        self.collisionHandler.sort_entries()
                        entry0 = self.collisionHandler.get_entry(0)
                        hitPos = entry0.get_surface_point(self.render)
                        # get the first parent with name
                        pickedObject = entry0.get_into_node_path()
                        while not pickedObject.has_tag(self.pickableTag):
                            pickedObject = pickedObject.getParent()
                            if not pickedObject:
                                return
                            if pickedObject == self.render:
                                return
                        #
                        self.pickedBody = pickedObject

                        self.oldPickingDist = (hitPos - rayFromWorld).length()
                        self.deltaDist = (
                            self.pickedBody.get_pos(self.render) - hitPos)
                        print(self.pickedBody.get_name(), hitPos)
                        if not self.dragging:
                            self.dragging = True
                            # create the task for updating picked body motion
                            self.updateTask = self.taskMgr.add(
                                self._movePickedBody, "_movePickedBody")
                            # set sort/priority
                            self.updateTask.set_sort(0)
                            self.updateTask.set_priority(0)
        else:

            if self.dragging:
                # remove pick body motion update task
                self.taskMgr.remove("_movePickedBody")
                self.updateTask = None
                self.dragging = False
                self.pickedBody = None
Exemplo n.º 11
0
 def traverse(self, nodePath, dnaStorage):
     node = dnaStorage.findNode(self.code)
     if node is None:
         raise DNAError.DNAError('DNAWall code ' + self.code +
                                 ' not found in DNAStorage')
     node = node.copyTo(nodePath)
     pos = LPoint3f(self.pos)
     pos.setZ(DNAFlatBuilding.DNAFlatBuilding.currentWallHeight)
     scale = LPoint3f(self.scale)
     scale.setZ(self.height)
     node.setPosHprScale(pos, self.hpr, scale)
     node.setColor(self.color)
     self.traverseChildren(node, dnaStorage)
     DNAFlatBuilding.DNAFlatBuilding.currentWallHeight += self.height
Exemplo n.º 12
0
    def __init__(self, rootParent=None):

        self.volume = DirectSlider(
            pos=LPoint3f(0.2, 0, 0.325),
            text='Volume',
            text_pos=(-1.05, -0.02),
            text_fg=(1, 1, 1, 1),
            text_scale=0.1,
            text_align=TextNode.ARight,
            parent=rootParent,
            command=base.messenger.send,
            extraArgs=["volumeChange"],
        )
        self.volume.setTransparency(0)

        self.audioMute = DirectCheckButton(
            frameSize=(-2.925000047683716, 3.024999713897705, -0.225,
                       0.8250000238418579),
            pos=LPoint3f(0, 0, 0),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Mute',
            parent=rootParent,
            command=self.toggleMute,
        )
        self.audioMute.setTransparency(0)

        self.btnBack = DirectButton(
            frameSize=(-1.5249999523162843, 1.6499999523162843,
                       -0.21250001192092896, 0.8250000238418579),
            pos=LPoint3f(0, 0, -0.575),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Back',
            parent=rootParent,
            command=base.messenger.send,
            extraArgs=["optionBack"],
            pressEffect=1,
        )
        self.btnBack.setTransparency(0)

        self.fullscreen = DirectCheckButton(
            frameSize=(-3.35, 2.6, -0.213, 0.825),
            pos=LPoint3f(0.045, 0, -0.175),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Fullscreen',
            parent=rootParent,
            command=self.toggleFullscreen,
        )
        self.fullscreen.setTransparency(0)
 def __createFile(self, filename, xPos, zPos):
     name = filename
     if len(filename) > 10:
         name = ""
         for i in range(min(math.ceil(len(filename)/10), 4)):
             name += filename[i*10:i*10+10]+"\n"
         name = name[:-1]
         if math.ceil(len(filename)/10) > 4:
             name += "..."
     btn = DirectButton(
         parent=self.container.getCanvas(),
         image="icons/File.png",
         image_scale=35,
         relief=1,
         frameColor = (
             (0.9, 0.9, 0.9, 0), # Normal
             (0.95, 0.95, 1, 1), # Click
             (0.9, 0.9, 1, 1), # Hover
             (0.5, 0.5, 0.5, 1)), # Disabled
         frameSize=(-40, 40, -40, 40),
         pos=LPoint3f(xPos, 0, zPos),
         text = name,
         text_scale=12,
         text_pos=(0,-40),
         command=self.txtFileName.set,
         extraArgs=[filename]
     )
     btn.bind(DGG.MWDOWN, self.scroll, [0.01])
     btn.bind(DGG.MWUP, self.scroll, [-0.01])
     btn.setTransparency(TransparencyAttrib.M_multisample)
Exemplo n.º 14
0
def __createFolder(self, entry, xPos, zPos):
    name = entry.name
    if len(entry.name) > 10:
        name = ""
        for i in range(max(math.ceil(len(entry.name) / 10), 4)):
            name += entry.name[i * 10:i * 10 + 10] + "\n"
        name = name[:-1]
        if math.ceil(len(entry.name) / 10) > 4:
            name += "..."
    btn = DirectButton(parent=self.container.getCanvas(),
                       image=loader.load_texture(f"{self.iconDir}/Folder.png",
                                                 loaderOptions=self.imageOpts),
                       image_scale=35,
                       relief=1,
                       frameColor=self.theme.folder_background,
                       frameSize=(-40, 40, -40, 40),
                       pos=LPoint3f(xPos, 0, zPos),
                       text=name,
                       text_scale=12,
                       text_pos=(0, -40),
                       text_fg=self.theme.default_text_color,
                       command=self.folderMoveIn,
                       extraArgs=[entry.path])
    btn.bind(DGG.MWDOWN, self.scroll, [0.01])
    btn.bind(DGG.MWUP, self.scroll, [-0.01])
    btn.setTransparency(TransparencyAttrib.M_multisample)
Exemplo n.º 15
0
def __createUnknown(self, filename, xPos, zPos):
    name = filename
    if len(filename) > 10:
        name = ""
        for i in range(math.ceil(len(filename) / 10)):
            name += filename[i * 10:i * 10 + 10] + "\n"
        name = name[:-1]
    lbl = DirectLabel(
        parent=self.container.getCanvas(),
        image=loader.load_texture(f"{self.iconDir}/File.png",
                                  loaderOptions=self.imageOpts),
        image_scale=35,
        image_color=self.theme.unknown_image_tint,
        relief=1,
        frameColor=(0.7, 0.7, 0.7, 0),
        frameSize=(-40, 40, -40, 40),
        pos=LPoint3f(xPos, 0, zPos),
        text=name,
        text_scale=12,
        text_pos=(0, -40),
        text_fg=self.theme.default_text_color,
    )
    lbl.bind(DGG.MWDOWN, self.scroll, [0.01])
    lbl.bind(DGG.MWUP, self.scroll, [-0.01])
    lbl.setTransparency(TransparencyAttrib.M_multisample)
Exemplo n.º 16
0
 def setupFlat(self, np, store, chr, wallCode):
     if self.name[:2] != 'tb':
         return
     ss = chr + 'b' + self.name[2:]
     node = np.attachNewNode(ss)
     scale = LPoint3f(self.scale)
     scale.setX(self.width)
     scale.setZ(DNAFlatBuilding.currentWallHeight)
     node.setZ(DNAFlatBuilding.currentWallHeight)
     node.setPosHprScale(self.pos, self.hpr, scale)
     numCodes = store.getNumCatalogCodes(wallCode)
     if not numCodes:
         return
     wallNode = store.findNode(
         store.getCatalogCode(wallCode, random.randint(0, numCodes - 1)))
     if wallNode.isEmpty():
         return
     wallNode.copyTo(node)
     if self.hasDoor:
         wallNp = node.find('wall_*')
         doorNp = store.findNode('suit_door').copyTo(wallNp)
         doorNp.setColor(0.2, 0.2, 0.2, 1)
         doorNp.setPosHprScale(0.5, 0, 0, 0, 0, 0, 1.0 / self.width, 0,
                               1.0 / DNAFlatBuilding.currentWallHeight)
         wallNp.setEffect(DecalEffect.make())
     node.flattenMedium()
     node.stash()
Exemplo n.º 17
0
    def processInput(self, dt):
        force = Vec3(0, 0, 0)
        throttleChange = 0.0
        #torque = Vec3(0, 0, 0)

        if inputState.isSet('forward'): force.setX(1)
        if inputState.isSet('reverse'): force.setX(-1)
        if inputState.isSet('left'): force.setY(-1)
        if inputState.isSet('right'): force.setY(1)
        if inputState.isSet('turnLeft'): throttleChange = -1.0
        if inputState.isSet('turnRight'): throttleChange = 1.0

        force *= -20.0 / 180.0 * math.pi
        self.throttle += throttleChange / 100.0
        self.throttle = min(max(self.throttle, 0), 1)
        thrust = Vec3(0, 0, self.throttle * 50)
        quatGimbal = self.rocketNozzle.getTransform(self.worldNP).getQuat()

        self.rocketNozzle.node().applyForce(quatGimbal.xform(thrust),
                                            LPoint3f(0, 0, 0))

        #torque *= 10.0

        #force = render.getRelativeVector(self.rocketNP, force)
        #torque = render.getRelativeVector(self.rocketNP, torque)

        self.rocketNozzle.node().setActive(True)
        self.rocketNP.node().setActive(True)
        #self.rocketNozzle.node().applyCentralForce(force)
        #self.rocketNozzle.node().applyTorque(torque)
        force = rot.from_euler('zyx', force).as_quat()

        self.cone.setMotorTarget(
            LQuaternionf(force[0], force[1], force[2], force[3]))
Exemplo n.º 18
0
def __createFolder(self, entry, xPos, zPos):
    name = entry.name

    btn = DirectButton(
        parent=self.container.getCanvas(),
        image=loader.load_texture(f"{self.iconDir}/Folder.png", loaderOptions=self.imageOpts),
        image_scale=16,
        image_pos=(16,0,0),
        relief=1,
        frameColor = self.theme.folder_background,
        frameSize=(0, self.screenWidthPxHalf*2, -16, 16),
        pos=LPoint3f(xPos, 0, zPos),
        text = name,
        text_scale=12,
        text_align=TextNode.ALeft,
        text_pos=(32,-4),
        text_fg=self.theme.default_text_color,
        command=self.folderMoveIn,
        extraArgs=[entry.path]
    )

    lblInfo = __createMIMEInfo(self, btn, entry, True)
    #lblSize = __createSizeInfo(self, btn, entry)

    btn.bind(DGG.MWDOWN, self.scroll, [0.01])
    btn.bind(DGG.MWUP, self.scroll, [-0.01])
    btn.setTransparency(TransparencyAttrib.M_multisample)
Exemplo n.º 19
0
 def __add_wheel(self, pos, is_front, node, radius, i):
     whl = self.vehicle.create_wheel()
     whl.set_node(node)
     whl.set_chassis_connection_point_cs(LPoint3f(*pos))
     whl.set_front_wheel(is_front)
     whl.set_wheel_direction_cs((0, 0, -1))
     whl.set_wheel_axle_cs((1, 0, 0))
     whl.set_wheel_radius(radius)
     whl.set_suspension_stiffness(self.suspension_stiffness[0])
     # default 5.88
     whl.set_wheels_damping_relaxation(self.wheels_damping_relaxation[0])
     # default .88
     whl.set_wheels_damping_compression(self.wheels_damping_compression[0])
     # default .83
     idx = 0 if is_front else 1
     whl.set_friction_slip(self.get_friction_static()[idx][0])
     # default 10.5
     # friction slip high -> more adherence
     whl.set_roll_influence(self.roll_influence[0])
     # low ->  more stability  # default .1
     whl.set_max_suspension_force(self.max_suspension_force)
     # default 6000
     whl.set_max_suspension_travel_cm(self.max_suspension_travel_cm)
     # default 500
     whl.set_skid_info(self.skid_info)  # default 0
     self.__whl2flytime[i] = 0
Exemplo n.º 20
0
    def load_simplex_dict(simp_index, golog_index):
        simp_dict = GSON[simp_index]
        if simp_index in handled: return handled[simp_index]
        faces = tuple([
            load_simplex_dict(face_key, golog_index)
            for face_key in simp_dict['faces']
        ])

        #handle math_data, if golog, change into an anctual golog
        if simp_dict['math_data_type'] == 'golog':
            golog_dict = {
                'golog': load_golog_dict(simp_dict['math_data']['golog']),
                'folder_path': simp_dict['math_data']['folder_path']
            }
            math_data = hcat.Math_Data(type='golog', math_data=golog_dict)
        else:
            math_data = hcat.Math_Data(type=simp_dict['math_data_type'],
                                       math_data=simp_dict['math_data'])

        G = load_golog_dict(golog_index)
        simp = G.add(faces,
                     label=simp_dict['meta']['label'],
                     math_data=math_data,
                     pos=LPoint3f(*GSON[golog_index]['pos_dict'][simp_index]))

        return simp
Exemplo n.º 21
0
        def __init__(self):
            ShowBase.__init__(self)
            self.disable_mouse()

            # need to migrate into gologToWindow
            base.accept("f5", sys.exit)
            base.accept("f6", sys.exit)

            G = golog(base, label='run')
            self.win.getDisplayRegion(1).setCamera(G.camera)
            a = G.add(0, label='1')
            b = G.add(0, label='2', pos=LPoint3f(0, 0, 10))
            f1 = G.add((b, a), label='(1,2)1', pos=LPoint3f(-2, 0, 0))
            f2 = G.add((b, a), label='(1,2)2', pos=LPoint3f(-1, 0, 0))
            f3 = G.add((b, a), label='(1,2)3', pos=LPoint3f(1, 0, 0))
            f4 = G.add((b, a), label='(1,2)4', pos=LPoint3f(2, 0, 0))
            G.Simplex_to_Graphics[a]._remove()
Exemplo n.º 22
0
    def takeoff(self):
        """
		Let the drones takeoff to one meter above their current position.
		"""
        for drone in self.drones:
            drone.in_flight = True
            pos = drone.get_pos()
            drone.set_target(LPoint3f(pos[0], pos[1], 1))
Exemplo n.º 23
0
    def stop_movement(self):
        """
		To stop all current movement just set the current position to the target position.
		"""
        self.stop_rotation()
        for drone in self.drones:
            pos = drone.get_pos()
            drone.set_target(LPoint3f(pos[0], pos[1], pos[2]))
    def traverse(self, np, store):
        DNAFlatBuilding.currentWallHeight = 0
        node = np.attachNewNode(self.name)
        internalNode = node.attachNewNode(self.getName() + '-internal')
        scale = LPoint3f(self.scale)
        scale.setX(self.width)
        internalNode.setScale(scale)
        node.setPosHpr(self.pos, self.hpr)

        for child in self.children:
            if isinstance(child, DNAWall.DNAWall):
                child.traverse(internalNode, store)
            else:
                child.traverse(node, store)

        if DNAFlatBuilding.currentWallHeight != 0:
            result = store.findNode("wall_camera_barrier")
            if result.isEmpty():
                raise DNAError.DNAError(
                    'DNAFlatBuilding requires that there is a wall_camera_barrier in storage'
                )

            cameraBarrier = result.copyTo(internalNode)
            cameraBarrier.setScale(1, 1, DNAFlatBuilding.currentWallHeight)
            self.setupSuitFlatBuilding(np, store)
            self.setupCogdoFlatBuilding(np, store)
            internalNode.flattenStrong()

            collNp = node.find("**/door_*/+CollisionNode")
            if not collNp.isEmpty():
                collNp.setName("KnockKnockDoorSphere_" +
                               store.getBlock(self.name))

            cameraBarrier.wrtReparentTo(np)
            wallCollection = internalNode.findAllMatches("wall*")
            doorCollection = internalNode.findAllMatches("**/door*")
            corniceCollection = internalNode.findAllMatches("**/cornice*_d")
            windowCollection = internalNode.findAllMatches("**/window*")
            wallHolder = node.attachNewNode("wall_holder")
            wallDecal = node.attachNewNode("wall_decal")
            wallCollection.reparentTo(wallHolder)
            doorCollection.reparentTo(wallDecal)
            corniceCollection.reparentTo(wallDecal)
            windowCollection.reparentTo(wallDecal)

            for i in range(wallHolder.getNumChildren()):
                child = wallHolder.getChild(i)
                child.clearTag("DNARoot")
                child.clearTag("DNACode")

            wallHolder.flattenStrong()
            wallDecal.flattenStrong()
            holderChild0 = wallHolder.getChild(0)
            wallDecal.getChildren().reparentTo(holderChild0)
            holderChild0.reparentTo(internalNode)
            holderChild0.setEffect(DecalEffect.make())
            wallHolder.removeNode()
            wallDecal.removeNode()
Exemplo n.º 25
0
    def get_taille(self):
        bounds = self.modele.getTightBounds()

        if bounds is not None:
            bound_min, bound_max = bounds
            return LPoint3f(abs(bound_max.x - bound_min.x),
                            abs(bound_max.y - bound_min.y),
                            abs(bound_max.z - bound_min.z))

        return bounds
Exemplo n.º 26
0
    def __init__(self, rootParent=None):

        self.frmMain = DirectFrame(
            frameColor=(0.0, 0.0, 0.0, 0.75),
            frameSize=(-1, 1, -1, 1),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0),
            parent=rootParent,
        )
        self.frmMain.setTransparency(1)

        self.btnQuit = DirectButton(
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, -0.75),
            scale=LVecBase3f(0.1, 0.1, 0.1),
            text='Quit',
            text_align=TextNode.A_center,
            text_scale=(1, 1),
            text_pos=(0, 0),
            text_fg=LVecBase4f(0, 0, 0, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
            command=base.messenger.send,
            extraArgs=["quitRoom"],
            pressEffect=1,
        )
        self.btnQuit.setTransparency(0)

        self.lblMessage = DirectLabel(
            frameColor=(0.0, 0.0, 0.0, 0.0),
            frameSize=(-2.981, 3.106, -0.325, 0.725),
            hpr=LVecBase3f(0, 0, 0),
            pos=LPoint3f(0, 0, 0),
            scale=LVecBase3f(0.2, 0.2, 0.2),
            text='Player A Won',
            text_align=TextNode.A_center,
            text_scale=(1.0, 1.0),
            text_pos=(0, 0),
            text_fg=LVecBase4f(1, 1, 1, 1),
            text_bg=LVecBase4f(0, 0, 0, 0),
            parent=self.frmMain,
        )
        self.lblMessage.setTransparency(0)
Exemplo n.º 27
0
    def __init__(self, manager, number):
        """
		Initialises the drone as a bullet and panda object.
		:param manager: The drone manager creating this very drone.
		"""
        self.manager = manager  # Drone manager handling this drone
        self.base = manager.base  # Simulation
        self.crazyflie = None  # object of real drone, if connected to one
        self.debug = False  # If debugging info should be given
        self.in_flight = False  # If currently in flight
        self.number = number  # Number of drone in list

        # Every drone has its own vector to follow if an avoidance manouver has to be done
        self.avoidance_vector = LVector3f(random.uniform(-1, 1),
                                          random.uniform(-1, 1),
                                          random.uniform(-1, 1)).normalize()

        # Create bullet rigid body for drone
        drone_collision_shape = BulletSphereShape(self.COLLISION_SPHERE_RADIUS)
        self.drone_node_bullet = BulletRigidBodyNode("RigidSphere")
        self.drone_node_bullet.addShape(drone_collision_shape)
        self.drone_node_bullet.setMass(self.RIGID_BODY_MASS)

        # Set some values for the physics object
        self.drone_node_bullet.setLinearSleepThreshold(
            self.LINEAR_SLEEP_THRESHOLD)
        self.drone_node_bullet.setFriction(self.FRICTION)
        self.drone_node_bullet.setLinearDamping(self.LINEAR_DAMPING)

        # Attach to the simulation
        self.drone_node_panda = self.base.render.attachNewNode(
            self.drone_node_bullet)

        # ...and physics engine
        self.base.world.attachRigidBody(self.drone_node_bullet)

        # Add a model to the drone to be actually seen in the simulation
        drone_model = self.base.loader.loadModel(
            "models/drones/drone_florian.egg")
        drone_model.setScale(0.2)
        drone_model.reparentTo(self.drone_node_panda)

        # Set the position and target position to their default (origin)
        default_position = LPoint3f(0, 0, 0)
        self.drone_node_panda.setPos(default_position)
        self.target_position = default_position

        # Create a line renderer to draw a line from center to target point
        self.line_creator = LineSegs()
        # Then draw a default line so that the update function works as expected (with the removal)
        self.target_line_node = self.base.render.attachNewNode(
            self.line_creator.create(False))

        # Create node for text
        self.drone_text_node_panda = None
Exemplo n.º 28
0
def getRandomPos(modelNP):
    """return a random point on the facing upwards surface of the model"""
    
    # collisions are made wrt render
    steerMgr = OSSteerManager.get_global_ptr()
    # get the bounding box of scene
    modelDims, modelDeltaCenter = (LVecBase3f(), LVector3f())
    # modelRadius not used
    steerMgr.get_bounding_dimensions(modelNP, modelDims, modelDeltaCenter)
    # throw a ray downward from a point with z = double scene's height
    # and x,y randomly within the scene's (x,y) plane
    # set the ray origin at double of maximum height of the model
    zOrig = ((-modelDeltaCenter.get_z() + modelDims.get_z() / 2.0) + modelNP.get_z()) * 2.0
    while True:
        x = modelDims.get_x() * (random.uniform(0.0, 1.0) - 0.5) - modelDeltaCenter.get_x() + modelNP.get_x()
        y = modelDims.get_y() * (random.uniform(0.0, 1.0) - 0.5) - modelDeltaCenter.get_y() + modelNP.get_y()
        gotCollisionZ = steerMgr.get_collision_height(LPoint3f(x, y, zOrig))
        if gotCollisionZ.get_first():
            break
    return LPoint3f(x, y, gotCollisionZ.get_second())
Exemplo n.º 29
0
    def consolidate(self, selected = False,sel_simp = None):
        #ask for label, or cancel
        G = self.golog

        # if a collection isn't provided, use the (multi-select) drag dictionary
        if not selected: selected = [G.Graphics_to_Simplex[G.NP_to_Graphics[node]] for node in self.drag_dict.keys()]
        if not selected: return #return if there was nothing passed, and nothing in the drag_dict
        for simp in selected:
            for face in simp.faces:
                if face not in selected: selected.append(face)

        # #? select a simplex to consolidate into
        # sel_simp = None
        # for simp in selected: 
        #     if simp.math_data.type == 'None':
                
        #         sel_simp = simp

        #make a golog from selected
        new_golog = golog.golog(self.base, label ='test')

        def add(simplex):
            for face in simplex.faces:
                add(face)
            new_golog.add(simplex, pos = G.Simplex_to_Graphics[simplex].graphics_kwargs['pos'])
        for simplex in selected: add(simplex)
        

        #consolidate into 1 simplex
        if sel_simp:
            #consolidate into sel_simp
            subgolog_folder_path = os.path.join(self.folder_path,'subgologs')
            unique_path = tk_funcs.unique_path(subgolog_folder_path,[sel_simp.label])
            new_folder_path = ['subgologs', *unique_path]
            
            sel_simp.math_data = hcat.Math_Data(math_data = {'golog':new_golog, 'folder_path':new_folder_path}, type = 'golog')
            
            #? remove simplexes and place at selected simplex location
            return sel_simp


        #create an entirely new simplex to put the golog into
        else:
            #? ask for label / cancel
            label = "test"
            subgolog_folder_path = os.path.join(self.folder_path,'subgologs')
            unique_path = tk_funcs.unique_path(subgolog_folder_path,[label])
            new_folder_path = ['subgologs', *unique_path]

            #create a simplex with average position of things in golog
            avg = LPoint3f(*[sum([G.Simplex_to_Graphics[simplex].graphics_kwargs['pos'][i]/len(new_golog.sSet.simplecies[()])  for simplex in new_golog.sSet.simplecies[()]]) for i in range(3)])
            s = self.golog.add(0, label ='test', math_data = hcat.Math_Data(math_data = {'golog':new_golog, 'folder_path':new_folder_path}, type = 'golog'), pos = LPoint3f(avg))

            return s
Exemplo n.º 30
0
    def random_formation(self):
        """
		Set targets of all drones to a random position within safe corridor of room.
		"""
        # Only use part of the room as possible coordinates
        safe_coordinates = self.ROOM_SIZE - LVector3f(1.0, 1.0, 0.5)

        for drone in self.drones:
            x = random.uniform(-safe_coordinates.x / 2, safe_coordinates.x / 2)
            y = random.uniform(-safe_coordinates.y / 2, safe_coordinates.y / 2)
            z = random.uniform(0.3, safe_coordinates.z)
            drone.set_target(LPoint3f(x, y, z))