-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointMass.java
More file actions
59 lines (44 loc) · 1.1 KB
/
PointMass.java
File metadata and controls
59 lines (44 loc) · 1.1 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
// Render color based on speed. Then velocity. then accel
public class PointMass {
public float x, y, xOld, yOld;
public Color c;
public boolean pinned;
public PointMass( float xPos, float yPos, float xVel, float yVel, Color c ){
this.x = xPos;
this.y = yPos;
// do it this way because old position's validity is irrelevant
this.xOld = xPos - xVel;
this.yOld = yPos - yVel;
pinned = false;
this.c = c;
}
public void update(){
if(!pinned){
float xVel = x - xOld;
float yVel = y - yOld;
float xAcc = 0;
float yAcc = .3f; // TODO: current implementation of gravity. change so that it's stored in a field, and updated only when world changes
float xNew = x + xVel + xAcc;
float yNew = y + yVel + yAcc;
xOld = x;
yOld = y;
x = xNew;
y = yNew;
}else{
// pinned
}
}
public void draw( Render r ){
r.drawColoredPoint((int)x, (int)y, c);
}
public void setPin( boolean b ){
pinned = b;
}
// translate the point if it is not pinned
public void translate( float dx, float dy ){
if( !pinned ){
x += dx;
y += dy;
}
}
}