Cleaned up some of the new code

pull/35/head
James Ball 2020-02-11 21:12:32 +00:00
rodzic ca9382d272
commit fb81288f87
5 zmienionych plików z 40 dodań i 38 usunięć

Wyświetl plik

@ -1,5 +1,8 @@
package audio;
import engine.Camera;
import engine.Vector3;
import engine.WorldObject;
import shapes.Ellipse;
import shapes.Shapes;
import shapes.Vector2;
@ -7,28 +10,27 @@ import shapes.Vector2;
public class AudioClient {
private static final int SAMPLE_RATE = 192000;
public static void main(String[] args) {
public static void main(String[] args) throws InterruptedException {
// TODO: Implement L-Systems drawing and Chinese postman.
AudioPlayer player = new AudioPlayer();
AudioPlayer.FORMAT = AudioPlayer.defaultFormat(SAMPLE_RATE);
// AudioPlayer.addShapes(Shapes.generatePolygram(5, 3, 0.5, 60));
//AudioPlayer.addShapes(Shapes.generatePolygon(500, 0.5, 10));
// AudioPlayer.addShape(new Ellipse(0.5, 1));
Camera camera = new Camera(0.6, new Vector3(0, 0, -2), 60);
WorldObject cube = new WorldObject(args[0], new Vector3(0,0,0), new Vector3());
// AudioPlayer.setRotateSpeed(0.8);
// AudioPlayer.setTranslation(2, new Vector(0.5, 0.5));
AudioPlayer.addShapes(Shapes.generatePolygon(4, new Vector2(0.25, 0.25)));
AudioPlayer.addShapes(Shapes.generatePolygon(4, new Vector2(0.5, 0.5)));
AudioPlayer.addShapes(Shapes.generatePolygon(4, new Vector2(-0.8, -0.8)));
for (int i = 0; i < 10; i++) {
AudioPlayer.addShape(new Ellipse(i / 10d, i / 10d));
}
player.start();
AudioPlayer.setScale(0.5);
player.start();
while(true) {
AudioPlayer.updateFrame(camera.draw(cube));
cube.rotate(new Vector3(
0,
Math.PI / 100,
0
));
Thread.sleep(1000/30);
}
}
}

Wyświetl plik

@ -1,21 +1,25 @@
package audio;
import com.xtaudio.xt.*;
import shapes.Line;
import shapes.Shape;
import shapes.Vector2;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
public class AudioPlayer extends Thread {
public static XtFormat FORMAT;
private static volatile boolean stopped = false;
private static List<Shape> shapes = new ArrayList<>();
private static int currentShape = 0;
private static int framesDrawn = 0;
private static double[] phases = new double[2];
private static Lock lock = new ReentrantLock();
public static XtFormat FORMAT;
private static double TRANSLATE_SPEED = 0;
private static Vector2 TRANSLATE_VECTOR;
private static final int TRANSLATE_PHASE_INDEX = 0;
@ -27,6 +31,8 @@ public class AudioPlayer extends Thread {
double time, long position, boolean timeValid, long error, Object user) {
XtFormat format = stream.getFormat();
lock.lock();
for (int f = 0; f < frames; f++) {
Shape shape = currentShape();
@ -50,6 +56,8 @@ public class AudioPlayer extends Thread {
currentShape++;
}
}
lock.unlock();
}
static double nextTheta(double sampleRate, double frequency, int phaseIndex) {
@ -98,6 +106,14 @@ public class AudioPlayer extends Thread {
AudioPlayer.shapes.addAll(shapes);
}
public static void updateFrame(List<Line> frame) {
lock.lock();
currentShape = 0;
shapes = new ArrayList<>();
shapes.addAll(frame);
lock.unlock();
}
private static Shape currentShape() {
if (currentShape >= shapes.size()) {
currentShape -= shapes.size();

Wyświetl plik

@ -1,6 +1,7 @@
package engine;
import shapes.Line;
import shapes.Shape;
import shapes.Vector2;
import java.util.ArrayList;
@ -16,10 +17,10 @@ public class Camera extends Renderer{
private Vector3 position;
private double fov;
public Camera() {
this.focalLength = 0.6;
this.position = new Vector3(0,0,-2);
this.fov = 60;
public Camera(double focalLength, Vector3 position, double fov) {
this.focalLength = focalLength;
this.position = position;
this.fov = fov;
}
public List<Line> draw(WorldObject worldObject) {

Wyświetl plik

@ -1,18 +0,0 @@
package engine;
public class Main {
public static void main(String[] args) throws InterruptedException {
Camera camera = new Camera();
WorldObject cube = new WorldObject("resources/machine.obj", new Vector3(0,0,0), new Vector3());
while(true) {
camera.draw(cube);
cube.rotate(new Vector3(
0,
Math.PI / 100,
0
));
Thread.sleep(1000/30);
}
}
}

Wyświetl plik

@ -3,6 +3,7 @@ package engine;
import shapes.Line;
import shapes.Vector2;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;