def move_camera(camera, camera_control, origin, amount = None): location = camera['location'] line_of_sight = camera['line_of_sight'] parallel = camera['parallel'] if camera_control in ['backward', 'forward']: if amount is None: amount = 0.25 if camera_control == 'forward': location = [location[i] + amount * line_of_sight[i] for i in range(len(location))] elif camera_control == 'backward': location = [location[i] - amount * line_of_sight[i] for i in range(len(location))] camera['location'] = location return camera if amount is None: amount = 2.0 * math.pi / 100.0 if camera_control == 'up': rot = matrix.rotv(parallel, -amount) elif camera_control == 'down': rot = matrix.rotv(parallel, amount) elif camera_control == 'left': rot = matrix.rotv(matrix.cross(parallel, line_of_sight), -amount) elif camera_control == 'right': rot = matrix.rotv(matrix.cross(parallel, line_of_sight), amount) line_of_sight = rot.operate(line_of_sight, origin = [0., 0., 0.]) parallel = rot.operate(parallel, origin = [0., 0., 0.]) location = rot.operate(location, origin = origin) camera = {'location': location, 'line_of_sight': line_of_sight, 'parallel': parallel} return camera
def camera_transform(location, line_of_sight, parallel, deltaz, point): r = [point[i] - location[i] for i in range(len(point))] dist_to_cam = matrix.dot(r, line_of_sight) horiz_coord = deltaz * matrix.dot(r, parallel) / dist_to_cam z = matrix.cross(parallel, line_of_sight) vert_coord = deltaz * matrix.dot(r, matrix.cross(line_of_sight, parallel)) / dist_to_cam return [horiz_coord, vert_coord]