diff --git a/out/production/EPQ 3D renderer/Face.class b/out/production/EPQ 3D renderer/Face.class index d1c181a..4abdb4e 100644 --- a/out/production/EPQ 3D renderer/Face.class +++ b/out/production/EPQ 3D renderer/Face.class Binary files differ diff --git a/out/production/EPQ 3D renderer/Matrix.class b/out/production/EPQ 3D renderer/Matrix.class index 5897f80..7b2526a 100644 --- a/out/production/EPQ 3D renderer/Matrix.class +++ b/out/production/EPQ 3D renderer/Matrix.class Binary files differ diff --git a/out/production/EPQ 3D renderer/Object3d.class b/out/production/EPQ 3D renderer/Object3d.class index 7e0b039..95c5e2b 100644 --- a/out/production/EPQ 3D renderer/Object3d.class +++ b/out/production/EPQ 3D renderer/Object3d.class Binary files differ diff --git a/out/production/EPQ 3D renderer/Screen.class b/out/production/EPQ 3D renderer/Screen.class index 4df8c31..2324799 100644 --- a/out/production/EPQ 3D renderer/Screen.class +++ b/out/production/EPQ 3D renderer/Screen.class Binary files differ diff --git a/out/production/EPQ 3D renderer/Triangle.class b/out/production/EPQ 3D renderer/Triangle.class index b9daefa..6a9649d 100644 --- a/out/production/EPQ 3D renderer/Triangle.class +++ b/out/production/EPQ 3D renderer/Triangle.class Binary files differ diff --git a/src/Face.java b/src/Face.java index 8879a50..3017d0d 100644 --- a/src/Face.java +++ b/src/Face.java @@ -89,9 +89,9 @@ (0.1+gradX*point.getRotatedPoint().x-point.getRotatedPoint().z)/gradX, (0.1+gradY*point.getRotatedPoint().y-point.getRotatedPoint().z)/gradY, 0.1)); - if(Double.isFinite(gradX)){ + if(!Double.isFinite(gradX)){ newPoints.get(newPoints.size() - 1).point.x = point.getRotatedPoint().x;} - if(Double.isFinite(gradY)){ + if(!Double.isFinite(gradY)){ newPoints.get(newPoints.size() - 1).point.y = point.getRotatedPoint().y;} } // finally - if the current point is valid, then add it to the list @@ -101,17 +101,21 @@ point.getRotatedPoint().y, point.getRotatedPoint().z)); } + lastPoint = point; lastValid = thisValid; } - // finished fixing points, now we need to create a new face consisting of those points. - fixedFace.points = newPoints.toArray(new PointComp[0]); - fixedFace.separateTris(); - // invalidate all the points so they are actually calculated - for (PointComp point: - newPoints) { - point.invalidate(); + // there must be at least 3 points in the face for it to be drawn successfully + if(newPoints.size() >= 3) { + // finished fixing points, now we need to create a new face consisting of those points. + fixedFace.points = newPoints.toArray(new PointComp[0]); + fixedFace.separateTris(); + // invalidate all the points so they are actually calculated + for (PointComp point : + newPoints) { + point.invalidate(); + } + fixedFace.draw(img, zBuf, debugImg, fixedFace.perspectiveMappingMatrix, FPDis, scrX, scrY); } - fixedFace.draw(img, zBuf, debugImg, fixedFace.perspectiveMappingMatrix, FPDis, scrX, scrY); } return numberOfPixels; } diff --git a/src/Line2d.java b/src/Line2d.java index ab1cff6..3e03428 100644 --- a/src/Line2d.java +++ b/src/Line2d.java @@ -6,7 +6,7 @@ public Point2D point1; public Point2D point2; - public boolean isDrawn = true; + public boolean isDrawn; // initializer variables boolean is_initialised = false; @@ -59,7 +59,7 @@ /** * Performs the initial calculations required to draw the line - * Is automatically called whenever nextpix() or draw() are called when initialise() has not run. + * Is automatically called whenever nextPix() or draw() are called when initialise() has not run. */ public void initialise(){ // initialise brensenham algorithm @@ -131,7 +131,7 @@ iteratorVal += 1; return returnVal; } - public double getZval(int x){ + public double getZVal(int x){ return realPoint1.z + (gradient * (x - realPoint1.x)); } } diff --git a/src/Matrix.java b/src/Matrix.java index 4480cc9..68d2892 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -19,15 +19,15 @@ public void setItems(double[][] newItems){ items = newItems; } - public Matrix multiplyGetResult(Matrix mult) { - Matrix result = new Matrix(mult.x, this.y); + public Matrix multiplyGetResult(Matrix multiplier) { + Matrix result = new Matrix(multiplier.x, this.y); double newItem; - if(x==mult.y){ + if(x== multiplier.y){ for(int rx = 0; rx< result.x; rx+=1){ for(int ry = 0; ry< result.y; ry+=1){ newItem = 0; for(int i = 0; i (int)zBuf.getRGB(x, y)){ //newZ > zBuf.getRGB(x, y) || + newZ > zBuf.getRGB(x, y)){ //newZ > zBuf.getRGB(x, y) || zBuf.setRGB(x, y, newZ); - double[] result = perspectiveMappingMatrix.multiplyPoint2raw(x, y); + // double[] result = perspectiveMappingMatrix.multiplyPoint2raw(x, y); // img.setRGB(x, y, texture.getRGB( // Math.floorMod((int)(result[0]), texture.getWidth()), // Math.floorMod((int)(result[1]), texture.getHeight())));