diff --git a/src/audio/AudioClient.java b/src/audio/AudioClient.java index 5fe258b..4ba2ddf 100644 --- a/src/audio/AudioClient.java +++ b/src/audio/AudioClient.java @@ -5,6 +5,7 @@ import engine.Vector3; import engine.WorldObject; import java.util.ArrayList; import java.util.List; +import java.util.stream.IntStream; import shapes.Shape; import shapes.Shapes; import shapes.Vector2; @@ -20,20 +21,27 @@ public class AudioClient { // Improve performance of line cleanup with a heuristic. // Pre-render in parallel. - Camera camera = new Camera(0.8, new Vector3(0, 0, -3)); + Camera camera = new Camera(0.6, new Vector3(0, 0, -0.08)); WorldObject object = new WorldObject(args[0], new Vector3(0, 0, 0), new Vector3()); Vector3 rotation = new Vector3(0,Math.PI / 100,Math.PI / 100); List> preRenderedFrames = new ArrayList<>(); int numFrames = (int) (Float.parseFloat(args[1]) * TARGET_FRAMERATE); - + long start = System.currentTimeMillis(); for (int i = 0; i < numFrames; i++) { - preRenderedFrames.add(Shapes.sortLines(camera.draw(object))); - object.rotate(rotation); + preRenderedFrames.add(new ArrayList<>()); } + IntStream.range(0, numFrames).parallel().forEach((frameNum) -> { + WorldObject clone = object.clone(); + clone.rotate(rotation.scale(frameNum)); + preRenderedFrames.set(frameNum, Shapes.sortLines(camera.draw(clone))); + }); + + System.out.println(System.currentTimeMillis() - start); + AudioPlayer player = new AudioPlayer(SAMPLE_RATE, preRenderedFrames); //AudioPlayer.setRotateSpeed(1); //AudioPlayer.setTranslation(1, new Vector2(1, 1)); diff --git a/src/audio/AudioPlayer.java b/src/audio/AudioPlayer.java index 97cb051..b7f1db7 100644 --- a/src/audio/AudioPlayer.java +++ b/src/audio/AudioPlayer.java @@ -136,7 +136,7 @@ public class AudioPlayer extends Thread { } private static Shape getCurrentShape() { - if (frames.size() == 0) { + if (frames.size() == 0 || frames.get(currentFrame).size() == 0) { return new Vector2(0, 0); } diff --git a/src/engine/Vector3.java b/src/engine/Vector3.java index 4fa5b30..6af045d 100644 --- a/src/engine/Vector3.java +++ b/src/engine/Vector3.java @@ -84,4 +84,8 @@ public final class Vector3 { return mean.scale(1f / (points.size())); } + + public Vector3 clone() { + return new Vector3(x, y, z); + } } diff --git a/src/engine/WorldObject.java b/src/engine/WorldObject.java index fa2c507..90e2a25 100644 --- a/src/engine/WorldObject.java +++ b/src/engine/WorldObject.java @@ -23,10 +23,21 @@ public class WorldObject { loadFromFile(filename); } + public WorldObject(List vertices, List edgeData, Vector3 position, Vector3 rotation) { + this.vertices = vertices; + this.edgeData = edgeData; + this.position = position; + this.rotation = rotation; + } + public void rotate(Vector3 theta) { rotation = rotation.add(theta); } + public void resetRotation() { + rotation = new Vector3(); + } + public List getVertices() { List newVertices = new ArrayList<>(); @@ -67,4 +78,20 @@ public class WorldObject { throw new IllegalArgumentException("Cannot load mesh data from: " + filename); } } + + public WorldObject clone() { + List newVertices = new ArrayList<>(); + + for (Vector3 vertex : vertices) { + newVertices.add(vertex.clone()); + } + + List newEdgeData = new ArrayList<>(); + + for (int edge : edgeData) { + newEdgeData.add(edge); + } + + return new WorldObject(newVertices, newEdgeData, position.clone(), rotation.clone()); + } }