-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrbiter.java
64 lines (53 loc) · 2.02 KB
/
Orbiter.java
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
import java.awt.Color;
import java.util.*;
/**
* An Orbiter is an object that orbits some other object, called its parent.
* The center of an orbital system is an Orbiter with no parent.
* Each Orbiter may have child Oribters that orbit it.
*
* An Orbiter stores its orbital radius and current orbit angle.
*/
public class Orbiter {
public enum Type {
CIRCLE, SQUARE, TRIANGLE
}
private final double orbitRadius;
private final Type type;
private final Color fillColor;
private double orbitAngle;
private double orbitSpeed;
private final List<Orbiter> children = new LinkedList<Orbiter>();
private final Orbiter parent;
public Orbiter(Orbiter parent, double orbitRadius, double orbitAngle, double orbitSpeed, Type type, Color fillColor) {
this.orbitRadius = orbitRadius;
this.orbitAngle = orbitAngle;
this.type = type;
this.fillColor = fillColor;
this.parent = parent;
this.orbitSpeed = orbitSpeed;
if (parent != null) parent.children.add(this);
}
public double getOrbitRadius() { return orbitRadius; }
public double getOrbitAngle() { return orbitAngle; }
public Color getFillColor() { return fillColor; }
public Type getType() { return type; }
public Orbiter getParent() { return parent; }
public List<Orbiter> getChildren() { return children; }
/**
* Updates the rotation of this orbiter by the amount specified in the deltaAngle parameter.
* @param deltaAngle The amount of rotation angle to add the to the current rotation.
*/
public void updateRotation(double timeDelta) {
orbitAngle += (timeDelta * orbitSpeed);
}
public Matrix getMatrix() throws UndefinedMatrixOpException {
if (parent == null) {
return Matrix.identity(3);
} else {
Matrix rotation = Matrix.rotationH2D(orbitAngle);
Matrix translation = Matrix.translationH2D(orbitRadius, 0);
Matrix parentMatrix = parent.getMatrix();
return parentMatrix.dot(rotation).dot(translation);
}
}
}