-
Notifications
You must be signed in to change notification settings - Fork 0
/
Planet.pde
153 lines (127 loc) · 4.64 KB
/
Planet.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Planet class file for use in Impossibru Planetary Destruction Simulator
//
//
////////////////////////////////////////////////////////////////////////////////////////
// GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD GOD /
static class God{ //////////////////////////////////////////////////////////////////////
static int noP = 0;
static ArrayList planArray = new ArrayList();
static ParticleSystem physics;
static boolean notYetInitialized = true;
God(){
}
static Planet pArray(int a){
return (Planet) planArray.get(a);
}
}
///////////////////////////////////////////////////////////////////////////////////
// PLANET PLANET PLANET PLANET PLANET PLANET PLANET PLANET PLANET PLANET PLANET ///
class Planet extends God{ /////////////////////////////////////////////////////////
String name;
Particle body;
Attraction[] attrArray;
float diam, rota, zoomDist;
Ellipsoid body3D;
ArrayList tail;
int tailColor, planetIndex;
char hotKey;
// Class constructor
Planet(){
if(notYetInitialized){ // First planet to create God
God.physics = new ParticleSystem(); // New particle system without gravity
God.physics.setIntegrator( ParticleSystem.RUNGE_KUTTA);
God.physics.setDrag(0);
God.notYetInitialized = false;
}
planetIndex = noP; // is the latest planet to be added to the array
noP++; // increment planet count
God.planArray.add(this);
diam = 10;
rota = 0.02;
tail = new ArrayList();
tailColor = 255; // default tail color white
zoomDist = 300;
body = God.physics.makeParticle(0,0,0,0); // Create particle
}
float x(){
return this.body.position().x();
}
float y(){
return this.body.position().y();
}
float z(){
return this.body.position().z();
}
float vx(){
return this.body.velocity().x();
}
float vy(){
return this.body.velocity().y();
}
float vz(){
return this.body.velocity().z();
}
void setLoca(float x, float y, float z){
body.position().set(x, y, z); // Set initial velocities
}
void setVelo(float vx, float vy, float vz){
body.velocity().set(vx, vy, vz); // Set initial velocities
}
void setMass(float m){
body.setMass(m);
}
void initSetup(){
for(i=0; i<planetIndex; i++){ // Create attractions
God.physics.makeAttraction(this.body, God.pArray(i).body, grav, mindist);
}
body3D = AddEllipsoid(20,30,name + ".jpg",diam/2); // Create 3D object
body3D.rotateBy(radians(-90), 0, 0); //correcting image orientation
tail.add(new PVector(this.x(),this.y(),this.z()));
}
void draw3D(){
body3D.draw();
}
void move3D(){
body3D.moveTo( this.x() - CENTRE.x(), this.y() - CENTRE.y(), this.z() - CENTRE.z());
body3D.rotateBy(0, degrees(rotStop*rota*dt), 0);
}
void popTrail(){
tail.add(new PVector(this.x(), this.y(), this.z()));
if(tail.size() > tailLength) // Remove oldest value if exceeding max trail length
tail.remove(0);
}
void drawTrail(){
PVector P1 = new PVector(0,0,0);
PVector P2 = new PVector(0,0,0);
int tailSize = 0;
tailSize = tail.size() - 1;
for(j=tailSize; j>1; j-=1){
stroke(tailColor, (int) 255*j/tailSize);
// Get 4 points
P1 = (PVector) tail.get(j);
P2 = (PVector) tail.get(j-1);
// Draw line
line(P1.x - CENTRE.x(), P1.y - CENTRE.y(), P1.z - CENTRE.z(),
P2.x - CENTRE.x(), P2.y - CENTRE.y(), P2.z - CENTRE.z());
}
}
Planet keySearch(char c){
if(hotKey == c){
distance = zoomDist;
return this;
}
else
return CENTRE;
}
void nuke(float tnt, PVector direction){}
void splitApart(float tnt, PVector direction){}
} // end planet class
//////////////////////////////////////////////////////////////////////////////////////
// ADDELLIPSOID ADDELLIPSOID ADDELLIPSOID ADDELLIPSOID ADDELLIPSOID ADDELLIPSOID /////
Ellipsoid AddEllipsoid(int slices, int segments, String textureFile, float radius){ //
Ellipsoid aShape = new Ellipsoid(this, slices, segments);
aShape.setTexture(textureFile);
aShape.drawMode(Shape3D.TEXTURE);
aShape.setRadius(radius);
return aShape;
} // end AddEllipsoid