Added adaptive weights

pull/35/head
James Ball 2020-02-13 23:11:14 +00:00
rodzic 50113368f9
commit 208bbecf13
7 zmienionych plików z 35 dodań i 5 usunięć

Wyświetl plik

@ -3,15 +3,17 @@ package audio;
import engine.Camera;
import engine.Vector3;
import engine.WorldObject;
import shapes.Shape;
import shapes.Shapes;
import java.util.List;
public class AudioClient {
private static final int SAMPLE_RATE = 192000;
private static final double FRAMERATE = 30;
public static void main(String[] args) throws InterruptedException {
// TODO: Implement adaptive default weight (i.e. the more things drawn, the lower the weight of lines)
// Calculate weight of lines using depth.
// TODO: Calculate weight of lines using depth.
// Reduce weight of lines drawn multiple times.
// Find intersections of lines to (possibly) improve line cleanup.
// Improve performance of line cleanup with a heuristic.

Wyświetl plik

@ -2,6 +2,7 @@ package audio;
import com.xtaudio.xt.*;
import shapes.Shape;
import shapes.Shapes;
import shapes.Vector2;
import java.util.ArrayList;
@ -24,6 +25,7 @@ public class AudioPlayer extends Thread {
private static double ROTATE_SPEED = 0;
private static final int ROTATE_PHASE_INDEX = 1;
private static double SCALE = 1;
private static double WEIGHT = 100;
private boolean stopped;
@ -37,6 +39,7 @@ public class AudioPlayer extends Thread {
for (int f = 0; f < frames; f++) {
Shape shape = getCurrentShape();
shape = shape.setWeight(WEIGHT);
shape = scale(shape);
shape = rotate(shape, FORMAT.mix.rate);
shape = translate(shape, FORMAT.mix.rate);
@ -123,6 +126,7 @@ public class AudioPlayer extends Thread {
currentShape = 0;
shapes = new ArrayList<>();
shapes.addAll(frame);
AudioPlayer.WEIGHT = 200 * Math.exp(-0.017 * Shapes.totalLength(frame));
lock.unlock();
}

Wyświetl plik

@ -56,4 +56,9 @@ public class Ellipse extends Shape {
public Ellipse translate(Vector2 vector) {
return new Ellipse(a, b, weight, rotation, position.translate(vector));
}
@Override
public Ellipse setWeight(double weight) {
return new Ellipse(a, b, weight, rotation, position);
}
}

Wyświetl plik

@ -96,6 +96,7 @@ public class Line extends Shape {
return new Line(getX1(), getY1(), getX2(), y2);
}
@Override
public Line setWeight(double weight) {
return new Line(getX1(), getY1(), getX2(), getY2(), weight);
}

Wyświetl plik

@ -1,7 +1,7 @@
package shapes;
public abstract class Shape {
public static final int DEFAULT_WEIGHT = 80;
public static final int DEFAULT_WEIGHT = 1;
protected double weight;
protected double length;
@ -11,6 +11,7 @@ public abstract class Shape {
public abstract Shape rotate(double theta);
public abstract Shape scale(double factor);
public abstract Shape translate(Vector2 vector);
public abstract Shape setWeight(double weight);
public double getWeight() {
return weight;

Wyświetl plik

@ -57,6 +57,14 @@ public class Shapes {
return generatePolygon(sides, new Vector2(scale, scale));
}
public static double totalLength(List<Shape> shapes) {
return shapes
.stream()
.map(Shape::getLength)
.reduce(Double::sum)
.orElse(0d);
}
public static List<Shape> sortLines(List<Line> lines) {
Graph<Vector2, DefaultWeightedEdge> graph = new DefaultUndirectedWeightedGraph<>(DefaultWeightedEdge.class);

Wyświetl plik

@ -8,10 +8,14 @@ public class Vector2 extends Shape{
private static final double EPSILON = 0.001;
public Vector2(double x, double y) {
public Vector2(double x, double y, double weight) {
this.x = x;
this.y = y;
this.weight = Shape.DEFAULT_WEIGHT;
this.weight = weight;
}
public Vector2(double x, double y) {
this(x, y, Shape.DEFAULT_WEIGHT);
}
public Vector2() {
@ -66,6 +70,11 @@ public class Vector2 extends Shape{
return new Vector2(getX() + vector.getX(), getY() + vector.getY());
}
@Override
public Vector2 setWeight(double weight) {
return new Vector2(x, y, weight);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;