Beispiel #1
0
 def move(self, position):
     if soya.get_mod() & soya.sdlconst.MOD_SHIFT:
         position = soya.Point(position.parent, position.x, position.y, position.z)
         position.convert_to(self.orientation.parent)
         position.y = self.orientation.y
     self.orientation.look_at(position)
     self.place()
Beispiel #2
0
    def on_event(self, event):
        # print event
        if event[0] == soya.sdlconst.MOUSEMOTION:
            if soya.get_mod() & soya.sdlconst.MOD_CTRL:
                self.cursor.grid_step = STEP
            else:
                self.cursor.grid_step = 0.0

            if self.camera_mode:
                self.camera.turn_y(float(event[3]))
                self.camera.turn_x(float(event[4]))

            x, y = event[1], event[2]
            if x == 0:
                self.camera += soya.Vector(self.camera, -0.1, 0.0, 0.0)
            elif x == self.camera.get_screen_width() - 1:
                self.camera += soya.Vector(self.camera, 0.1, 0.0, 0.0)
            if y == 0:
                self.camera += soya.Vector(self.camera, 0.0, 0.1, 0.0)
            elif y == self.camera.get_screen_height() - 1:
                self.camera += soya.Vector(self.camera, 0.0, -0.1, 0.0)

            self.cursor.mouse_moved(x, y)

        elif event[0] == soya.sdlconst.MOUSEBUTTONDOWN:
            if event[1] < 3:  # Left or middle button
                current = time.time()
                if current - self.last_click < 0.2:
                    self.cursor.button_pressed(
                        2, soya.get_mod() & soya.sdlconst.MOD_SHIFT
                    )  # Double-click is the same that middle click
                else:
                    self.cursor.button_pressed(event[1], soya.get_mod() & soya.sdlconst.MOD_SHIFT)
                self.last_click = current
            elif event[1] == 3:
                self.camera_mode = 1

        elif event[0] == soya.sdlconst.MOUSEBUTTONUP:
            if self.camera_mode:
                if event[1] == 3:
                    self.camera_mode = 0
                elif event[1] == 4:
                    self._zoom(-1.0)
                elif event[1] == 5:
                    self._zoom(1.0)
            else:
                if event[1] < 3:
                    self.cursor.button_released(event[1])
                elif event[1] == 4:
                    self.cursor.mouse_rolled(-0.25)
                elif event[1] == 5:
                    self.cursor.mouse_rolled(0.25)

        elif event[0] == soya.sdlconst.KEYDOWN:
            # Page up, page down
            if event[1] == 280:
                self.cursor.mouse_rolled(-1 - 9 * (soya.get_mod() & soya.sdlconst.MOD_SHIFT))
            elif event[1] == 281:
                self.cursor.mouse_rolled(1 + 9 * (soya.get_mod() & soya.sdlconst.MOD_SHIFT))

            # Left, right, up, down
            elif event[1] == 276:
                self.camera += soya.Vector(
                    self.camera, -1.0 - 9.0 * (soya.get_mod() & soya.sdlconst.MOD_SHIFT), 0.0, 0.0
                )
            elif event[1] == 275:
                self.camera += soya.Vector(
                    self.camera, 1.0 + 9.0 * (soya.get_mod() & soya.sdlconst.MOD_SHIFT), 0.0, 0.0
                )
            elif event[1] == 273:
                self.camera += soya.Vector(
                    self.camera, 0.0, 1.0 + 9.0 * (soya.get_mod() & soya.sdlconst.MOD_SHIFT), 0.0
                )
            elif event[1] == 274:
                self.camera += soya.Vector(
                    self.camera, 0.0, -1.0 - 9.0 * (soya.get_mod() & soya.sdlconst.MOD_SHIFT), 0.0
                )

            # o : toggle ortho camera
            elif event[1] == 111:
                self.camera.ortho = not self.camera.ortho
                self.camera.fov = 60.0

                # +, - : zoom
            elif event[1] == 270:
                self._zoom(-1.0 - 9 * (soya.get_mod() & soya.sdlconst.MOD_SHIFT))
            elif event[1] == 269:
                self._zoom(1.0 + 9 * (soya.get_mod() & soya.sdlconst.MOD_SHIFT))

            # 4, 6, 8, 2, 5, 0 : predefined views
            elif event[1] == 260:
                a, b = self.world.get_box()
                cameray, cameraz = self.camera.y, self.camera.z
                self.camera.set_identity()
                self.camera.set_xyz(min((a % self.scene).x, (b % self.scene).x) - 3.0, cameray, cameraz)
                self.camera.look_at(soya.Vector(None, 1.0, 0.0, 0.0))
            elif event[1] == 262:
                a, b = self.world.get_box()
                cameray, cameraz = self.camera.y, self.camera.z
                self.camera.set_identity()
                self.camera.set_xyz(max((a % self.scene).x, (b % self.scene).x) + 3.0, cameray, cameraz)
                self.camera.look_at(soya.Vector(None, -1.0, 0.0, 0.0))
            elif event[1] == 264:
                a, b = self.world.get_box()
                camerax, cameraz = self.camera.x, self.camera.z
                self.camera.set_identity()
                self.camera.set_xyz(camerax, max((a % self.scene).y, (b % self.scene).y) + 3.0, cameraz)
                self.camera.look_at(soya.Vector(None, 0.0, -1.0, 0.0))
            elif event[1] == 258:
                a, b = self.world.get_box()
                camerax, cameraz = self.camera.x, self.camera.z
                self.camera.set_identity()
                self.camera.set_xyz(camerax, min((a % self.scene).y, (b % self.scene).y) - 3.0, cameraz)
                self.camera.look_at(soya.Vector(None, 0.0, 1.0, 0.0))
            elif event[1] == 261:
                a, b = self.world.get_box()
                camerax, cameray = self.camera.x, self.camera.y
                self.camera.set_identity()
                self.camera.set_xyz(camerax, cameray, min((a % self.scene).z, (b % self.scene).z) - 3.0)
                self.camera.look_at(soya.Vector(None, 0.0, 0.0, 1.0))
            elif event[1] == 256:
                a, b = self.world.get_box()
                camerax, cameray = self.camera.x, self.camera.y
                self.camera.set_identity()
                self.camera.set_xyz(camerax, cameray, max((a % self.scene).z, (b % self.scene).z) + 3.0)
                self.camera.look_at(soya.Vector(None, 0.0, 0.0, -1.0))

                # q, t : new quad, new triangle
            elif event[1] == 113:
                if hasattr(self.current, "children"):
                    into = self.current
                else:
                    into = self.current.parent
                into.append(soya.Quad())
            elif event[1] == 116:
                if hasattr(self.current, "children"):
                    into = self.current
                else:
                    into = self.current.parent
                into.append(soya.Triangle())
            else:
                if KEY_BINDINGS.has_key(event[1]):
                    KEY_BINDINGS[event[1]](self.world, self.current)