-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnimatedModel.java
85 lines (75 loc) · 1.98 KB
/
AnimatedModel.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.util.ArrayList;
/**
* A Model with the ability to support a trailing animation.
*
* @author Justin Chang
*/
public class AnimatedModel extends Model
{
/**
* Master list of all animated models to be rendered.
*/
public static ArrayList<AnimatedModel> pipeline = new ArrayList<AnimatedModel>();
/**
* The number of ticks for which this animation trails. As an example,
* lifeSpan = 20 implies that this model will be followed by 20 fading copies.
*/
public int lifeSpan;
/**
* The starting transparency of the fade operation.
*/
public int alpha_0;
/**
* All model trails corresponding to this AnimatedModel.
*/
private ArrayList<ModelTrail> trails = new ArrayList<ModelTrail>();
/**
* Constructs an empty AnimatedModel at the specified origin. Sets the
* specified binding constants and animation constants.
*/
public AnimatedModel(Vec3 o, boolean s, int life, int alpha)
{
super(o, s);
lifeSpan = life;
alpha_0 = alpha;
}
/**
* Copy constructor.
*/
public AnimatedModel(AnimatedModel o)
{
super(o);
lifeSpan = o.lifeSpan;
alpha_0 = o.alpha_0;
}
/**
* Updates the trails of this animated model.
*/
public void tick()
{
if (lifeSpan > 0 && alpha_0 > -1 && alpha_0 < 256)
{
// Store a new trail at this location.
trails.add(new ModelTrail(this));
for (int j = 0; j < trails.size(); j++)
{
// Decay the lifespan of each trail.
ModelTrail mt = trails.get(j);
mt.tick();
// Remove invisible trails.
if (mt.hidden())
{
trails.remove(mt);
j--;
}
}
}
}
// Adds the model and all corresponding trails to the pipeline.
public void addTo(ArrayList<Triangle> pipeline, boolean shadows)
{
super.addTo(pipeline, shadows);
for (ModelTrail mt : trails)
mt.addTo(pipeline, shadows);
}
}