7 def calculate_fov(fov, horizontal, vertical, viewzoom):
8 viewzoom_multiplier = 1 / viewzoom
9 frustumy = math.tan(fov * math.pi / 360) * 0.75 * viewzoom_multiplier
10 frustumx = frustumy * horizontal / vertical
12 fovx = math.atan2(frustumx, 1) / math.pi * 360
13 fovy = math.atan2(frustumy, 1) / math.pi * 360
15 print(fov, "degrees of hfov with 4:3 resolution (unstretched without black bars) actually gives:")
16 print("Horizontal FOV =", fovx)
17 print("Vertical FOV =", fovy)
20 if __name__ == "__main__":
21 parser = argparse.ArgumentParser(description='Process in-game fov cvars to horizontal and vertical degrees.')
22 parser.add_argument('fov', type=float,
23 help="in-game fov cvar, degrees of hfov with 4:3 resolution, required field")
24 parser.add_argument('horizontalAspectRatio', type=float, default=16, nargs='?',
25 help="Horizontal num of the aspect ratio, for 16:9 that is 16, default: 16")
26 parser.add_argument('verticalAspectRatio', type=float, default=9, nargs='?',
27 help="Vertical num of the aspect ratio, for 16:9 that is 9, default: 9")
28 parser.add_argument('viewzoom', type=float, default=1, nargs='?',
29 help="Zoom amount, default: 1 / no zoom")
30 args = parser.parse_args()
32 if (args.fov < 1 or args.fov > 170):
33 print("WARNING: Xonotic's fov is currently restricted between 1 and 170, calculations might be broken with this number.")
34 if (args.viewzoom < 1 or args.viewzoom > 30):
35 print("WARNING: Xonotic's zoom is currently restricted between 1 and 30, calculations might be broken with this number.")
37 calculate_fov(args.fov, args.horizontalAspectRatio, args.verticalAspectRatio, args.viewzoom)