Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package celestial;
- import mainpkg.CPU;
- import setup.MakeWorld;
- import util.Methods;
- import com.jme3.math.ColorRGBA;
- import com.jme3.math.FastMath;
- import com.jme3.math.Vector3f;
- import com.jme3.renderer.queue.RenderQueue.Bucket;
- import com.jme3.renderer.queue.RenderQueue.ShadowMode;
- import com.jme3.scene.Geometry;
- import com.jme3.scene.Node;
- import com.jme3.scene.Spatial;
- import com.jme3.scene.shape.Quad;
- public class Nebula extends Node{
- float size;
- ColorRGBA template;
- public Nebula(Vector3f loc, float size, ColorRGBA col)
- {
- super();
- setLocalTranslation(loc);
- this.size = size;
- if(col != null)
- template = col; //predefined color
- else
- template = new ColorRGBA( //generates a random color
- FastMath.nextRandomFloat()*0.8f,
- FastMath.nextRandomFloat()*0.8f,
- FastMath.nextRandomFloat()*0.8f,
- 0f
- );
- }
- public void disable(){
- //delete untill rebuilt again
- if(getChildren().size() > 0)
- detachAllChildren();
- }
- public void enable(){
- if(getChildren().size() == 0)
- {
- //construct the nebula
- for (int i = 0; i < size/50; i++) {
- float rand1 = FastMath.nextRandomFloat()*FastMath.pow((size/75f), 1.85f);
- float rand2 = FastMath.nextRandomFloat()*FastMath.pow((size/75f), 1.85f);
- float rand3 = FastMath.nextRandomFloat()*FastMath.pow((size/75f), 1.85f);
- Quad side = new Quad(size,size);
- Geometry plate = new Geometry("plane",side);
- plate.setMaterial(MakeWorld.nebula.get(FastMath.rand.nextInt(MakeWorld.nebula.size())).clone());
- plate.setQueueBucket(Bucket.Transparent);
- plate.setLocalTranslation(-size/2+rand1, -size/2+rand2, rand3);
- plate.setShadowMode(ShadowMode.Off);
- Node n = new Node();
- n.attachChild(plate);
- n.getLocalRotation().fromAngleAxis(i*36, Methods.randomVector3f());
- attachChild(n);
- }
- }
- }
- public void cycle(float tpf)
- {
- Node temp = new Node();
- for (Spatial plate : getChildren()) {
- //get both vectors (don't ask)
- Vector3f one = plate.getLocalRotation().getRotationColumn(2);
- temp.setLocalTranslation(((Geometry)((Node)plate).getChild(0)).getWorldTranslation());
- temp.lookAt(CPU.game.getCamera().getLocation().mult(0.7f), Vector3f.UNIT_Y);
- Vector3f two = temp.getLocalRotation().getRotationColumn(2);
- //calculate opacity
- float opacity = FastMath.abs(one.dot(two))*0.75f;
- //set opacity
- ((Geometry)((Node)plate).getChild(0)).getMaterial()
- .setColor("Color", new ColorRGBA(template.r,template.g,template.b,opacity));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement