deathcam_mouse_deadzone = 2
giant_camera = (
0, 0, 0,
[
(neg|is_presentation_active, "prsnt_battle"),
(mouse_get_position, pos1),
(set_fixed_point_multiplier, 1000),
(position_get_x, reg1, pos1),
(position_get_y, reg2, pos1),
],
[
(mission_cam_set_mode, 1, 0, 0),
# fix for windowed mode: recenter the mouse
(assign, ":continue", 1),
(try_begin),
(eq, reg1, "$camera_mouse_x"),
(eq, reg2, "$camera_mouse_y"),
(val_add, "$camera_mouse_counter", 1),
(try_begin), #hackery: if the mouse hasn't moved for X cycles, recenter it
(gt, "$camera_mouse_counter", 50),
(assign, "$camera_mouse_center_x", reg1),
(assign, "$camera_mouse_center_y", reg2),
(assign, "$camera_mouse_counter", 0),
(try_end),
(assign, ":continue", 0),
(try_end),
(assign, "$camera_mouse_counter", 0), # reset recentering hackery
# update recorded mouse position
(assign, "$camera_mouse_x", reg1),
(assign, "$camera_mouse_y", reg2),
(mission_cam_get_position, pos47),
(get_player_agent_no, ":player_agent"),
(agent_get_position, pos5, ":player_agent"),
(position_get_x, ":pos_x", pos5),
(position_get_y, ":pos_y", pos5),
(position_get_z, ":pos_z", pos5),
(position_set_x, pos47, ":pos_x"),
(position_set_y, pos47, ":pos_y"),
(position_set_z, pos47, ":pos_z"),
(position_move_z, pos47, 250),
(store_sub, ":shift", "$camera_mouse_center_x", reg1), #horizontal shift for pass 0
(store_sub, ":shift_vertical", reg2, "$camera_mouse_center_y"), #for pass 1
(try_for_range, ":pass", 0, 2), #pass 0: check mouse x movement (left/right), pass 1: check mouse y movement (up/down)
(try_begin),
(eq, ":pass", 1),
(assign, ":shift", ":shift_vertical"), #get ready for the second pass
(try_end),
(this_or_next|lt, ":shift", -deathcam_mouse_deadzone), #skip pass if not needed (mouse deadzone)
(gt, ":shift", deathcam_mouse_deadzone),
(assign, ":sign", 1),
(try_begin),
(lt, ":shift", 0),
(assign, ":sign", -1),
(try_end),
# square root calc
(val_abs, ":shift"),
(val_sub, ":shift", deathcam_mouse_deadzone), # ":shift" is now 1 or greater
(convert_to_fixed_point, ":shift"),
(store_sqrt, ":shift", ":shift"),
(convert_from_fixed_point, ":shift"),
(val_clamp, ":shift", 1, 6), #limit rotation speed
(val_mul, ":shift", ":sign"),
(try_begin),
(eq, ":pass", 0), # rotate around z (left/right)
(store_mul, ":minusrotx", "$camera_rotx", -1),
(position_rotate_x, pos47, ":minusrotx"), #needed so camera yaw won't change
(position_rotate_z, pos47, ":shift"),
(position_rotate_x, pos47, "$camera_rotx"), #needed so camera yaw won't change
(try_end),
(try_begin),
(eq, ":pass", 1), # rotate around x (up/down)
(position_rotate_x, pos47, ":shift"),
(val_add, "$camera_rotx", ":shift"),
(try_end),
(try_end), #try_for_range ":pass"
(mission_cam_set_position, pos47),
]
)