def set_perspective(self): glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(self._fov, self._aspect, self._near_dist, self._far_dist) # If the transform for the camera has changed, then recalculate the frustrum if self.node_parent.transform.has_changed_this_frame: self._update_frustum = Settings.get('RenderSettings','update_frustum') if Input.get_key(Input.KEY_1): if not self._update_frustum: self._update_frustum = True#not self._update_frustum print "Frustum update enabled" print "cam pos: %s" % self._transform.position if Input.get_key(Input.KEY_2): if self._update_frustum: self._update_frustum = False print "Frustum update disabled" print "@ cam pos: %s" % self._transform.position if self._update_frustum: #self.calc_frustum() self.calc_frustum_lighthouse() self.update_projection_matrix() # show the frustum visualisation self._vis_frustum(not self._update_frustum)
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