kopia lustrzana https://github.com/jameshball/osci-render
Cleaned up some of the new code
rodzic
ca9382d272
commit
fb81288f87
|
@ -1,5 +1,8 @@
|
||||||
package audio;
|
package audio;
|
||||||
|
|
||||||
|
import engine.Camera;
|
||||||
|
import engine.Vector3;
|
||||||
|
import engine.WorldObject;
|
||||||
import shapes.Ellipse;
|
import shapes.Ellipse;
|
||||||
import shapes.Shapes;
|
import shapes.Shapes;
|
||||||
import shapes.Vector2;
|
import shapes.Vector2;
|
||||||
|
@ -7,28 +10,27 @@ import shapes.Vector2;
|
||||||
public class AudioClient {
|
public class AudioClient {
|
||||||
private static final int SAMPLE_RATE = 192000;
|
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.
|
// TODO: Implement L-Systems drawing and Chinese postman.
|
||||||
|
|
||||||
AudioPlayer player = new AudioPlayer();
|
AudioPlayer player = new AudioPlayer();
|
||||||
AudioPlayer.FORMAT = AudioPlayer.defaultFormat(SAMPLE_RATE);
|
AudioPlayer.FORMAT = AudioPlayer.defaultFormat(SAMPLE_RATE);
|
||||||
|
|
||||||
// AudioPlayer.addShapes(Shapes.generatePolygram(5, 3, 0.5, 60));
|
Camera camera = new Camera(0.6, new Vector3(0, 0, -2), 60);
|
||||||
//AudioPlayer.addShapes(Shapes.generatePolygon(500, 0.5, 10));
|
WorldObject cube = new WorldObject(args[0], new Vector3(0,0,0), new Vector3());
|
||||||
// AudioPlayer.addShape(new Ellipse(0.5, 1));
|
|
||||||
|
|
||||||
// AudioPlayer.setRotateSpeed(0.8);
|
player.start();
|
||||||
// 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));
|
|
||||||
}
|
|
||||||
|
|
||||||
AudioPlayer.setScale(0.5);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,21 +1,25 @@
|
||||||
package audio;
|
package audio;
|
||||||
|
|
||||||
import com.xtaudio.xt.*;
|
import com.xtaudio.xt.*;
|
||||||
|
import shapes.Line;
|
||||||
import shapes.Shape;
|
import shapes.Shape;
|
||||||
import shapes.Vector2;
|
import shapes.Vector2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.locks.Lock;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
public class AudioPlayer extends Thread {
|
public class AudioPlayer extends Thread {
|
||||||
|
public static XtFormat FORMAT;
|
||||||
|
|
||||||
private static volatile boolean stopped = false;
|
private static volatile boolean stopped = false;
|
||||||
private static List<Shape> shapes = new ArrayList<>();
|
private static List<Shape> shapes = new ArrayList<>();
|
||||||
private static int currentShape = 0;
|
private static int currentShape = 0;
|
||||||
private static int framesDrawn = 0;
|
private static int framesDrawn = 0;
|
||||||
|
|
||||||
private static double[] phases = new double[2];
|
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 double TRANSLATE_SPEED = 0;
|
||||||
private static Vector2 TRANSLATE_VECTOR;
|
private static Vector2 TRANSLATE_VECTOR;
|
||||||
private static final int TRANSLATE_PHASE_INDEX = 0;
|
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) {
|
double time, long position, boolean timeValid, long error, Object user) {
|
||||||
XtFormat format = stream.getFormat();
|
XtFormat format = stream.getFormat();
|
||||||
|
|
||||||
|
lock.lock();
|
||||||
|
|
||||||
for (int f = 0; f < frames; f++) {
|
for (int f = 0; f < frames; f++) {
|
||||||
Shape shape = currentShape();
|
Shape shape = currentShape();
|
||||||
|
|
||||||
|
@ -50,6 +56,8 @@ public class AudioPlayer extends Thread {
|
||||||
currentShape++;
|
currentShape++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
static double nextTheta(double sampleRate, double frequency, int phaseIndex) {
|
static double nextTheta(double sampleRate, double frequency, int phaseIndex) {
|
||||||
|
@ -98,6 +106,14 @@ public class AudioPlayer extends Thread {
|
||||||
AudioPlayer.shapes.addAll(shapes);
|
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() {
|
private static Shape currentShape() {
|
||||||
if (currentShape >= shapes.size()) {
|
if (currentShape >= shapes.size()) {
|
||||||
currentShape -= shapes.size();
|
currentShape -= shapes.size();
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package engine;
|
package engine;
|
||||||
|
|
||||||
import shapes.Line;
|
import shapes.Line;
|
||||||
|
import shapes.Shape;
|
||||||
import shapes.Vector2;
|
import shapes.Vector2;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -16,10 +17,10 @@ public class Camera extends Renderer{
|
||||||
private Vector3 position;
|
private Vector3 position;
|
||||||
private double fov;
|
private double fov;
|
||||||
|
|
||||||
public Camera() {
|
public Camera(double focalLength, Vector3 position, double fov) {
|
||||||
this.focalLength = 0.6;
|
this.focalLength = focalLength;
|
||||||
this.position = new Vector3(0,0,-2);
|
this.position = position;
|
||||||
this.fov = 60;
|
this.fov = fov;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Line> draw(WorldObject worldObject) {
|
public List<Line> draw(WorldObject worldObject) {
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,6 +3,7 @@ package engine;
|
||||||
import shapes.Line;
|
import shapes.Line;
|
||||||
import shapes.Vector2;
|
import shapes.Vector2;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue