Beispiel #1
0
    def update_pos_by_dist_and_dir(self, distance, direction):
        """
        params:
        distance - distance went through
        direction - angles relative to the west (clockwise)
        """
        dirRelativeNorth = Map.get_direction_relative_north(self.building, self.level, direction)
        northAt = Map.get_north_at(self.building, self.level)
        userDir = dirRelativeNorth + northAt  # relative to map
        userDir = userDir % 360
        if not self.nextLoc:
            self.nextLoc = self.get_next_location(self.pos[0], self.pos[1])
        movingDir = Map.get_direction(self.pos[0], self.nextLoc["x"],
                                      self.pos[1], self.nextLoc["y"])  # relative to map
        relativeDir = movingDir - userDir
        # if relativeDir > 0, it's at user's rhs, else lhs
        if relativeDir > 180:
            relativeDir -= 360
        if relativeDir < -180:
            relativeDir += 360
        (x, y, newDir) = Map.get_direction_details(self.building, self.level, distance, direction + relativeDir)

        vec1X = self.pos[0] - float(self.nextLoc["x"])
        vec1Y = self.pos[1] - float(self.nextLoc["y"])
        vec2X = self.pos[0] + x - float(self.nextLoc["x"])
        vec2Y = self.pos[1] + y - float(self.nextLoc["y"])
        isSameDirection = (vec1X * vec2X + vec1Y * vec2Y > 0)
        isReachNextLoc = self.is_reach_node(self.nextLoc, self.pos[0] + x, self.pos[1] + y)
        isWentPass = not isSameDirection and not isReachNextLoc
        if isWentPass:
            self.reachedLoc.append(self.nextLoc["nodeName"])
        self.update_pos(x, y)