summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/SpinBehavior.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/SpinBehavior.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/scape/SpinBehavior.java')
-rw-r--r--NET/worlds/scape/SpinBehavior.java122
1 files changed, 122 insertions, 0 deletions
diff --git a/NET/worlds/scape/SpinBehavior.java b/NET/worlds/scape/SpinBehavior.java
new file mode 100644
index 0000000..92be2d4
--- /dev/null
+++ b/NET/worlds/scape/SpinBehavior.java
@@ -0,0 +1,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();
+ }
+ }
+}