A Fountain of Lines
The LineParticles class implements a particle system made up of yellow and red lines, which shoot out from the origin with parabolic trajectories. The effect, as seen in Figure 21-2, is something like a firework. The thickness of the lines is increased slightly, and anti-aliasing is switched on. When a line has completely dropped below the y-axis, it's reinitialized, which means the firework never runs out.
The main difference from PointParticles is the extra code required to initialize the lines and update them inside the float arrays. Six values in a float array are necessary to represent a single line, three values for each of the two end points.
The LineParticles constructor creates a LineArray object using BY_REFERENCE geometry for its coordinates and color:
lineParts = new LineArray(numPoints, LineArray.COORDINATES |
LineArray.COLOR_3 | LineArray.BY_REFERENCE );
lineParts.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
lineParts.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);Initializing the Particles
The changes start with the initialization of the float arrays inside createGeometry():
// step in 6's == two (x,y,z) coords == one line
for(int i=0; i < numPoints*3; i=i+6)
initTwoParticles(i);
initTwoParticles() initializes the two points. It assigns the same position and velocity to both points and then calls updateParticle() to update one of the point's position and velocity. This specifies a line with a point which is one update ahead of the other point. ...