-
Notifications
You must be signed in to change notification settings - Fork 0
/
FallingObject.pde
executable file
·48 lines (44 loc) · 1.13 KB
/
FallingObject.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
class FallingObject
{
public PVector Location; // TODO: change to rotation offsets and drop translation?
public float FallingOffsetY;
public float FallingRate; // TODO: change to per time value
public FallingObject( PVector setLocation, float setFallingOffsetY, float setFallingRate )
{
Location = new PVector( setLocation.x, setLocation.y, setLocation.z );
FallingOffsetY = setFallingOffsetY;
FallingRate = setFallingRate;
}
public boolean isSettled()
{
return FallingOffsetY == 0;
}
public void settle()
{
if ( FallingRate < 0 ) // TODO: is this necessary? assume always falling in positive Y?
{
if ( FallingOffsetY > 0 )
{
FallingOffsetY += FallingRate;
}
else if ( FallingOffsetY < 0 )
{
FallingOffsetY = 0;
}
} else if ( FallingRate > 0 )
{
if ( FallingOffsetY < 0 )
{
FallingOffsetY += FallingRate;
}
else if ( FallingOffsetY > 0 )
{
FallingOffsetY = 0;
}
}
}
public void translateToLocation()
{
translate( Location.x, Location.y + FallingOffsetY, Location.z );
}
}