Package org.pollux3d.map

Source Code of org.pollux3d.map.Sun

package org.pollux3d.map;

import org.pollux3d.cam.CamTarget;
import org.pollux3d.core.Pollux;
import org.pollux3d.menu.CircleMarker;
import org.pollux3d.menu.Markable;

import com.jme3.asset.AssetManager;
import com.jme3.effect.EmitterPointShape;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh.Type;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.material.RenderState.FaceCullMode;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue.ShadowMode;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Sphere;



public class Sun extends MapEntity implements CamTarget, Markable {
 
  private Geometry sun;
  private AssetManager assetManager;
  private Markable marker;
  private PointLight light;
  private int size = 120;

  public Sun(String name) {
    super(name);
    this.assetManager = Pollux.get().getAssetManager();
    genSunClickGeo();
    this.attachChild(getEmitter("part_"+name));
    Pollux.get().getGeometryManager().registerGeometry(sun, this);
    this.attachChild(sun);
    marker = new CircleMarker(size*0.8f, size*0.02f, ColorRGBA.White);
    //marker.rotate(0, FastMath.PI, FastMath.PI);
    //marker.hide();
    //marker = new QuadMarker(size);
    this.attachChild((Spatial)marker);
  }
 
  public PointLight getLight() {
    light = new PointLight();
    light.setColor(ColorRGBA.White);
    light.setRadius(400000f);
    light.setPosition(this.getLocalTranslation());
    return light;
  }
 
  private void genSunClickGeo() {
    Sphere s = new Sphere(16, 16, size);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md");
    mat.setColor("Color", ColorRGBA.Yellow);
    mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack);
      sun = new Geometry("geo_"+name, s);
      sun.setMaterial(mat);
      sun.setShadowMode(ShadowMode.Off);
     
  }
 
  private ParticleEmitter getEmitter(String name) {
    ParticleEmitter flame = new ParticleEmitter(name, Type.Triangle, 32);
        flame.setSelectRandomImage(false);
        flame.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, 1f));
        flame.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
        flame.setStartSize(size);
        flame.setEndSize(size);
        //flame.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
        flame.setShape(new EmitterPointShape(Vector3f.ZERO));
        flame.setParticlesPerSec(20);
        flame.setGravity(-5f);
        flame.setLowLife(1f);
        flame.setHighLife(1.5f);
        //flame.setInitialVelocity(new Vector3f(0, 7, 0));
        flame.setRandomAngle(true);
        flame.setInitialVelocity(new Vector3f(0, 3, 0));
        //flame.setVelocityVariation(1f);
        flame.setVelocityVariation(1.5f);
        flame.setImagesX(8);
        flame.setImagesY(1);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        //mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
        mat.setTexture("Texture", assetManager.loadTexture("Textures/d3.png"));
        mat.setBoolean("PointSprite", true);
        flame.setMaterial(mat);
        //flame.setLocalTranslation(100, 0, 0);
        return flame;
  }
 
  public float getZoomDistance() {
    return 2000;
  }

  public void hideMark() {
    marker.hideMark();
  }

  public void showMark() {
    marker.showMark();
  }

}
TOP

Related Classes of org.pollux3d.map.Sun

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.