diff options
| author | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-12 22:33:32 -0800 |
| commit | c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch) | |
| tree | df9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/scape/Motion.java | |
| download | worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip | |
Initial commit
Diffstat (limited to 'NET/worlds/scape/Motion.java')
| -rw-r--r-- | NET/worlds/scape/Motion.java | 398 |
1 files changed, 398 insertions, 0 deletions
diff --git a/NET/worlds/scape/Motion.java b/NET/worlds/scape/Motion.java new file mode 100644 index 0000000..9283376 --- /dev/null +++ b/NET/worlds/scape/Motion.java @@ -0,0 +1,398 @@ +package NET.worlds.scape; + +import NET.worlds.console.Console; +import java.io.IOException; +import java.text.MessageFormat; +import java.util.Date; + +class Motion extends TriggeredSwitchableBehavior implements FrameHandler, Persister, MouseDownHandler, BumpHandler { + long startMotionTime; + protected float cycleTime; + protected String frameList; + protected int cycles; + protected Transform motionTransform; + protected Point3 startPoint; + protected Point3 endPoint; + protected Point3 deltaPoint; + protected Point3 startScale; + protected Point3 endScale; + protected Point3 deltaScale; + protected Point3 startSpin; + protected Point3 endSpin; + protected Point3 currentSpin; + protected float startRotation; + protected float endRotation; + protected float currentRotation; + protected boolean motionTransformInitialized; + protected boolean variableInitialized; + protected boolean motionEnd = true; + + public Motion() { + this.cycleTime = 1000.0F; + this.trigger = new String("none"); + this.externalTriggerTag = new String(""); + this.cycles = 0; + this.motionTransformInitialized = false; + this.variableInitialized = false; + this.startPoint = new Point3(); + this.endPoint = new Point3(); + this.deltaPoint = new Point3(); + this.startScale = new Point3(); + this.endScale = new Point3(); + this.deltaScale = new Point3(); + this.startSpin = new Point3(); + this.endSpin = new Point3(); + this.currentSpin = new Point3(); + this.startMotion(); + } + + @Override + public void ExternalTrigger(Trigger trigger_source, int sequence_no, int event_no) { + this.trigger_source = trigger_source; + this.sequence_no = sequence_no; + this.event_no = event_no; + this.startMotion(); + } + + public boolean equivalent(Point3Temp a, Point3Temp b) { + return Math.round(a.x) == Math.round(b.x) && Math.round(a.y) == Math.round(b.y) && Math.round(a.z) == Math.round(b.z); + } + + public void startMotion() { + if (this.motionTransform != null + && this.equivalent(this.startPoint, this.motionTransform.getPosition()) + && Math.round(this.startScale.x) == Math.round(this.motionTransform.getTotalScale())) { + this.currentRotation = Math.round(this.motionTransform.getSpin(this.currentSpin)); + this.startRotation = Math.round(this.startRotation); + if ((this.startRotation == this.currentRotation || this.startRotation - 360.0F == this.currentRotation) + && this.equivalent(this.startSpin, this.currentSpin) + || (-this.startRotation == this.currentRotation || 360.0F - this.startRotation == this.currentRotation) + && this.equivalent(this.startSpin, this.currentSpin.negate())) { + Date timer = new Date(); + this.startMotionTime = timer.getTime(); + this.motionEnd = true; + } + } + } + + @Override + public boolean handle(FrameEvent e) { + if (!this.motionTransformInitialized) { + this.motionTransform = e.target; + this.motionTransformInitialized = true; + } + + if (!this.variableInitialized) { + this.startPoint.copy(this.motionTransform.getPosition()); + this.endPoint.copy(this.startPoint); + this.startScale.x = this.motionTransform.getTotalScale(); + this.startScale.y = this.motionTransform.getTotalScale(); + this.startScale.z = this.motionTransform.getTotalScale(); + this.endScale.copy(this.startScale); + this.startRotation = this.motionTransform.getSpin(this.startSpin); + this.endRotation = 0.0F; + this.variableInitialized = true; + } + + if (this.enabled) { + Date timer = new Date(); + long currentTime = timer.getTime(); + float frameLoc = (float)(-this.startMotionTime + currentTime) % this.cycleTime / this.cycleTime; + int cycleNo = (int)((float)(-this.startMotionTime + currentTime) / this.cycleTime); + if (cycleNo < this.cycles || this.cycles == 0 || !this.motionEnd) { + this.motionEnd = false; + if (cycleNo >= this.cycles && this.cycles != 0) { + this.motionEnd = true; + frameLoc = 1.0F; + if (this.trigger_source != null) { + this.trigger_source.registerFinishedTriggerTag(this.sequence_no, this.event_no); + } + } + + e.receiver.makeIdentity(); + e.receiver + .scale( + this.startScale.x + (this.endScale.x - this.startScale.x) * frameLoc, + this.startScale.x + (this.endScale.x - this.startScale.x) * frameLoc, + this.startScale.x + (this.endScale.x - this.startScale.x) * frameLoc + ); + e.receiver + .moveTo( + this.startPoint.x + (this.endPoint.x - this.startPoint.x) * frameLoc, + this.startPoint.y + (this.endPoint.y - this.startPoint.y) * frameLoc, + this.startPoint.z + (this.endPoint.z - this.startPoint.z) * frameLoc + ); + e.receiver.spin(this.startSpin, this.startRotation); + e.receiver.spin(this.endSpin, this.endRotation * frameLoc); + } + } + + return true; + } + + @Override + public boolean handle(MouseDownEvent e) { + if (this.enabled && this.trigger.equals("click")) { + this.startMotion(); + } + + return true; + } + + @Override + public boolean handle(BumpEventTemp e) { + if (this.enabled && this.trigger.equals("bump")) { + this.startMotion(); + } + + return true; + } + + public void startTransform() { + if (this.motionTransform != null) { + this.motionTransform.makeIdentity(); + this.motionTransform.scale(this.startScale.x, this.startScale.x, this.startScale.x); + this.motionTransform.moveTo(this.startPoint.x, this.startPoint.y, this.startPoint.z); + this.motionTransform.spin(this.startSpin, this.startRotation); + } else { + System.out.println("motionTransform is null!!!!"); + } + } + + public void endTransform() { + if (this.motionTransform != null) { + this.motionTransform.makeIdentity(); + this.motionTransform.scale(this.endScale.x, this.endScale.x, this.endScale.x); + this.motionTransform.moveTo(this.endPoint.x, this.endPoint.y, this.endPoint.z); + this.motionTransform.spin(this.startSpin, this.startRotation); + this.motionTransform.spin(this.endSpin, this.endRotation); + } else { + System.out.println("motionTransform is null!!!!"); + } + } + + @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 = new ClassProperty(this, index, "Motion"); + } + break; + case 1: + 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 2: + if (mode == 0) { + ret = IntegerPropertyEditor.make(new Property(this, index, "Cycles")); + } else if (mode == 1) { + ret = new Integer(this.cycles); + } else if (mode == 2) { + this.cycles = (Integer)value; + } + break; + case 3: + if (mode == 0) { + ret = StringPropertyEditor.make(new Property(this, index, "Trigger")); + } else if (mode == 1) { + ret = new String(this.trigger); + } else if (mode == 2) { + this.trigger = ((String)value).toString().trim(); + if (this.trigger.equals("external")) { + Trigger.TriggeredSwitchableBehaviorList[Trigger.TriggeredSwitchableBehaviorListCount] = this; + Trigger.TriggeredSwitchableBehaviorListCount++; + } + } + break; + case 4: + if (mode == 0) { + ret = StringPropertyEditor.make(new Property(this, index, "External Trigger Tag")); + } else if (mode == 1) { + ret = new String(this.externalTriggerTag); + } else if (mode == 2) { + this.externalTriggerTag = ((String)value).toString().trim(); + } + break; + case 5: + if (mode == 0) { + ret = Point3PropertyEditor.make(new Property(this, index, "End Point")); + } else if (mode == 1) { + ret = new Point3(this.endPoint); + this.endTransform(); + } else if (mode == 2) { + this.endPoint.copy((Point3)value); + this.endTransform(); + } + break; + case 6: + if (mode == 0) { + ret = Point3PropertyEditor.make(new Property(this, index, "Start Point")); + } else if (mode == 1) { + ret = new Point3(this.startPoint); + this.startTransform(); + } else if (mode == 2) { + this.startPoint.copy((Point3)value); + this.startTransform(); + } + break; + case 7: + if (mode == 0) { + ret = Point3PropertyEditor.make(new Property(this, index, "End Scale")); + } else if (mode == 1) { + ret = new Point3(this.endScale); + this.endTransform(); + } else if (mode == 2) { + this.endScale.copy((Point3)value); + this.endTransform(); + } + break; + case 8: + if (mode == 0) { + ret = Point3PropertyEditor.make(new Property(this, index, "Start Scale")); + } else if (mode == 1) { + ret = new Point3(this.startScale); + this.startTransform(); + } else if (mode == 2) { + this.startScale.copy((Point3)value); + this.startTransform(); + } + break; + case 9: + if (mode == 0) { + ret = Point3PropertyEditor.make(new Property(this, index, "End Spin (Relative)")); + } else if (mode == 1) { + ret = new Point3(this.endSpin); + this.endTransform(); + } else if (mode == 2) { + this.endSpin.copy((Point3)value); + this.endTransform(); + } + break; + case 10: + if (mode == 0) { + ret = Point3PropertyEditor.make(new Property(this, index, "Start Spin")); + } else if (mode == 1) { + ret = new Point3(this.startSpin); + this.startTransform(); + } else if (mode == 2) { + this.startSpin.copy((Point3)value); + this.startTransform(); + } + break; + case 11: + if (mode == 0) { + ret = FloatPropertyEditor.make(new Property(this, index, "End Rotation (Relative)")); + } else if (mode == 1) { + ret = new Float(this.endRotation); + this.endTransform(); + } else if (mode == 2) { + this.endRotation = (Float)value; + this.endTransform(); + } + break; + case 12: + if (mode == 0) { + ret = FloatPropertyEditor.make(new Property(this, index, "Start Rotation")); + } else if (mode == 1) { + ret = new Float(this.startRotation); + this.startTransform(); + } else if (mode == 2) { + this.startRotation = (Float)value; + this.startTransform(); + } + break; + default: + ret = super.properties(index, offset + 13, mode, value); + } + + if (mode == 2 && this.trigger.equals("none")) { + this.startMotion(); + } + + return ret; + } + + @Override + public String toString() { + return "Motion: cycleTime " + + this.cycleTime + + ", cycles " + + this.cycles + + ", enabled " + + this.enabled + + ", trigger " + + this.trigger + + ", externalTriggerTag " + + this.externalTriggerTag; + } + + @Override + public void saveState(Saver s) throws IOException { + s.saveFloat(this.cycleTime); + s.saveInt(this.cycles); + s.saveString(this.trigger); + s.saveString(this.externalTriggerTag); + this.endPoint.saveState(s); + this.startPoint.saveState(s); + this.endScale.saveState(s); + this.startScale.saveState(s); + this.endSpin.saveState(s); + this.startSpin.saveState(s); + s.saveFloat(this.endRotation); + s.saveFloat(this.startRotation); + } + + @Override + public void restoreState(Restorer r) throws IOException { + this.cycleTime = r.restoreFloat(); + this.cycles = r.restoreInt(); + this.trigger = r.restoreString(); + if (this.trigger.equals("external")) { + Trigger.TriggeredSwitchableBehaviorList[Trigger.TriggeredSwitchableBehaviorListCount] = this; + Trigger.TriggeredSwitchableBehaviorListCount++; + } + + this.externalTriggerTag = r.restoreString(); + + try { + this.endPoint.restoreState(r); + this.startPoint.restoreState(r); + this.endScale.restoreState(r); + this.startScale.restoreState(r); + this.endSpin.restoreState(r); + this.startSpin.restoreState(r); + } catch (Exception var3) { + } + + this.endRotation = r.restoreFloat(); + this.startRotation = r.restoreFloat(); + this.variableInitialized = true; + if (!this.trigger.equals("none")) { + this.startMotionTime = (int)(-(this.cycles * this.cycleTime)); + } else { + this.startMotion(); + } + } + + @Override + public void postRestore(int version) { + String name = this.getName(); + String arg1 = name == null ? "<null>" : name; + SuperRoot owner = this.getOwner(); + String oname = ""; + if (owner != null) { + oname = owner.getName(); + } + + String arg2 = oname == null ? "<null>" : oname; + Object[] arguments = new Object[]{new String(arg1), new String(arg2)}; + Console.println(MessageFormat.format(Console.message("Motion-obs"), arguments)); + } +} |