Removed renderer class and moved methods to camera

pull/35/head
James Ball 2020-02-11 22:01:56 +00:00
rodzic 96f8304879
commit 0346c6eb16
4 zmienionych plików z 20 dodań i 30 usunięć

Wyświetl plik

@ -21,7 +21,7 @@ public class AudioClient {
AudioPlayer.setScale(0.5);
while (true) {
AudioPlayer.updateFrame(Shapes.sortLines(camera.draw(cube)));
AudioPlayer.setFrame(Shapes.sortLines(camera.draw(cube)));
cube.rotate(rotation);
Thread.sleep((long) (1000 / FRAMERATE));
}

Wyświetl plik

@ -106,7 +106,7 @@ public class AudioPlayer extends Thread {
AudioPlayer.shapes.addAll(shapes);
}
public static void updateFrame(List<Line> frame) {
public static void setFrame(List<Line> frame) {
lock.lock();
currentShape = 0;
shapes = new ArrayList<>();

Wyświetl plik

@ -6,7 +6,7 @@ import shapes.Vector2;
import java.util.ArrayList;
import java.util.List;
public class Camera extends Renderer{
public class Camera {
private double focalLength;
private double clipping = 0.001;
private Vector3 pos;
@ -36,4 +36,21 @@ public class Camera extends Renderer{
vertex.getY() * focalLength / (vertex.getZ() - pos.getZ()) + pos.getY()
);
}
public List<Line> getFrame(List<Vector2> vertices, List<Integer> connections) {
List<Line> lines = new ArrayList<>();
for (int i = 0; i < connections.size(); i+=2) {
Vector2 start = vertices.get(connections.get(i));
Vector2 end = vertices.get(connections.get(i+1));
double x1 = start.getX();
double y1 = start.getY();
double x2 = end.getX();
double y2 = end.getY();
lines.add(new Line(x1, y1, x2, y2));
}
return lines;
}
}

Wyświetl plik

@ -1,27 +0,0 @@
package engine;
import shapes.Line;
import shapes.Vector2;
import java.awt.*;
import java.util.ArrayList;
import java.util.List;
public abstract class Renderer {
public List<Line> getFrame(List<Vector2> vertices, List<Integer> connections) {
List<Line> lines = new ArrayList<>();
for (int i = 0; i < connections.size(); i+=2) {
Vector2 start = vertices.get(connections.get(i));
Vector2 end = vertices.get(connections.get(i+1));
double x1 = start.getX();
double y1 = start.getY();
double x2 = end.getX();
double y2 = end.getY();
lines.add(new Line(x1, y1, x2, y2));
}
return lines;
}
}