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