From c016c613aa05270ba3a330b8cc2541d5aa936ac9 Mon Sep 17 00:00:00 2001 From: Joshua Sigona Date: Wed, 3 Nov 2021 08:53:32 +0900 Subject: [PATCH] Fix missing rendered face with plane clipping. --- src/sig/Panel.java | 5 ++++- src/sig/SigRenderer.java | 12 ++++++------ src/sig/Triangle.java | 5 ++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/sig/Panel.java b/src/sig/Panel.java index b3069ea..2d90dc6 100644 --- a/src/sig/Panel.java +++ b/src/sig/Panel.java @@ -129,13 +129,16 @@ public class Panel extends JPanel implements Runnable { triViewed.A = Matrix.MultiplyVector(matView,triTransformed.A); triViewed.B = Matrix.MultiplyVector(matView,triTransformed.B); triViewed.C = Matrix.MultiplyVector(matView,triTransformed.C); - triProjected.setColor(new Color(dp,dp,dp)); + triViewed.setColor(new Color(dp,dp,dp)); int clippedTriangles = 0; Triangle[] clipped = new Triangle[]{new Triangle(),new Triangle()}; clippedTriangles = Triangle.ClipAgainstPlane(new Vector(0,0,1),new Vector(0,0,1), triViewed, clipped); for (int i=0;i0) { + triProjected = new Triangle(); + } triProjected.A = Matrix.MultiplyVector(SigRenderer.matProj,clipped[i].A); triProjected.B = Matrix.MultiplyVector(SigRenderer.matProj,clipped[i].B); triProjected.C = Matrix.MultiplyVector(SigRenderer.matProj,clipped[i].C); diff --git a/src/sig/SigRenderer.java b/src/sig/SigRenderer.java index 40dab7d..f422d57 100644 --- a/src/sig/SigRenderer.java +++ b/src/sig/SigRenderer.java @@ -14,7 +14,7 @@ import java.awt.BorderLayout; public class SigRenderer implements KeyListener,MouseListener,MouseMotionListener{ - public static boolean WIREFRAME = true; + public static boolean WIREFRAME = false; public static Mesh cube; public static int SCREEN_WIDTH=1280; @@ -45,16 +45,16 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene public void runGameLoop() { if (upHeld) { - vCamera.y-=MOVESPEED; + vCamera.y+=MOVESPEED; } if (downHeld) { - vCamera.y+=MOVESPEED; + vCamera.y-=MOVESPEED; } if (rightHeld) { - vCamera.x+=MOVESPEED; + vCamera.x-=MOVESPEED; } if (leftHeld) { - vCamera.x-=MOVESPEED; + vCamera.x+=MOVESPEED; } if (wHeld||sHeld) { Vector forward = Vector.multiply(vLookDir,MOVESPEED); @@ -74,7 +74,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene } SigRenderer(JFrame f) { - cube = new Mesh(OBJReader.ReadOBJFile("axis.obj")); + cube = new Mesh(OBJReader.ReadOBJFile("teapot.obj")); Panel p = new Panel(); diff --git a/src/sig/Triangle.java b/src/sig/Triangle.java index 0c85534..bebe7ec 100644 --- a/src/sig/Triangle.java +++ b/src/sig/Triangle.java @@ -68,15 +68,14 @@ public class Triangle { return 1; } else if (insidePointCount==1&&outsidePointCount==2) { - out_tri[0].col = Color.BLUE; + out_tri[0].col = in.col; out_tri[0].A = inside_points[0]; out_tri[0].B = Vector.IntersectPlane(plane_p, plane_n, inside_points[0], outside_points[0]); out_tri[0].C = Vector.IntersectPlane(plane_p, plane_n, inside_points[0], outside_points[1]); return 1; } else if (insidePointCount==2&&outsidePointCount==1) { - out_tri[0].col=Color.RED; - out_tri[1].col=Color.GREEN; + out_tri[0].col=out_tri[1].col=in.col; out_tri[0].A = inside_points[0]; out_tri[0].B = inside_points[1]; out_tri[0].C = Vector.IntersectPlane(plane_p, plane_n, inside_points[0], outside_points[0]);