Multiple simultaneous visualizations

Now that we have a collection of visualizations, we can enhance the app to run more than one at a time and switch between them.

To support multiple concurrent visualizations, replace the activeViz variable in VisualizerBox with a list of visualizations:

public List<Visualization> visualizations = new ArrayList<Visualization|();

Then, cycle through the list in each of the VisualizerBox method that use it. We always want to set up all of them, but then only draw (preDraw, postDraw) the active ones:

    public void setup() {
        audioTexture = genTexture();
        fftTexture = genTexture();
        for (Visualization viz : visualizations) {
            viz.setup();
        }
    }
    public void preDraw() {
        for (Visualization viz : visualizations) {
            viz.preDraw();
        }
    }
    public void postDraw() {
        for (Visualization viz : visualizations) {
            viz.postDraw();
        }
    }

We can control the scene in MainActivity. Modify the MainActivity class's onCreate method to populate the visualizations list, as follows:

visualizerBox = new VisualizerBox(cardboardView);
visualizerBox.visualizations.add( new GeometricVisualization(visualizerBox));
visualizerBox.visualizations.add( new WaveformVisualization(visualizerBox));
visualizerBox.visualizations.add( new FFTVisualization(visualizerBox));

Run the project and we have a 3D scene full of visualizations!

Multiple simultaneous visualizations
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset