Exemple #1
0
  def on_key_up(self,event):
    if event[1]==sdlconst.K_w:
      self.speed.z=0
      if self.speed.z<-1.: self.speed.z=-1.
    elif event[1]==sdlconst.K_s:
      self.speed.z=0
      if self.speed.z>1.: self.speed.z=1.

    elif event[1]==sdlconst.K_a:
      self.speed.x=0
    elif event[1]==sdlconst.K_d:
      self.speed.x=0

    elif event[1]==sdlconst.K_LCTRL:
      self.zoom=0
      self.speed.z=0.

    elif event[1]==sdlconst.K_F11:
      soya.toggle_wireframe()
Exemple #2
0
    def begin_round(self):
        soya.World.begin_round(self)

        for event in soya.process_event():
            
            # Mouse down initiates the dragdrop.
                        # key pressed:
            if event[0] == soya.sdlconst.KEYDOWN:
                #print self.x, self.y, self.z
                # [ARROW UP] - move forward:
                if event[1] == soya.sdlconst.K_UP or event[1] == soya.sdlconst.K_w:
                    self.cam.speed.z = -0.2
                # [ARROW DOWN] - move backward:
                elif event[1] == soya.sdlconst.K_DOWN or event[1] == soya.sdlconst.K_s:
                    self.cam.speed.z = 0.2
                # [ARROW LEFT] - turn left:
                elif event[1] == soya.sdlconst.K_LEFT or event[1] == soya.sdlconst.K_a:
                    self.cam.rotation_y_speed = 1.5
                # [ARROW RIGHT] - turn right:
                elif event[1] == soya.sdlconst.K_RIGHT or event[1] == soya.sdlconst.K_d:
                    self.cam.rotation_y_speed = -1.5
                # [s] - take a screenshot:
                #elif event[1] == soya.sdlconst.K_s:
                #	self.make_screenshot()
                # [b] - toggle wireframe:
                elif event[1] == soya.sdlconst.K_b:
                    soya.toggle_wireframe()
                # [q] - quit:
                #elif event[1] == soya.sdlconst.K_q:
                #	soya.MAIN_LOOP.stop()
                # [ESC] - quit:
                elif event[1] == soya.sdlconst.K_ESCAPE:
                    soya.MAIN_LOOP.stop()
                # [p] - look up:
                elif event[1] == soya.sdlconst.K_p:
                    self.cam.rotation_x_speed = 1.0
                # [l] - look down:
                elif event[1] == soya.sdlconst.K_l:
                    self.cam.rotation_x_speed = -1.0
                #TODO:  [x] - save world:
                #elif event[1] == soya.sdlconst.K_x:
                #	self.save()
                # [e] - rotate world:
                elif event[1] == soya.sdlconst.K_e:
                    self.rotation_y_speed = 1.5
                # [r] - rotate world:
                elif event[1] == soya.sdlconst.K_r:
                    self.rotation_y_speed = -1.5
                # [u] - reset camera position:
                elif event[1] == soya.sdlconst.K_u:
                    self.cam.set_xyz(0.0, 0.0, 15.0)
                    self.cam.look_at_y(self.point)
                # [o] - rotate world:
                elif event[1] == soya.sdlconst.K_o:
                    self.rotation_x_speed = 1.5
                # [k] - rotate world:
                elif event[1] == soya.sdlconst.K_k:
                    self.rotation_x_speed = -1.5

            # key released:
            elif event[0] == soya.sdlconst.KEYUP:
                # [ARROW UP] - stop motion:
                if event[1] == soya.sdlconst.K_UP or event[1] == soya.sdlconst.K_w:
                    self.cam.speed.z = 0.0
                # [ARROW DOWN] - stop motion:
                elif event[1] == soya.sdlconst.K_DOWN or event[1] == soya.sdlconst.K_s:
                    self.cam.speed.z = 0.0
                # [ARROW LEFT] - stop motion:
                elif event[1] == soya.sdlconst.K_LEFT or event[1] == soya.sdlconst.K_a:
                    self.cam.rotation_y_speed = 0.0
                # [ARROW RIGHT] - stop motion:
                elif event[1] == soya.sdlconst.K_RIGHT or event[1] == soya.sdlconst.K_d:
                    self.cam.rotation_y_speed = 0.0
                # [p] - stop looking up:
                elif event[1] == soya.sdlconst.K_p or event[1] == soya.sdlconst.K_l:
                    self.cam.rotation_x_speed = 0.0
                elif event[1] == soya.sdlconst.K_e or event[1] == soya.sdlconst.K_r:
                    self.rotation_y_speed = 0.0
                # [o/k] - stop rotate world:
                elif event[1] == soya.sdlconst.K_o or event[1] == soya.sdlconst.K_k:
                    self.rotation_x_speed = 0.0

            elif event[0] == soya.sdlconst.MOUSEBUTTONDOWN:
                # The event give us the 2D mouse coordinates in pixel. The camera.coord2d_to_3d
                # convert these 2D pixel coordinates into a soy.Point object.
                mouse = self.cam.coord2d_to_3d(event[2], event[3])

                # Performs a raypicking, starting at the camera and going toward the mouse.
                # The vector_to method returns the vector between 2 positions.
                # This raypicking grabs anything that is under the mouse. Raypicking returns
                # None if nothing is encountered, or a (impact, normal) tuple, where impact is the
                # position of the impact and normal is the normal vector at this position.
                # The object encountered is impact.parent ; here, we don't need the normal.
                result = self.raypick(self.cam, self.cam.vector_to(mouse))
                if result:
                    self.impact, normal = result
                    self.dragdroping = self.impact.parent

                    # Converts impact into the camera coordinate system, in order to get its Z value.
                    # camera.coord2d_to_3d cannot choose a Z value for you, so you need to pass it
                    # as a third argument (it defaults to -1.0). Then, we computes the old mouse
                    # position, which has the same Z value than impact.
                    self.impact.convert_to(self.cam)
                    self.old_mouse = self.cam.coord2d_to_3d(event[2], event[3], self.impact.z)


            # Mouse up ends the dragdrop.
            elif event[0] == soya.sdlconst.MOUSEBUTTONUP:
                self.dragdroping = None

            # Mouse motion moves the dragdroping object, if there is one.
            elif event[0] == soya.sdlconst.MOUSEMOTION:
                if self.dragdroping:

                    # Computes the new mouse position, at the same Z value than impact.
                    new_mouse = self.cam.coord2d_to_3d(event[1], event[2], self.impact.z)

                    # Translates dragdroping by a vector starting at old_mouse and ending at
                    # new_mouse.
                    self.dragdroping.add_vector(self.old_mouse.vector_to(new_mouse))

                    # Store the current mouse position.
                    self.old_mouse = new_mouse
Exemple #3
0
    def begin_roundzz(self):
        soya.Camera.begin_round(self)

        # go through the events:
        for event in soya.process_event():
            # key pressed:
            if event[0] == soya.sdlconst.KEYDOWN:
                #print self.x, self.y, self.z
                # [ARROW UP] - move forward:
                if event[1] == soya.sdlconst.K_UP or event[1] == soya.sdlconst.K_w:
                    if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW UP]'
                    self.speed.z = -0.2
                # [ARROW DOWN] - move backward:
                elif event[1] == soya.sdlconst.K_DOWN or event[1] == soya.sdlconst.K_s:
                    if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW DOWN]'
                    self.speed.z =  0.2
                # [ARROW LEFT] - turn left:
                elif event[1] == soya.sdlconst.K_LEFT or event[1] == soya.sdlconst.K_a:
                    if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW LEFT]'
                    self.rotation_y_speed =  1.5
                # [ARROW RIGHT] - turn right:
                elif event[1] == soya.sdlconst.K_RIGHT or event[1] == soya.sdlconst.K_d:
                    if self.debug: print 'DEBUG: MovableCamera - key pressed - [ARROW RIGHT]'
                    self.rotation_y_speed = -1.5
                # [s] - take a screenshot:
                elif event[1] == soya.sdlconst.K_s:
                    if self.debug: print 'DEBUG: UserInputManager - key pressed - [s]'
                    self.make_screenshot()
                # [t] - toggle wireframe:
                elif event[1] == soya.sdlconst.K_t:
                    if self.debug: print 'DEBUG: UserInputManager - key pressed - [t]'
                    soya.toggle_wireframe()
                # [q] - quit:
                elif event[1] == soya.sdlconst.K_q:
                    if self.debug: print 'DEBUG: MovableCamera - key pressed - [q]'
                    soya.MAIN_LOOP.stop()
                # [ESC] - quit:
                elif event[1] == soya.sdlconst.K_ESCAPE:
                    if self.debug: print 'DEBUG: MovableCamera - key pressed - [ESCAPE]'
                    soya.MAIN_LOOP.stop()
                # [o] - look up:
                elif event[1] == soya.sdlconst.K_o:
                    if self.debug: print 'DEBUG: MovableCamera - key pressed - [o]'
                    self.rotation_x_speed = 1.0
                # [k] - look down:
                elif event[1] == soya.sdlconst.K_k:
                    if self.debug: print 'DEBUG: MovableCamera - key pressed - [k]'
                    self.rotation_x_speed = -1.0
                # [k] - look down:
                elif event[1] == soya.sdlconst.K_r:
                    if self.debug: print 'DEBUG: MovableCamera - key pressed - [r]'
                    self.make_screenshot()

            # key released:
            if event[0] == soya.sdlconst.KEYUP:
                # [ARROW UP] - stop motion:
                if event[1] == soya.sdlconst.K_UP or event[1] == soya.sdlconst.K_w:
                    self.speed.z = 0.0
                # [ARROW DOWN] - stop motion:
                elif event[1] == soya.sdlconst.K_DOWN or event[1] == soya.sdlconst.K_s:
                    self.speed.z = 0.0
                # [ARROW LEFT] - stop motion:
                elif event[1] == soya.sdlconst.K_LEFT or event[1] == soya.sdlconst.K_a:
                    self.rotation_y_speed = 0.0
                # [ARROW RIGHT] - stop motion:
                elif event[1] == soya.sdlconst.K_RIGHT or event[1] == soya.sdlconst.K_d:
                    self.rotation_y_speed = 0.0
                # [o] - look up:
                elif event[1] == soya.sdlconst.K_o:
                    self.rotation_x_speed = 0.0
                # [k] - look down:
                elif event[1] == soya.sdlconst.K_k:
                    self.rotation_x_speed = 0.0
Exemple #4
0
    def begin_roundzz(self):
        soya.Camera.begin_round(self)

        # go through the events:
        for event in soya.process_event():
            # key pressed:
            if event[0] == soya.sdlconst.KEYDOWN:
                #print self.x, self.y, self.z
                # [ARROW UP] - move forward:
                if event[1] == soya.sdlconst.K_UP or event[
                        1] == soya.sdlconst.K_w:
                    if self.debug:
                        print 'DEBUG: MovableCamera - key pressed - [ARROW UP]'
                    self.speed.z = -0.2
                # [ARROW DOWN] - move backward:
                elif event[1] == soya.sdlconst.K_DOWN or event[
                        1] == soya.sdlconst.K_s:
                    if self.debug:
                        print 'DEBUG: MovableCamera - key pressed - [ARROW DOWN]'
                    self.speed.z = 0.2
                # [ARROW LEFT] - turn left:
                elif event[1] == soya.sdlconst.K_LEFT or event[
                        1] == soya.sdlconst.K_a:
                    if self.debug:
                        print 'DEBUG: MovableCamera - key pressed - [ARROW LEFT]'
                    self.rotation_y_speed = 1.5
                # [ARROW RIGHT] - turn right:
                elif event[1] == soya.sdlconst.K_RIGHT or event[
                        1] == soya.sdlconst.K_d:
                    if self.debug:
                        print 'DEBUG: MovableCamera - key pressed - [ARROW RIGHT]'
                    self.rotation_y_speed = -1.5
                # [s] - take a screenshot:
                elif event[1] == soya.sdlconst.K_s:
                    if self.debug:
                        print 'DEBUG: UserInputManager - key pressed - [s]'
                    self.make_screenshot()
                # [t] - toggle wireframe:
                elif event[1] == soya.sdlconst.K_t:
                    if self.debug:
                        print 'DEBUG: UserInputManager - key pressed - [t]'
                    soya.toggle_wireframe()
                # [q] - quit:
                elif event[1] == soya.sdlconst.K_q:
                    if self.debug:
                        print 'DEBUG: MovableCamera - key pressed - [q]'
                    soya.MAIN_LOOP.stop()
                # [ESC] - quit:
                elif event[1] == soya.sdlconst.K_ESCAPE:
                    if self.debug:
                        print 'DEBUG: MovableCamera - key pressed - [ESCAPE]'
                    soya.MAIN_LOOP.stop()
                # [o] - look up:
                elif event[1] == soya.sdlconst.K_o:
                    if self.debug:
                        print 'DEBUG: MovableCamera - key pressed - [o]'
                    self.rotation_x_speed = 1.0
                # [k] - look down:
                elif event[1] == soya.sdlconst.K_k:
                    if self.debug:
                        print 'DEBUG: MovableCamera - key pressed - [k]'
                    self.rotation_x_speed = -1.0
                # [k] - look down:
                elif event[1] == soya.sdlconst.K_r:
                    if self.debug:
                        print 'DEBUG: MovableCamera - key pressed - [r]'
                    self.make_screenshot()

            # key released:
            if event[0] == soya.sdlconst.KEYUP:
                # [ARROW UP] - stop motion:
                if event[1] == soya.sdlconst.K_UP or event[
                        1] == soya.sdlconst.K_w:
                    self.speed.z = 0.0
                # [ARROW DOWN] - stop motion:
                elif event[1] == soya.sdlconst.K_DOWN or event[
                        1] == soya.sdlconst.K_s:
                    self.speed.z = 0.0
                # [ARROW LEFT] - stop motion:
                elif event[1] == soya.sdlconst.K_LEFT or event[
                        1] == soya.sdlconst.K_a:
                    self.rotation_y_speed = 0.0
                # [ARROW RIGHT] - stop motion:
                elif event[1] == soya.sdlconst.K_RIGHT or event[
                        1] == soya.sdlconst.K_d:
                    self.rotation_y_speed = 0.0
                # [o] - look up:
                elif event[1] == soya.sdlconst.K_o:
                    self.rotation_x_speed = 0.0
                # [k] - look down:
                elif event[1] == soya.sdlconst.K_k:
                    self.rotation_x_speed = 0.0