diff --git a/src/Line.java b/src/Line.java index 0968350..24acda2 100644 --- a/src/Line.java +++ b/src/Line.java @@ -35,8 +35,8 @@ try { img.setRGB(returnVal[0], returnVal[1], Color.HSBtoRGB(1, 1, 1)); } - catch (ArrayIndexOutOfBoundsException ref){ - System.out.println(returnVal[0] + " " + returnVal[1]); + catch (ArrayIndexOutOfBoundsException ignored){ + // System.out.println(returnVal[0] + " " + returnVal[1]); } } } else { @@ -45,8 +45,8 @@ try { img.setRGB(returnVal[0], returnVal[1], Color.HSBtoRGB(.5f, 1, 1)); } - catch (ArrayIndexOutOfBoundsException ref){ - System.out.println(returnVal[0] + " " + returnVal[1]); + catch (ArrayIndexOutOfBoundsException ignored){ + // System.out.println(returnVal[0] + " " + returnVal[1]); } } } @@ -125,7 +125,7 @@ } else { is_initialised = false; - return null; + throw new RuntimeException("Accessed too many line pixels"); } iteratorVal += 1; return returnVal; diff --git a/src/Matrix.java b/src/Matrix.java new file mode 100644 index 0000000..3a75712 --- /dev/null +++ b/src/Matrix.java @@ -0,0 +1,63 @@ +public class Matrix { + protected int x; + protected int y; + private double[][] items; + + public Matrix(int _x, int _y){ + x = _x; y= _y; + items = new double[y][x]; + } + public double item(int _x, int _y){ + return items[_y][_x]; + } + public void setItem(int _x, int _y, double val){ + items[_y][_x] = val; + } + public double[][] getItems() { + return items; + } + public void setItems(double[][] newItems){ + items = newItems; + } + public Matrix multiply(Matrix mult) { + Matrix result = new Matrix(mult.x, this.y); + double newItem; + if(x==mult.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 newPoints = new ArrayList(); + for (Point3D point: points) { + Point3D _new = player.camMatrix.multiplyPoint3((point)); + if(_new.z > .1) { + newPoints.add(_new); + } else{ + newPoints.add(null); + } + } + Triangle t1 = null; + Triangle t2 = null; + try { + t1 = new Triangle( + newPoints.get(0).project(player.Fpdis, getWidth(), getHeight()), + newPoints.get(1).project(player.Fpdis, getWidth(), getHeight()), + newPoints.get(2).project(player.Fpdis, getWidth(), getHeight())); + } catch(NullPointerException ignored){} + try{ + t2 = new Triangle( + newPoints.get(0).project(player.Fpdis, getWidth(), getHeight()), + newPoints.get(2).project(player.Fpdis, getWidth(), getHeight()), + newPoints.get(3).project(player.Fpdis, getWidth(), getHeight())); + } catch(NullPointerException ignored){} + + try{t1.draw(img);}catch (NullPointerException ignored){} + try{t2.draw(img);}catch (NullPointerException ignored){} ang += 0.02; g.drawImage(img, 0, 0, this); @@ -107,7 +137,11 @@ } @Override - public void keyReleased(KeyEvent e) {} + public void keyReleased(KeyEvent e) { + int key = e.getKeyCode(); + + player.keyReleased(key); + } // gets the relative position of the mouse since the last time this function was called public Point2D get_mouse_rel(){ @@ -136,7 +170,7 @@ public void mouseClicked(MouseEvent mouseEvent) { if (mouseEvent.getButton() == MouseEvent.BUTTON1){ captured = true; - //setCursor(invisibleCursor); + setCursor(invisibleCursor); } } diff --git a/src/Triangle.java b/src/Triangle.java index 5356e41..7c85ed3 100644 --- a/src/Triangle.java +++ b/src/Triangle.java @@ -23,7 +23,8 @@ } public void draw(BufferedImage img){ if (!is_initialised){initialise();} - int[] point1 = new int[]{0,0}; int[] point2 = new int[]{0, 0}; + int[] point1 = new int[]{0, 0}; + int[] point2 = new int[]{0, 0}; int lastX = 0; int lastXLong = 0; char currentLine = 'A'; @@ -39,8 +40,8 @@ } while(lastX == point2[0]) { if (currentLine == 'A') { - point2 = LineA.nextPix(); - if (point2 == null) { + try{point2 = LineA.nextPix();} + catch (RuntimeException e){ currentLine = 'B'; point2 = LineB.nextPix(); } @@ -52,14 +53,22 @@ lastXLong = point1[0]; lastX = point2[0]; if(point1[1] < point2[1]) { - for (int y = point1[1]; y <= point2[1]; y += 1) {img.setRGB(x, y, Color.HSBtoRGB(.5f, 1, 1)); + for (int y = point1[1]; y <= point2[1]; y += 1) { + try{img.setRGB(x, y, Color.HSBtoRGB(.5f, 1, 1));} + catch(ArrayIndexOutOfBoundsException ignored){} }} else { - for (int y = point2[1]; y <= point1[1]; y += 1) {img.setRGB(x, y, Color.HSBtoRGB(.5f, 1, 1)); - }} + for (int y = point2[1]; y <= point1[1]; y += 1) { + try{img.setRGB(x, y, Color.HSBtoRGB(.5f, 1, 1));} + catch(ArrayIndexOutOfBoundsException ignored){} + + }} } is_initialised = false; } public void initialise(){ + if (point1 == null || point2 == null || point3 == null){ + throw new NullPointerException(); + } min = new Point2D(Math.min(point1.x, Math.min(point2.x, point3.x)), Math.min(point1.y, Math.min(point2.y, point3.y))); max = new Point2D(Math.max(point1.x, Math.max(point2.x, point3.x)), Math.max(point1.y, Math.max(point2.y, point3.y))); // woo horrible IFs mess.