summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/BoxBumpCalc.java
blob: 06e6c50a1486e7cf9e8a01fb51453ec1421a08b0 (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
package NET.worlds.scape;

import java.io.IOException;

public class BoxBumpCalc extends BumpCalc {
   private static Object classCookie = new Object();

   @Override
   public void detectBump(BumpEventTemp b, WObject owner) {
      BoundBoxTemp box = owner.getBoundBox();
      BoundBoxTemp sourceBox = ((WObject)b.source).getBoundBox();
      box.lo.minus(sourceBox.hi.minus(b.sourceAt));
      box.hi.minus(sourceBox.lo.minus(b.sourceAt));
      Point3Temp pos = Point3Temp.make();
      pos.x = box.lo.x;
      pos.y = box.lo.y;
      float xExtent = box.hi.x - box.lo.x;
      float yExtent = box.hi.y - box.lo.y;
      Point3Temp d = Point3Temp.make(xExtent, 0.0F, 0.0F);
      Point3Temp extent = Point3Temp.make(0.0F, yExtent / 2.0F, 0.0F);
      if (!b.hitTriRegion(owner, pos, d, extent)) {
         pos.x = box.hi.x;
         pos.y = box.hi.y;
         d.x = -d.x;
         extent.y = -extent.y;
         if (!b.hitTriRegion(owner, pos, d, extent)) {
            pos.y = box.lo.y;
            d.y = yExtent;
            d.x = 0.0F;
            extent.x = -xExtent / 2.0F;
            extent.y = 0.0F;
            if (!b.hitTriRegion(owner, pos, d, extent)) {
               pos.x = box.lo.x;
               pos.y = box.hi.y;
               d.y = -d.y;
               extent.x = -extent.x;
               if (!b.hitTriRegion(owner, pos, d, extent)) {
                  ;
               }
            }
         }
      }
   }

   @Override
   public void saveState(Saver s) throws IOException {
      s.saveVersion(0, classCookie);
      super.saveState(s);
   }

   @Override
   public void restoreState(Restorer r) throws IOException, TooNewException {
      switch (r.restoreVersion(classCookie)) {
         case 0:
            super.restoreState(r);
            return;
         default:
            throw new TooNewException();
      }
   }
}