Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: java
26 changes: 15 additions & 11 deletions src/EuclideanSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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<PointSet> getShapes() {
return new ArrayList<>(shapes);
}
Expand Down
76 changes: 68 additions & 8 deletions src/MyFrame.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MyFrame extends JFrame {
private EuclideanSpace space;
Expand All @@ -22,25 +23,84 @@ 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);
panel.add(yField);
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));
}
}
4 changes: 2 additions & 2 deletions src/Sphere.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down