Esempio n. 1
0
    def update(self):
        # Get UI values
        self.speed = self._ui.speed
        self.angle_speed = self._ui.angle_speed

        super(CameraMoveController, self).update()

        if Input.get_mouse_left() and not self._mouse_over_ui:
            
            pos = self._node.transform.position
            forward = self._node.transform.forward
            
            mx, my = Input.get_mouse_move_relative()
            # FIXME: HACK to prevent immediate jump on initial mouse movement
            if math.fabs(mx) < 60.0 and math.fabs(my) < 60.0: # <== This makes mouse movement feel like 
                                                              # it's moving through molasses
                h_angle = self._mouse_speed_x * -mx
                v_angle = self._mouse_speed_y * -my
                
                self._node.transform.rotate(Quaternion().rotate_axis(h_angle, self._node.transform.up), Space.PARENT )
                self._node.transform.rotate(Quaternion().rotate_axis(v_angle, self._node.transform.right), Space.PARENT )

                #self._node.transform.rotate(Quaternion().rotate_axis(h_angle, Vector3(0,1,0)), Space.PARENT )
                #self._node.transform.rotate(Quaternion().rotate_axis(v_angle, Vector3(1,0,0)), Space.PARENT )
                
                self._node.camera.look_at_position = pos + ( forward * self._speed)
Esempio n. 2
0
    def update(self):
        
        if not self._mouse_over_ui:
            # If the left mouse button is down
            mouse_left_down = Input.get_mouse_left()
            
            # If the left mouse is down 
            if mouse_left_down:
                
                if not self._unlock_mouse:
                    Input.set_lock_mouse(True)
                self._unlock_mouse = True
#                # Hide the cursor
#                #mouse.set_visible(False)
#                
#                # And its not the initial frame
#                if not self._initial_mouse_down:
#                    # Reset the mouse position to the centre of the screen
#                    #self._mouse_x, self._mouse_y = mouse.get_pos()
#                    self._mouse_x, self._mouse_y = Input.get_mouse_move()
#                    self._mouse_x -= self._h_res[0]
#                    self._mouse_y -= self._h_res[1]
#                    Input.set_mouse_pos(self._mouse_x, self._mouse_y)
#                else:
#                    self._initial_mouse_down = False
#                    Input.set_mouse_pos(0, 0)
#                    
#                #mouse.set_pos(self._h_res[0],self._h_res[1])
#                Input.set_mouse_pos(self._h_res[0],self._h_res[1])
#                
#                self._initial_mouse_up = True
                
                # Handle Keyboard
                
                # Handle adjusting normal speed
                if Input.get_key(Input.KEY_BACKSLASH):
                    self._final_speed -= self._adj_speed * Time.delta_time
                    if self._final_speed < 0:
                        self._final_speed = self._adj_speed
                    
                if Input.get_key(Input.KEY_EQUALS):
                    self._final_speed += self._adj_speed * Time.delta_time 
                    
                applied_speed = self._final_speed
                    
                # Handle temporary speed boost
                if Input.get_key(Input.KEY_LEFT_SHIFT):
                    applied_speed *= 10.0
                
                if Input.get_key(Input.KEY_A):
                    self._node.transform.translate(  ( Vector3.RIGHT() * applied_speed * Time.delta_time ) )
                if Input.get_key(Input.KEY_D):
                    self._node.transform.translate(  ( Vector3.RIGHT() * -applied_speed * Time.delta_time ) )
                if Input.get_key(Input.KEY_W):
                    self._node.transform.translate( ( Vector3.FORWARD() * applied_speed * Time.delta_time ) )
                if Input.get_key(Input.KEY_S):
                    self._node.transform.translate( ( Vector3.FORWARD() * -applied_speed * Time.delta_time ) )
                    
                if Input.get_key(Input.KEY_R):
                    self._node.transform.translate( ( Vector3.UP() * applied_speed * Time.delta_time ) )
                if Input.get_key(Input.KEY_F):
                    self._node.transform.translate( ( Vector3.UP() * -applied_speed * Time.delta_time ) )
                
                angle = self._angle_speed * Time.delta_time
                angle = angle * (math.pi / 180 )
                
                if Input.get_key(Input.KEY_Q):
                    self._node.transform.rotate(Quaternion().rotate_axis(angle, Vector3(0,1,0)) )
                    
                if Input.get_key(Input.KEY_E):
                    self._node.transform.rotate( Quaternion().rotate_axis(-angle, Vector3(0,1,0)) )
                
            else:
                if self._unlock_mouse:
                    Input.set_lock_mouse(False)
                    self._unlock_mouse = False