summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/MoveCameraAction.java
blob: d77258845c6af68cb7607d6322bd603184468a93 (plain) (blame)
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
package NET.worlds.scape;

import NET.worlds.core.Std;
import java.util.Enumeration;

public class MoveCameraAction extends MoveAction {
   private static Object classCookie = new Object();

   @Override
   public Persister trigger(Event e, Persister seqID) {
      Pilot pl = Pilot.getActive();
      if (!(pl instanceof HoloPilot)) {
         return null;
      } else {
         HoloPilot holo = (HoloPilot)pl;
         holo.releaseCamera();
         Object owner = holo.getCamera();
         if (owner != null && owner instanceof WObject) {
            WObject o = (WObject)owner;
            if (this.killed) {
               this.killed = false;
               this.activeID = null;
               holo.reclaimCamera();
               return null;
            } else {
               if (seqID == null) {
                  if (this.activeID != null) {
                     return this.activeID;
                  }

                  if (this.killOthers) {
                     Enumeration acts = o.getActions();

                     while (acts.hasMoreElements()) {
                        Action a = (Action)acts.nextElement();
                        if (a != this && a instanceof MoveAction) {
                           MoveAction ma = (MoveAction)a;
                           if (ma.isRunning()) {
                              ma.kill();
                           }
                        }
                     }
                  }

                  this.startTime = Std.getRealTime();
                  this.activeID = new SuperRoot();
                  seqID = this.activeID;
               }

               if (seqID != this.activeID) {
                  return null;
               } else {
                  int currentTime = Std.getRealTime();
                  int cycleNo = (currentTime - this.startTime) / this.cycleTime;
                  float frameLoc = 1.0F;
                  if (cycleNo >= this.cycles && !this.loopInfinite) {
                     System.out.println("Killing MoveCameraAction.  loopInfinite = " + this.loopInfinite);
                     this.activeID = null;
                  } else {
                     frameLoc = (float)((currentTime - this.startTime) % this.cycleTime) / this.cycleTime;
                  }

                  o.makeIdentity();
                  o.spin(this.extentSpin, this.extentRotation * frameLoc);
                  o.spin(this.startSpin, this.startRotation);
                  Point3Temp p = Point3Temp.make(
                     (float)Math.pow(this.extentScale.x, frameLoc),
                     (float)Math.pow(this.extentScale.y, frameLoc),
                     (float)Math.pow(this.extentScale.z, frameLoc)
                  );
                  o.scale(p.times(this.startScale));
                  o.moveTo(Point3Temp.make(this.extentPoint).times(frameLoc).plus(this.startPoint));
                  if (this.activeID == null) {
                     holo.reclaimCamera();
                  }

                  return this.activeID;
               }
            }
         } else {
            return null;
         }
      }
   }
}