package javara.world.environment;
import javara.world.VisibleObject;
import javara.world.World;
import com.jme3.light.DirectionalLight;
import com.jme3.light.Light;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Sphere;
public class Celestial extends VisibleObject {
protected DirectionalLight light;
protected float azimuth, elevation, radius;
protected boolean visible;
protected Material starMat;
public static float celestialScale = 45.0f;
public static float celestialDistance = 1000.0f * 255.0f / 256.0f;
public Celestial(World world, ColorRGBA color, float intensity, float azimuth, float elevation, float radius, boolean visible) {
super(color);
this.azimuth = azimuth;
this.elevation = elevation;
this.radius = radius;
this.visible = visible;
if (intensity > 0) {
light = new DirectionalLight();
light.setColor(color.mult(intensity));
light.setDirection(World.toCartesian(azimuth, elevation, 1).negate());
}
}
public void attachedToWorld() {
// Visible celestials do not get added to World.rootNode like other objects. Instead, they
// should be added as children of Sky.
if (visible) {
starMat = new Material(world.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
starMat.setColor("Color", color);
starMat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
Geometry geom = new Geometry(identifier, new Sphere(16, 16, celestialScale * radius));
geom.setMaterial(starMat);
geom.setLocalTranslation(World.toCartesian(azimuth, elevation, celestialDistance));
world.getSky().addCelestialSpatial(geom);
}
}
public Light getLight() {
return light;
}
}