summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/DiskShadow.java
blob: 603ad7569df4c79a858e207280cb6d9d2ac11f79 (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.awt.Color;

public class DiskShadow extends Polygon implements NonPersister, Shadow {
   private static int numSides = 8;
   private static float[] diskVertices = new float[5 * numSides];

   static {
      float radius = 0.5F;
      int end = 5 * numSides;
      double angle = 0.0;
      double angleInc = (float)((Math.PI * 2) / numSides);

      for (int i = 0; i < end; angle += angleInc) {
         float x = (float)Math.cos(angle);
         float y = (float)Math.sin(angle);
         diskVertices[i + 0] = radius * x;
         diskVertices[i + 1] = radius * y;
         diskVertices[i + 2] = 0.0F;
         diskVertices[i + 3] = 0.5F + 0.5F * x;
         diskVertices[i + 4] = 0.5F + 0.5F * y;
         i += 5;
      }
   }

   public DiskShadow(WObject caster) {
      super(diskVertices, new Material(0.0F, 0.0F, 0.0F, Color.black, null, 0.5F, false, false));
      this.setBumpable(false);
      this.adjustShadow(caster);
   }

   @Override
   public void adjustShadow(WObject caster) {
      Room r = caster.getRoom();
      if (caster.getVisible() && r != null) {
         float defSize = 0.0F;
         float size = caster.getMinXYExtent();
         BoundBoxTemp box = caster.getBoundBox();
         if (!(size <= 0.0F) && !(size > 10000.0F) && !(box.hi.z < 0.0F) && !(box.lo.z >= 250.0F)) {
            float shadowFrac = 1.0F;
            if (box.lo.z > 0.0F) {
               shadowFrac = 1.0F - box.lo.z / 250.0F;
            }

            if (this.getOwner() == null && r != null) {
               r.getEnvironment().add(this);
            }

            Point3Temp xyz = caster.getWorldPosition();
            this.moveTo(xyz.x, xyz.y, r.floorHeight(xyz.x, xyz.y, xyz.z) + 0.5F);
            this.yaw(this.getYaw() - caster.getYaw());
            this.scale(size * shadowFrac / this.getScaleX());
         } else {
            this.detach();
         }
      } else {
         this.detach();
      }
   }
}