From 9e6537c8b28b316cfb1d485f88d72aca8af31af5 Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Wed, 3 Nov 2021 09:26:32 +0900 Subject: [PATCH] Edge screen clipping. --- src/sig/Panel.java | 30 +++++++++++++++++++++++++++--- src/sig/SigRenderer.java | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/sig/Panel.java b/src/sig/Panel.java index 2d90dc6..4685bf7 100644 --- a/src/sig/Panel.java +++ b/src/sig/Panel.java @@ -181,9 +181,33 @@ public class Panel extends JPanel implements Runnable { }); for (Triangle t : accumulatedTris) { - DrawUtils.FillTriangle(p,(int)t.A.x,(int)t.A.y,(int)t.B.x,(int)t.B.y,(int)t.C.x,(int)t.C.y,t.getColor()); - if (SigRenderer.WIREFRAME) { - DrawUtils.DrawTriangle(p,(int)t.A.x,(int)t.A.y,(int)t.B.x,(int)t.B.y,(int)t.C.x,(int)t.C.y,Color.BLACK); + Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()}; + List triList = new ArrayList<>(); + triList.add(t); + int newTriangles=1; + for (int pl=0;pl<4;pl++) { + int trisToAdd=0; + while (newTriangles>0) { + Triangle test = triList.remove(0); + newTriangles--; + switch (pl) { + case 0:{trisToAdd = Triangle.ClipAgainstPlane(new Vector(0,0,0),new Vector(0,1,0),test,clipped);}break; + case 1:{trisToAdd = Triangle.ClipAgainstPlane(new Vector(0,getHeight()-1f,0),new Vector(0,-1,0),test,clipped);}break; + case 2:{trisToAdd = Triangle.ClipAgainstPlane(new Vector(0,0,0),new Vector(1,0,0),test,clipped);}break; + case 3:{trisToAdd = Triangle.ClipAgainstPlane(new Vector(getWidth()-1f,0,0),new Vector(-1,0,0),test,clipped);}break; + } + for (int w=0;w