Point class

Well I tried to port my old spaceDust particle engine to jme and failed miserably. Probably because I dont understand jme quite right just yet, At wiki there was another class for creating spacedust, perhaps you could explain a part of the code for me. cause I simply dont get it.





Its the part with the 3 for loops. What is going on there. Why is Point clas given a big vertex of points. Does it draw several points?, and why put it in a 3X3X3 array?.. thanks


 public StarDust() {
        DisplaySystem display = DisplaySystem.getDisplaySystem();

        node = new Node("stardust");
        //
        // A star field
        //
        // in this first edition, just use the standard 'point' class
        // but in future would like to have a custom drawn one - where intensity
        // is related to distance?
        Random r = new Random();

        Vector3f[] vertexes = new Vector3f[numStars];
        ColorRGBA[] colors = new ColorRGBA[numStars];
        ColorRGBA color = new ColorRGBA(0.5f,0.5f,0.5f,0.5f);
        for (int x=0; x<numStars; ++x) {
            vertexes[x] = new Vector3f( (r.nextFloat())*blockSize,
                    (r.nextFloat())*blockSize,
                    (r.nextFloat())*blockSize);
           
            colors[x]= color;
        }






        for (int k=0; k<3; ++k) {
            for (int j=0; j<3; ++j) {
                for (int i=0; i<3; ++i) {
                    p[i][j][k] = new Point("stardust "+i+""+j+""+k, vertexes, null, colors, null);
                    p[i][j][k].setLocalTranslation(
                            new Vector3f((i-1)*blockSize, (j-1)*blockSize, (k-1)*blockSize));
                    p[i][j][k].setModelBound(new BoundingBox());
                    p[i][j][k].updateModelBound();
                    node.attachChild(p[i][j][k]);
                }
            }
        }

        // We don't want the light to affect our dust
        LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
        lightState.setEnabled(false);
        node.setRenderState(lightState);
        node.setLightCombineMode(LightState.REPLACE);
        node.updateWorldBound();
    }

I’m not sure about that wiki entry… but you would probably have better luck using the particle engine rather than a bunch of OpenGL points. Play with the particle editor to get the effect you desire, that will give you a code template you can then paste into your program.

not too sure. these points need to have 0 velocity and be spread out around the camera (fix points). Since the cam move the points should be reused. The particle emitter "emits" particles from a point, not distribute them randomly.

Ok, well, to answer your original question then. It appears to me (first time looking at it), that the above code generates 27 point objects arranged in a 3x3x3 cube. Each point entry is itself a cube of OpenGL points (where it contains a numStars amount of points).


Does it draw several points?


Yes, Point can contain any number of points grouped. One point per vertex assigned to the node.

thanks, makes sense now

Well after that hint I actually converted my code in 20 mins. Its not very effective but it creates a nice effect just like I want it.



Here it is if anyone wants it





/*
 * Created on 2004-09-06
 * This file is created for the Extorris game
 * and is copyrighted
 */
package com.extorris.effects;

import java.util.Random;

import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Controller;
import com.jme.scene.Node;
import com.jme.scene.Point;
import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem;



/**
 * This represents spacedust eg small particles in space.
 * It is used to give a point of reference and thus a feeling of movement.
 * Remember to make the spheresize beig enough so particles will appear outside
 * of camera depth. .
 * @author oliver billing
 *2004-09-06
 */
public class SpaceDustParticleSystem extends Controller  {
   
   private int maxParticles;
   private ColorRGBA color;
   private Vector3f[] points;
    private ColorRGBA[] colors;
   public Vector3f center;
   private Random rng;
   private float cubeSizeHalf;
   private int sphereSize;
    private Point point;
   
    public Node node;
   
   
   public SpaceDustParticleSystem(int maxParticles,int sphereSize,ColorRGBA color,Vector3f c) {
      

      points = new Vector3f[maxParticles];
        colors = new ColorRGBA[maxParticles];
      center  = c;
      cubeSizeHalf = sphereSize/2;
      rng = new Random();
   
      this.maxParticles=maxParticles;
      
      this.color=color;
      //drawable = new SpaceDustParticleSystemDrawable(this);
      this.sphereSize = sphereSize;
      //create vertextes
      for(int i=0;i<maxParticles;i++) {
            Vector3f pos = new Vector3f();
            pos.x =(center.x - (sphereSize/2)) + rng.nextFloat() * sphereSize;
            pos.y =(center.y - (sphereSize/2)) + rng.nextFloat() * sphereSize;
            pos.z =(center.z - (sphereSize/2)) + rng.nextFloat() * sphereSize;
            points[i] =pos;
            colors[i] = color;
      }
      
        point = new Point("Space dust",points,null,colors,null);
        node = new Node("dust");
        node.attachChild(point);
        // We don't want the light to affect our dust
        LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
        lightState.setEnabled(false);
        node.setRenderState(lightState);
        node.setLightCombineMode(LightState.REPLACE);
        node.updateWorldBound();
      
   }
   
   

    public void update(float time) {
       
        Vector3f[] pointPosArr = point.getVertices();
        //find all points that are outside box
          for(int i=0;i<maxParticles;i++){
              Vector3f pos= pointPosArr[i];
             
              if(pos.distance(center)>sphereSize/2){
                System.out.println("distance " +pos.distance(center));
                System.out.println("sphereSize/2 " +sphereSize/2);
                System.out.println("center " +center);
               
               
                    pos.x =(center.x - (sphereSize/2)) + rng.nextFloat() * sphereSize;
                    pos.y =(center.y - (sphereSize/2)) + rng.nextFloat() * sphereSize;
                    pos.z =(center.z - (sphereSize/2)) + rng.nextFloat() * sphereSize;
             
                }
                     
          }
   
    }
   


}



test class


/*
 * Created on 2005-02-28
 * This file is created for the Extorris game
 * and is copyrighted
 */
package com.extorris.test;

import com.extorris.effects.SpaceDustParticleSystem;
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.renderer.ColorRGBA;

/**
 * @author oliver
 *2005-02-28
 */
public class TestSpaceDust extends SimpleGame {
   
   
    SpaceDustParticleSystem st;

   
    protected void simpleUpdate() {
       // st.update(0);
       
        cam.setLocation(cam.getLocation().add(new Vector3f(0.1f,0f,0f),cam.getLocation()));
    }
   


   
    /* (non-Javadoc)
     * @see com.jme.app.SimpleGame#simpleInitGame()
     */
    protected void simpleInitGame() {
       
       
       
        display.setTitle("Test of space Dust");
       
        //stardust
        st = new SpaceDustParticleSystem(200,500,new ColorRGBA(1f,1f,1f,1f),cam.getLocation());
        rootNode.attachChild(st.node);
        rootNode.addController(st);
       
    }
   
    public static void main(String[] args) {
        TestSpaceDust app = new TestSpaceDust();
        app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
        app.start();
     }

}