Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package celestial.support;
- import com.jme3.material.Material;
- import com.jme3.math.ColorRGBA;
- import com.jme3.math.FastMath;
- import com.jme3.math.Vector3f;
- import com.jme3.scene.Node;
- import com.jme3.scene.Spatial;
- import com.jme3.scene.shape.Sphere;
- import com.jme3.texture.Texture;
- import com.jme3.util.TangentBinormalGenerator;
- import celestial.AsteroidField;
- import celestial.Nebula;
- import celestial.Planet;
- import celestial.Star;
- import celestial.Star.Type;
- import setup.MakeWorld;
- import station.SpaceStation;
- import util.Methods;
- public class PlanetarySystemData extends Node{
- public enum Danger{
- None, Minimal, Medium, High, Extreme
- }
- public static Sphere ultra, high, medium;
- public String tag;
- public Star.Type startype;
- public Vector3f loc;
- private SpaceStation[] spesteshun;
- public static void init(){
- ultra = new Sphere(128,128,1, true, false);
- high = new Sphere(96,96,1, true, false);
- medium = new Sphere(64,64,1, true, false);
- TangentBinormalGenerator.generate(ultra);
- TangentBinormalGenerator.generate(high);
- TangentBinormalGenerator.generate(medium);
- }
- public PlanetarySystemData(int x, int y, int z, String tag, Node[] predefined, Type type)
- {
- loc = new Vector3f(x,y,z);
- this.tag = tag;
- for (int i = 0; i < predefined.length; i++)
- attachChild(predefined[i]);
- startype = type;
- }
- public PlanetarySystemData(int x, int y, int z, String tag){
- this(x,y,z,tag,randomStarType());
- }
- public PlanetarySystemData(int x, int y, int z, String tag, Type type)
- {
- loc = new Vector3f(x,y,z);
- this.tag = tag;
- generatePlanets();
- SpaceObject p = (SpaceObject)getChild(FastMath.nextRandomInt(0, getChildren().size()-1));
- float k = 2.5f;
- if(p instanceof Nebula)
- k = 1.5f;
- SpaceStation st = new SpaceStation(p.getLocalTranslation().add(Methods.randomVector3f().multLocal(p.getSize()*k)));
- if(st.getLocalTranslation().length() < 50000)
- st.setLocalTranslation(st.getLocalTranslation().normalize().multLocal(80000));
- attachChild(st);
- spesteshun = new SpaceStation[1];
- spesteshun[0] = st;
- attachChild(new Star(tag, type));
- startype = type;
- }
- private static Type randomStarType() {
- switch(FastMath.nextRandomInt(0, 7)){
- case 0: return Star.Type.BlueGiant;
- case 1: return Star.Type.Pulsar;
- case 2: return Star.Type.Singularity;
- case 3: return Star.Type.WhiteDwarf;
- case 4: return Star.Type.RedGiant;
- case 5: return Star.Type.Singularity;
- case 6: return Star.Type.MainSequence;
- default: return Star.Type.Singularity;
- }
- }
- private void generatePlanets() {
- int count = FastMath.rand.nextInt(6)+5;
- int nebcount = 0;
- while(count > 0)
- {
- int type = FastMath.rand.nextInt(4);
- while(nebcount >= 2 && type == 2)
- type = FastMath.rand.nextInt(4);
- int size;
- if(type == 1)
- size = FastMath.rand.nextInt(3000)+3000;
- else if(type == 2){
- size = FastMath.rand.nextInt(6000)+19000;
- nebcount++;
- }else
- size = FastMath.rand.nextInt(3000)+500;
- Vector3f loc = new Vector3f(
- FastMath.rand.nextFloat()*450000-225000,
- FastMath.rand.nextFloat()*150000-75000,
- FastMath.rand.nextFloat()*450000-252000
- );
- boolean clear = true;
- for (Spatial object : getChildren()) {
- Vector3f vec = null;
- if(object instanceof Planet)
- vec = ((Planet)object).getLocalTranslation();
- else if (object instanceof Nebula)
- vec = ((Nebula)object).getLocalTranslation();
- else if (object instanceof AsteroidField)
- vec = ((AsteroidField)object).getLocalTranslation();
- if(loc.distance(vec) < 60000)
- clear = false;
- }
- if(type != 2 && loc.length() < 60000)
- clear = false;
- if(clear)
- {
- if(type == 2)
- {
- attachChild(new Nebula(loc,size*(FastMath.nextRandomFloat()/3+0.9f),Methods.randomColor().mult(0.8f)));
- count--;
- }
- else
- {
- /* if(FastMath.nextRandomInt(0, 4) == 0 && !asteroidfield)
- {
- attachChild(new AsteroidField(loc,size*2,size/20));
- asteroidfield = true;
- }
- else*/
- {
- Sphere Lod = getpolycount(size);
- Material ground = getMaterial(type);
- ColorRGBA col = randomRGBA();
- Planet planet = new Planet(loc.x,loc.y,loc.z,size,Lod,ground,getRings(type),tag,(float)(Math.random()/10)+0.001f,setAtmo(ground),col,col.mult(0.8f),this);
- attachChild(planet);
- }
- count--;
- }
- }
- }
- }
- private ColorRGBA randomRGBA() {
- return new ColorRGBA(FastMath.nextRandomFloat(),FastMath.nextRandomFloat(),FastMath.nextRandomFloat(),1);
- }
- private Texture setAtmo(Material m1) {
- if(m1.getName() != null && m1.getName().equals("atmo"))
- return MakeWorld.atmosimg.get((int)(Math.random()*MakeWorld.atmosimg.size()));
- return null;
- }
- private Material getRings(int type) {
- if(type == 1)
- {
- if((int)(Math.random()*2) == 0)
- return MakeWorld.rings.get((int)(Math.random()*MakeWorld.rings.size()));
- else
- return null;
- }
- else
- {
- if((int)(Math.random()*5) == 0)
- return MakeWorld.rings.get((int)(Math.random()*MakeWorld.rings.size()));
- else
- return null;
- }
- }
- public void disablePhy(){
- for (Spatial celestial : getChildren()) {
- if(celestial instanceof SpaceObject)
- ((SpaceObject)celestial).disable();
- }
- }
- public void enablePhy(){
- for (Spatial celestial : getChildren()) {
- if(celestial instanceof SpaceObject)
- ((SpaceObject)celestial).enable();
- }
- }
- private Material getMaterial(int type) {
- if(type == 1)
- return MakeWorld.gass.get((int)(Math.random()*MakeWorld.gass.size()));
- return MakeWorld.rocky.get((int)(Math.random()*MakeWorld.rocky.size()));
- }
- private Sphere getpolycount(int size) {
- if(size > 3000)
- return ultra;
- if(size > 2000)
- return high;
- return medium;
- }
- public String toString(){
- return "["+tag+" x:"+loc.x+" y:"+loc.y+" z:"+loc.z+"]";
- }
- public SpaceStation[] getStation(){
- return spesteshun;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment