diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..dff5f3a --- /dev/null +++ b/.travis.yml @@ -0,0 +1 @@ +language: java diff --git a/src/EuclideanSpace.java b/src/EuclideanSpace.java index bd3c304..6c32a61 100644 --- a/src/EuclideanSpace.java +++ b/src/EuclideanSpace.java @@ -14,6 +14,15 @@ public EuclideanSpace(Camera cam) { this.cam = cam; } + public Camera getCam() { + return cam; + } + + public void setCam(Camera cam) { + this.cam = cam; + repaint(); + } + @Override public void paintComponent(Graphics g) { super.paintComponent(g); @@ -49,15 +58,15 @@ public void paintComponent(Graphics g) { double unitY = (project.getZ() - cam.getOrig().getZ()) / cam.getCircleRad(); - double screenX = SIDE_LENGTH/2 + unitX * SIDE_LENGTH / 2; - double screenY = SIDE_LENGTH/2 - unitY * SIDE_LENGTH / 2; + double screenX = SIDE_LENGTH / 2 + unitX * SIDE_LENGTH / 2; + double screenY = SIDE_LENGTH / 2 - unitY * SIDE_LENGTH / 2; ells.add(new Ellipse2D.Double( - screenX - 10, screenY - 10, - 20, 20)); + screenX - 6, screenY - 6, + 12, 12)); } - if(shape.getColor() != null) { + if (shape.getColor() != null) { g2.setPaint(shape.getColor()); } else { g2.setPaint(Color.BLACK); @@ -70,18 +79,13 @@ public void paintComponent(Graphics g) { @Override public Dimension getPreferredSize() { - return new Dimension((int)SIDE_LENGTH, (int)SIDE_LENGTH); + return new Dimension((int) SIDE_LENGTH, (int) SIDE_LENGTH); } public void addShape(PointSet shape) { shapes.add(shape); } - public void setCam(Camera cam) { - this.cam = cam; - repaint(); - } - public ArrayList getShapes() { return new ArrayList<>(shapes); } diff --git a/src/MyFrame.java b/src/MyFrame.java index b41ac66..0503910 100644 --- a/src/MyFrame.java +++ b/src/MyFrame.java @@ -1,5 +1,6 @@ import javax.swing.*; import java.awt.*; +import java.awt.event.*; public class MyFrame extends JFrame { private EuclideanSpace space; @@ -22,17 +23,15 @@ public MyFrame() { JTextField radField = new JTextField("radius"); JButton reInitButton = new JButton("ReInit"); - reInitButton.addActionListener(e -> space.setCam( - new Camera( - new Point3( - Double.parseDouble(xField.getText()), - Double.parseDouble(yField.getText()), - Double.parseDouble(zField.getText()) - ), + reInitButton.addActionListener(e -> + reinitialize( + Double.parseDouble(xField.getText()), + Double.parseDouble(yField.getText()), + Double.parseDouble(zField.getText()), Double.parseDouble(yPlField.getText()), Double.parseDouble(radField.getText()) ) - )); + ); panel.add(reInitButton); panel.add(xField); @@ -40,7 +39,68 @@ public MyFrame() { panel.add(zField); panel.add(yPlField); panel.add(radField); + + InputMap imap = panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); + ActionMap amap = panel.getActionMap(); + + imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), + "decreaseX"); + amap.put("decreaseX", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + Camera camera = space.getCam(); + Point3 origin = camera.getOrig(); + reinitialize(origin.getX() - 5, origin.getY(), + origin.getZ(), camera.getYPlane(), + camera.getCircleRad()); + } + }); + + imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), + "increaseX"); + amap.put("increaseX", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + Camera camera = space.getCam(); + Point3 origin = camera.getOrig(); + reinitialize(origin.getX() + 5, origin.getY(), + origin.getZ(), camera.getYPlane(), + camera.getCircleRad()); + } + }); + + imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), + "increaseZ"); + amap.put("increaseZ", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + Camera camera = space.getCam(); + Point3 origin = camera.getOrig(); + reinitialize(origin.getX(), origin.getY(), + origin.getZ() + 5, camera.getYPlane(), + camera.getCircleRad()); + } + }); + + imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), + "decreaseZ"); + amap.put("decreaseZ", new AbstractAction() { + @Override + public void actionPerformed(ActionEvent e) { + Camera camera = space.getCam(); + Point3 origin = camera.getOrig(); + reinitialize(origin.getX(), origin.getY(), + origin.getZ() - 5, camera.getYPlane(), + camera.getCircleRad()); + } + }); + add(panel); } + private void reinitialize(double x, double y, double z, + double yPl, double rad) { + space.setCam(new Camera(new Point3(x, y, z), + yPl, rad)); + } } diff --git a/src/Sphere.java b/src/Sphere.java index 13e669e..8ee61b0 100644 --- a/src/Sphere.java +++ b/src/Sphere.java @@ -30,9 +30,9 @@ public Sphere(double x0, double y0, double z0, double rad, Color c) { while (s < 2 * PI) { points.add(new Point3(x0 + rad * cos(t) * cos(s) , y0 + rad * cos(t) * sin(s), z0 + rad * sin(t))); - s = s + 0.05; + s = s + 0.5; } - t = t + 0.05; + t = t + 0.5; } //Adding all the points formed super.setPoints(points);