-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslation.java
More file actions
58 lines (51 loc) · 1.53 KB
/
Translation.java
File metadata and controls
58 lines (51 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
public class Translation {
private double[] transMat = new double[2];
private double worldSizeX;
private double worldSizeY;
private double xScaler;
private double yScaler;
// constructors
public Translation(double worldSizeX, double worldSizeY, double xScaler, double yScaler) {
this.worldSizeX = worldSizeX;
this.worldSizeY = worldSizeY;
this.xScaler = xScaler;
this.yScaler = yScaler;
}
public Translation(double[] m) {
transMat = m;
}
// setters
public void setXScaler(double xScaler) {
this.xScaler = xScaler;
}
public void setYScaler(double yScaler) {
this.yScaler = yScaler;
}
public void setWorld() {
transMat[0] = xScaler/worldSizeX;
transMat[1] = yScaler/worldSizeY;
}
public void addScalers(double xScaler, double yScaler) {
this.xScaler *= xScaler;
this.yScaler *= yScaler;
}
// getters
public double[] getMat() {
return transMat;
}
// multiplies two matrices for translating
public double[] translate(double[] input) {
double[] result = new double[2];
for (int i = 0; i < result.length; i++) {
result[i] = transMat[i] * input[i];
}
return result;
}
public double[] inverseTranslate(double[] input) {
double[] result = new double[2];
for (int i = 0; i < result.length; i++) {
result[i] = input[i] / transMat[i];
}
return result;
}
}