-
Notifications
You must be signed in to change notification settings - Fork 0
/
Spring.pde
89 lines (80 loc) · 2.87 KB
/
Spring.pde
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
/**
* @author jakemingolla
* @since 1,0
*
* Scene-specific implementation of a Spring, which will join two
* {@link Atom} objects inheriting the {@link Node} abstract class.
*
* Is the information needed for the implementation of Hooke's
* law in a later version.
*
* @see Node
* @see Renderable
*/
public class Spring extends Edge implements Renderable {
/*
* Ideal length of the Spring for interaction with
* Hooke's Law.
*/
private Double idealLength;
/**
* @author jakemingolla
*
* Default constructor for the spring class given two {@link Atom}
* instances.
*
* @param vertex1 The first Atom within the Spring.
* @param vertex2 The second Atom within the Spring.
*/
Spring(Atom vertex1, Atom vertex2, Double idealLength) {
super(vertex1, vertex2, Atom.class);
this.idealLength = idealLength;
}
/**
* @author jakemingolla
*
* Overriden render function to render a Spring object. Rendering a Spring
* is defined as a straight line between each of the {@link Atom} objects
* as vertices and can be controlled using {@link Constants} fields.
*/
@Override
public void render() {
pushMatrix();
stroke(Constants.DEFAULT_SPRING_R.floatValue(),
Constants.DEFAULT_SPRING_G.floatValue(),
Constants.DEFAULT_SPRING_B.floatValue(),
Constants.DEFAULT_SPRING_A.floatValue());
strokeWeight(Constants.DEFAULT_SPRING_STROKE_WEIGHT.floatValue());
/* Note the conversion between our Double values and the float values
* needed for processing. */
Atom v1 = (Atom)vertex1;
Atom v2 = (Atom)vertex2;
line(v1.getX().floatValue(), v1.getY().floatValue(), v1.getZ().floatValue(),
v2.getX().floatValue(), v2.getY().floatValue(), v2.getZ().floatValue());
popMatrix();
}
/**
* @author jakemingolla
*
* Overriden update function. As of version 1,0, this does nothing as Springs
* never need to be updated.
*/
@Override
public void update() {
}
/*
*
* GETTERS AND SETTERS BELOW
*
*
*/
public Double getIdealLength() {
return idealLength;
}
public void setIdealLength(Double idealLength) {
if (!Utilities.isPositive(idealLength)) {
throw new IllegalArgumentException();
}
this.idealLength = idealLength;
}
}