kopia lustrzana https://github.com/jameshball/osci-render
Removed renderer class and moved methods to camera
rodzic
96f8304879
commit
0346c6eb16
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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<>();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue