def __init__( self, position=(0.0, 0.0, 1.0), focus=(0.0, 0.0, 0.0), up=(0.0, 1.0, 0.0), fov=45.0, near_plane=0.01, far_plane=20.0, aspect_ratio=8.0 / 6.0, ): super(TrackballCamera, self).__init__( position=position, focus=focus, up=up, fov=fov, near_plane=near_plane, far_plane=far_plane, aspect_ratio=aspect_ratio, ) self.view_matrix = get_lookat_matrix(self.position, self.focus, self.up) rotation_matrix = self.view_matrix[0:3, 0:3] self.orientation = rotation_matrix_to_quaternion(rotation_matrix)
def _update_matrices(self): self.view_matrix = get_lookat_matrix(self.position, self.focus, self.up) self.orientation = rotation_matrix_to_quaternion(self.view_matrix[0:3, 0:3]) self.projection_matrix = self.proj_func(self.fov, self.aspect_ratio, self.near_plane, self.far_plane)
def compute_matrices(self): rotation_matrix = quaternion_to_rotation_matrix(self.orientation) dp = np.linalg.norm(self.position - self.focus) * rotation_matrix[2] self.position = dp + self.focus self.up = rotation_matrix[1] self.view_matrix = get_lookat_matrix(self.position, self.focus, self.up) self.projection_matrix = self.proj_func(self.fov, self.aspect_ratio, self.near_plane, self.far_plane)
def update_orientation(self, start_x, start_y, end_x, end_y): self.orientation = update_orientation(self.orientation, start_x, start_y, end_x, end_y) rotation_matrix = quaternion_to_rotation_matrix(self.orientation) dp = np.linalg.norm(self.position - self.focus) * rotation_matrix[2] self.position = dp + self.focus self.up = rotation_matrix[1] self.view_matrix = get_lookat_matrix(self.position, self.focus, self.up) self.projection_matrix = self.proj_func(self.fov, self.aspect_ratio, self.near_plane, self.far_plane)
def offset_position(self, dpos=None): if dpos is None: dpos = np.array([0.0, 0.0, 0.0]) self.position += dpos self.view_matrix = get_lookat_matrix(self.position, self.focus, self.up)
def _default_view_matrix(self): return get_lookat_matrix(self.position, self.focus, self.up)