コード例 #1
0
ファイル: ocemp.py プロジェクト: s-horiguchi/PyWiiRemote
 def get_status(self):
     self.param["org_mode"] = wiiremote.start_status()
     while wiiremote.running():
         if not self.param["org_mode"]:
             wiiremote.pause(False)  #pause release
             break
     return
コード例 #2
0
ファイル: ocemp.py プロジェクト: s-horiguchi/PyWiiRemote
    def main(self):
        #init
        self.load_conf()
        pygame.init()
        wiiremote.init(self)
        if not wiiremote.running(): return
        wiiremote.pause(True)  #pause to get acc and gyro data

        #visual
        visual.scene.width = self.param["width"]
        visual.scene.height = self.param["height"]
        visual.scene.title = "WiiRemote"
        visual.scene.forward = visual.vector(1, 0, 0)  # not to error ?
        visual.scene.up = visual.vector(0, 0, 1)
        visual.scene.forward = visual.vector(-1, 1, -1)
        visual.scene.autoscale = 0
        self.visual["axis"][0] = visual.arrow(color=visual.color.red,
                                              axis=(3, 0, 0),
                                              headwidth=1,
                                              shaftwidth=0.5,
                                              fixedwidth=1)
        self.visual["axis"][1] = visual.arrow(color=visual.color.green,
                                              axis=(0, 3, 0),
                                              headwidth=1,
                                              shaftwidth=0.5,
                                              fixedwidth=1)
        self.visual["axis"][2] = visual.arrow(color=visual.color.blue,
                                              axis=(0, 0, 3),
                                              headwidth=1,
                                              shaftwidth=0.5,
                                              fixedwidth=1)
        self.visual["wiiobj"] = visual.box(
            pos=(0, 0, 0),
            length=1,
            height=4,
            width=1.5,
            color=visual.color.white,
        )

        #sound
        if self.option["sound"]:
            self.init_sound()

        #status
        self.get_status()

        #accel
        self.init_accel()
        acc = [0, 0, 0]

        #pygame
        old = [self.param["height"] / 2] * 3
        view = [True, True, True]
        screen = pygame.display.set_mode(
            (self.param["width"], self.param["height"]))
        font = pygame.font.SysFont(None,
                                   int(self.param["sidebar_width"] * 1.5))
        self.param[
            "width_"] = self.param["width"] - self.param["sidebar_width"]

        print "[--- start ---]"
        if self.option["sound"]:
            print "press A to on/off saber"

        while self.param["running"]:
            #self.re.refresh()
            pygame.time.wait(100)
            pygame.display.update()

            screen.fill((0, 0, 0),
                        (self.param["width_"], 0, self.param["sidebar_width"],
                         self.param["height"]))
            screen.blit(screen, (-1, 0))

            for i in range(int(maxA * 2 + 1)):
                screen.blit(
                    font.render("%-d" % (maxA - i), True, (144, 144, 144)),
                    (self.param["width_"], float(self.param["height"]) /
                     (maxA * 2) * i - self.param["sidebar_width"] * 1.5 / 4))
                pygame.draw.line(
                    screen, (144, 144, 144),
                    (0, float(self.param["height"]) / (maxA * 2) * i),
                    (self.param["width_"], float(self.param["height"]) /
                     (maxA * 2) * i))

            #pygame
            for c in range(3):  # 3axis
                if view[c]:
                    s = int((acc[c] * self.param["height"] / maxA +
                             self.param["height"]) / 2)
                    s = max(0, min(self.param["height"] - 1, s))
                    pygame.draw.line(screen, colors[c],
                                     (self.param["width_"] - 3, old[c]),
                                     (self.param["width_"] - 2, s))
                    old[c] = s

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    wiiremote.quit()
                    sys.exit(1)
                    return
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        wiiremote.quit()
                        sys.exit(1)
                        return
                    if event.key == pygame.K_x:
                        if view[0]: view[0] = False
                        else: view[0] = True
                    elif event.key == pygame.K_y:
                        if view[1]: view[1] = False
                        else: view[1] = True
                    elif event.key == pygame.K_z:
                        if view[2]: view[2] = False
                        else: view[2] = True