kopia lustrzana https://github.com/jameshball/osci-render
Cleaned Camera code
rodzic
8752ba58ef
commit
a82c9863d6
|
@ -1,42 +1,39 @@
|
||||||
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;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Camera extends Renderer{
|
public class Camera extends Renderer{
|
||||||
|
|
||||||
// position at 0,0,0,0
|
|
||||||
// rotation towards positive z axis
|
|
||||||
|
|
||||||
private double focalLength;
|
private double focalLength;
|
||||||
private double clipping = 0.001;
|
private double clipping = 0.001;
|
||||||
private Vector3 position;
|
private Vector3 pos;
|
||||||
|
|
||||||
public Camera(double focalLength, Vector3 position) {
|
public Camera(double focalLength, Vector3 pos) {
|
||||||
this.focalLength = focalLength;
|
this.focalLength = focalLength;
|
||||||
this.position = position;
|
this.pos = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Line> draw(WorldObject worldObject) {
|
public List<Line> draw(WorldObject worldObject) {
|
||||||
List<Vector2> vertices = new ArrayList<>();
|
List<Vector2> vertices = new ArrayList<>();
|
||||||
|
|
||||||
for(Vector3 vertex : worldObject.getVertices()) {
|
for(Vector3 vertex : worldObject.getVertices()) {
|
||||||
vertices.add(this.project(vertex));
|
vertices.add(project(vertex));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.getFrame(vertices, worldObject.getEdgeData());
|
return getFrame(vertices, worldObject.getEdgeData());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector2 project(Vector3 vertex) {
|
private Vector2 project(Vector3 vertex) {
|
||||||
if(vertex.getZ() - this.position.getZ() < clipping) {
|
if(vertex.getZ() - pos.getZ() < clipping) {
|
||||||
return new Vector2(0, 0);
|
return new Vector2(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Vector2(
|
return new Vector2(
|
||||||
vertex.getX() * focalLength / (vertex.getZ() - this.position.getZ()) + this.position.getX(),
|
vertex.getX() * focalLength / (vertex.getZ() - pos.getZ()) + pos.getX(),
|
||||||
vertex.getY() * focalLength / (vertex.getZ() - this.position.getZ()) + this.position.getY()
|
vertex.getY() * focalLength / (vertex.getZ() - pos.getZ()) + pos.getY()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue