Creating the SceneThe WrapParticles3D object is passed two integers from the command line: the number of points to be used when creating a particle system and an integer between 1 and 3, which selects a particular system. The selection is done inside the createSceneGraph( ) method: switch(fountainChoice) { case 1: addPointsFountain(numParts); break; case 2: addLinesFountain(numParts); break; case 3: addQuadFountain(numParts); break; default: break; // do nothing } Figure 21-5. The Particles3D classesThe three particle systems all render variants of a fountain, which explains the prevalence of the word "fountain." The three addFountain( ) methods are similar, with addPointsFountain( ) the longest: private void addPointsFountain(int numParts) { PointParticles ptsFountain = new PointParticles(numParts, 20); // 20ms time delay between updates // move particles start position to (2,0,1) TransformGroup posnTG = new TransformGroup( ); Transform3D trans = new Transform3D( ); trans.setTranslation( new Vector3d(2.0f, 0.0f, 1.0f) ); posnTG.setTransform(trans); posnTG.addChild(ptsFountain); sceneBG.addChild( posnTG ); // timed behavior to animate the fountain Behavior partBeh = ptsFountain.getParticleBeh( ); partBeh.setSchedulingBounds( bounds ); sceneBG.addChild(partBeh); } The particle system (together with its GeometryUpdater and Behavior objects) is created by the PointParticles( ) constructor, which supplies the number of points to use and the time delay between each update. The middle part of the addPointFountain( ) shows that moving the systemas a single Shape3D entityto a new position is simple. By default, the systems all start at the origin. Though the Behavior object is created inside PointParticles, it still needs to be attached to the scene graph and given a bounding volume. This is done in the last part of addPointFountain( ) and requires a public getParticleBeh( ) method to return a reference to the behavior. |