Skip to content

Instantly share code, notes, and snippets.

@Skwuruhl
Created January 8, 2018 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skwuruhl/64625cc14f21cc2ef1d914dacf5d59dc to your computer and use it in GitHub Desktop.
Save Skwuruhl/64625cc14f21cc2ef1d914dacf5d59dc to your computer and use it in GitHub Desktop.
Killing Floor 2 ADS Normalization (Java)
package kf2ads;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class Normalization {
double rfov, coef;
double[] zoom, rzoom;
String[] bind;
public Normalization(double f, double c) {
rfov = Math.toRadians(90 * f);
coef = c;
zoom = new double[6];
zoom[0] = 80 * f;
zoom[1] = 77 * f;
zoom[2] = 75 * f;
zoom[3] = 73 * f;
zoom[4] = 70 * f;
zoom[5] = 65 * f;
rzoom = new double[6];
for (int i = 0; i < rzoom.length; i++) {
rzoom[i] = Math.toRadians(zoom[i]);
}
bind = new String[6];
calcBind();
}
public void calcBind() {
DecimalFormat df = new DecimalFormat("#.######");
df.setRoundingMode(RoundingMode.HALF_UP);
bind[0] = "SetBind NumpadOne \"fov " + df.format(zoom[0]) + "|SetZoomedSensitivity " + df.format(Normalize(0))
+ "\"";
bind[1] = "SetBind NumpadTwo \"fov " + df.format(zoom[1]) + "|SetZoomedSensitivity " + df.format(Normalize(1))
+ "\"";
bind[2] = "SetBind NumpadThree \"fov " + df.format(zoom[2]) + "|SetZoomedSensitivity " + df.format(Normalize(2))
+ "\"";
bind[3] = "SetBind NumpadFour \"fov " + df.format(zoom[3]) + "|SetZoomedSensitivity " + df.format(Normalize(3))
+ "\"";
bind[4] = "SetBind NumpadFive \"fov " + df.format(zoom[4]) + "|SetZoomedSensitivity " + df.format(Normalize(4))
+ "\"";
bind[5] = "SetBind NumpadSix \"fov " + df.format(zoom[5]) + "|SetZoomedSensitivity " + df.format(Normalize(5))
+ "\"";
}
public double Normalize(int z) {
if (coef > 0)
return Math.atan(coef * Math.tan(rzoom[z] / 2)) / Math.atan(coef * Math.tan(rfov / 2)) / zoom[z] / 0.013330;
return Math.tan(rzoom[z] / 2) / Math.tan(rfov / 2) / zoom[z] / 0.013330;
}
public String toString() {
String output = "";
for (String s : bind)
output += s + "|";
return output.substring(0, output.length() - 1);
}
}
package kf2ads;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.util.Scanner;
public class Run {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.print("FOVOptionsPercentageValue=");
Double fov = kb.nextDouble();
System.out.print("Coefficient=");
Double coef = kb.nextDouble();
kb.close();
Normalization norm = new Normalization(fov, coef);
StringSelection selection = new StringSelection(norm.toString());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment