Repository navigation
Expand file tree
/
Copy pathCamera.java
More file actions
108 lines (83 loc) · 2.01 KB
/
Copy pathCamera.java
File metadata and controls
108 lines (83 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Panel;
import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
public class Camera implements Drawable, MouseMotionListener, MouseListener {
private int x;
private int y;
private int radius = 10;
private double angle;
public Camera(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public double getRadius() {
return radius;
}
public void setRadius(double distance) {
this.radius = (int) distance;
}
public double getDiameter() {
return 2 * radius;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public void rotate(int deltaAngle) {
this.angle += deltaAngle;
}
public double getAngle() {
return angle;
}
public void setAngle(double angle) {
this.angle = angle;
}
@Override
public void draw(Graphics2D g2d) {
g2d.setColor(Color.black);
g2d.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
}
@Override
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
p.translate(-Panel.WIDTH / 2, -Panel.HEIGHT / 2);
x = p.x;
y = p.y;
}
@Override
public void mouseDragged(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
int button = e.getButton();
if (button == MouseEvent.BUTTON1) {
angle ++;
} else if (button == MouseEvent.BUTTON3) {
angle --;
}
}
}