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(); } } }