Fix missing rendered face with plane clipping.
This commit is contained in:
parent
2e86db49f2
commit
c016c613aa
@ -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;i<clippedTriangles;i++) {
|
||||
if (i>0) {
|
||||
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);
|
||||
|
@ -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;
|
||||
}
|
||||
if (downHeld) {
|
||||
vCamera.y+=MOVESPEED;
|
||||
}
|
||||
if (downHeld) {
|
||||
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();
|
||||
|
||||
|
@ -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]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user