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.
/**
* 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();
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];
//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();
}