if (attrs.getValue("size") != null)
size = Float.parseFloat(attrs.getValue("size"));
if (attrs.getValue("visible") != null)
visible = parseBoolean(attrs.getValue("visible"));
Celestial cel = new Celestial(world, color, intensity, azimuth, elevation, size, visible);
world.addWorldObject(cel);
if (intensity > 0)
numLights++;
}
else if (localName.equalsIgnoreCase("starfield")) {
long seed = world.getName().hashCode();
int count = 500;
boolean monochrome = false;
ColorRGBA minColor = ColorRGBA.White;
ColorRGBA maxColor = ColorRGBA.White;
float minSize = 0.025f;
float maxSize = 0.025f;
if (attrs.getValue("seed") != null)
seed = Long.parseLong(attrs.getValue("seed"));
if (attrs.getValue("count") != null)
count = Integer.parseInt(attrs.getValue("count"));
if (attrs.getValue("monochrome") != null)
monochrome = parseBoolean(attrs.getValue("monochrome"));
if (attrs.getValue("minColor") != null)
minColor = parseColor(attrs.getValue("minColor"));
if (attrs.getValue("maxColor") != null)
maxColor = parseColor(attrs.getValue("maxColor"));
if (attrs.getValue("minSize") != null)
minSize = Float.parseFloat(attrs.getValue("minSize"));
if (attrs.getValue("maxSize") != null)
minSize = Float.parseFloat(attrs.getValue("maxSize"));
Random rand = new Random(seed);
float minR = minColor.r;
float deltaR = maxColor.r - minR;
float minG = minColor.g;
float deltaG = maxColor.g - minG;
float minB = minColor.b;
float deltaB = maxColor.b - minB;
for (int i = 0; i < count; i++) {
// Note: in order to end up with an even distribution of stars, we can't just
// use two raw random numbers.
// We need to scale them such that tere are fewer stars near the poles than near
// the equator.
// The following lines should result in an even distribution.
float theta = FastMath.TWO_PI * rand.nextFloat();
float phi = FastMath.abs(FastMath.HALF_PI - FastMath.acos(rand.nextFloat()));
float r, g, b;
if (monochrome) {
float dice = rand.nextFloat();
r = minR + dice * deltaR;
g = minG + dice * deltaG;
b = minB + dice * deltaB;
}
else {
r = minR + rand.nextFloat() * deltaR;
g = minG + rand.nextFloat() * deltaG;
b = minB + rand.nextFloat() * deltaB;
}
ColorRGBA color = new ColorRGBA(r, g, b, (phi / FastMath.HALF_PI));
float size = minSize + rand.nextFloat() * (maxSize - minSize);
Celestial cel = new Celestial(world, color, 0.0f, theta, phi, size, true);
world.addWorldObject(cel);
}
}
else if (localName.equalsIgnoreCase("incarnator")) {
Vector3f location;