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
package sample;
import javafx.scene.Scene;
import javafx.scene.input.KeyCode;
public class _transform {
private double[][] m;
private double[] p;
private double ax, ay;
public _transform() {
angle(0, 0);
position(0, 0, 0);
}
public void angle(double ax, double ay) {
this.ax = ax; this.ay = ay;
ax *= Math.PI / 180; ay *= Math.PI / 180;
double sx = Math.sin(ax), cx = Math.cos(ax);
double sy = Math.sin(ay), cy = Math.cos(ay);
m = new double[][] {
{ cy, sx * sy, -cx * sy },
{ 0, cx, sx },
{ sy, -sx * cy, cx * cy }};
}
public void position(double x, double y, double z) {
p = new double[] { x, y, z };
}
public double[] mul(double x, double y, double z) {
x += p[0]; y += p[1]; z += p[2];
double[] v = new double[3];
for (int i = 0; i < 3; i++)
v[i] = m[0][i] * x + m[1][i] * y + m[2][i] * z;
return v;
}
public static interface _angle_listener {
public void angle_changed();
}
public void add_angle_listener(Scene scene, _angle_listener lis) {
scene.setOnKeyPressed((e) -> {
KeyCode key = e.getCode();
switch (key) {
case UP: angle(this.ax + 5, this.ay); break;
case DOWN: angle(this.ax - 5, this.ay); break;
case LEFT: angle(this.ax, this.ay + 5); break;
case RIGHT: angle(this.ax, this.ay - 5); break;
default: return;
}
lis.angle_changed();
});
}
}