-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslation.java
More file actions
45 lines (41 loc) · 1.22 KB
/
Translation.java
File metadata and controls
45 lines (41 loc) · 1.22 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
public class Translation {
private double[][] transMat = new double[2][2];
private double worldSizeX;
private double worldSizeY;
// constructors
public Translation(double worldSizeX, double worldSizeY) {
this.worldSizeX = worldSizeX;
this.worldSizeY = worldSizeY;
}
public Translation(double[][] m) {
transMat = m;
}
// setters
public void setMat(double xScaler, double yScaler) {
transMat[0][0] = xScaler;
transMat[1][1] = yScaler;
}
public void setWorld(double xScaler, double yScaler) {
transMat[0][0] = xScaler/worldSizeX;
transMat[1][1] = yScaler/worldSizeY;
}
// getters
public double[][] getMat() {
return transMat;
}
// multiplies two matrices for translating
public int[] translate(int[] input) {
int[] result = new int[2];
for (int i = 0; i < result.length; i++) {
result[i] = multiplycell(input, i);
}
return result;
}
public int multiplycell(int[] input, int col) {
double cell = 0.0;
for (int i = 0; i < transMat.length; i++) {
cell += input[i] * transMat[i][col];
}
return (int)cell;
}
}