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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
package NET.worlds.scape;
import java.io.IOException;
public class SpinBehavior extends SwitchableBehavior implements FrameHandler {
protected float cycleTime;
protected float ax;
protected float ay;
protected float az;
private static Object classCookie = new Object();
public SpinBehavior() {
this(5.0F);
}
public SpinBehavior(float cycleTime) {
this(cycleTime, 0.0F, 0.0F, 1.0F);
}
public SpinBehavior(Point3Temp axis) {
this(5.0F, axis);
}
public SpinBehavior(float ax, float ay, float az) {
this(5.0F, ax, ay, az);
}
public SpinBehavior(float cycleTime, Point3Temp axis) {
this(cycleTime, axis.x, axis.y, axis.z);
}
public SpinBehavior(float cycleTime, float ax, float ay, float az) {
this.cycleTime = cycleTime;
this.ax = ax;
this.ay = ay;
this.az = az;
}
public float getCycleTime() {
return this.cycleTime;
}
public void setCycleTime(float t) {
this.cycleTime = t;
}
public Point3Temp getAxis() {
return Point3Temp.make(this.ax, this.ay, this.az);
}
public void setAxis(Point3Temp axis) {
this.ax = axis.x;
this.ay = axis.y;
this.az = axis.z;
}
@Override
public boolean handle(FrameEvent e) {
if (this.enabled && this.cycleTime > 0.0F) {
e.receiver.spin(this.ax, this.ay, this.az, 0.36F * e.dt / this.cycleTime);
}
return true;
}
@Override
public Object properties(int index, int offset, int mode, Object value) throws NoSuchPropertyException {
Object ret = null;
switch (index - offset) {
case 0:
if (mode == 0) {
ret = FloatPropertyEditor.make(new Property(this, index, "Cycle Time"));
} else if (mode == 1) {
ret = new Float(this.cycleTime);
} else if (mode == 2) {
this.cycleTime = (Float)value;
}
break;
case 1:
if (mode == 0) {
ret = Point3PropertyEditor.make(new Property(this, index, "Axis"));
} else if (mode == 1) {
ret = new Point3(this.getAxis());
} else if (mode == 2) {
this.setAxis((Point3)value);
}
break;
default:
ret = super.properties(index, offset + 2, mode, value);
}
return ret;
}
@Override
public String toString() {
return super.toString() + "[axis " + this.getAxis() + ", cycleTime " + this.cycleTime + ", enabled " + this.enabled + "]";
}
@Override
public void saveState(Saver s) throws IOException {
s.saveVersion(0, classCookie);
s.saveFloat(this.cycleTime);
s.saveFloat(this.ax);
s.saveFloat(this.ay);
s.saveFloat(this.az);
}
@Override
public void restoreState(Restorer r) throws IOException, TooNewException {
switch (r.restoreVersion(classCookie)) {
case 0:
this.cycleTime = r.restoreFloat();
this.ax = r.restoreFloat();
this.ay = r.restoreFloat();
this.az = r.restoreFloat();
return;
default:
throw new TooNewException();
}
}
}
|