-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolar_System_Simulation.pde
More file actions
263 lines (209 loc) · 6.27 KB
/
Solar_System_Simulation.pde
File metadata and controls
263 lines (209 loc) · 6.27 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
import peasy.PeasyCam;
PeasyCam camera;
float timeScale = 1;
int frequency = 1;
float speed = 1;
float acceleration = 0.3;
float scaleFactor;
float scaleStep;
float rotateX;
float rotateY;
String center;
float centerX;
float centerY;
float centerZ;
float delta_time=86400*1; //(seconds in 1 day) * (days)
int menuState = 0;
boolean menuOpen = false;
boolean menuIsMoving = false;
PImage sunTexture;
PImage mercuryTexture;
PImage venusTexture;
PImage earthTexture;
PImage marsTexture;
PImage jupiterTexture;
PImage saturnTexture;
PImage uranusTexture;
PImage neptuneTexture;
int earthOrbitCounter = 0;
PVector lastSunPos = new PVector(0, 0, 0);
boolean addPlanet = false;
Star star;
Solar_System solarSystem;
Menu menu;
ArrayList<Button> menuButtons = new ArrayList<Button>();
ArrayList<Slider> sliders = new ArrayList<Slider>();
ArrayList<DropdownMenu> dropdownMenus = new ArrayList<DropdownMenu>();
ArrayList<String> planetListOptions = new ArrayList<String>();
/*
~=+=+=+=+=+=+=+=~
| ACTIVITY LOG: |
~=+=+=+=+=+=+=+=~
We (sorta) did it! We got gravity to work with multiple bodies! 10:25:45, 12/21/17 - Evab & Jazin
Added all EIGHT planets and got their relative positions, velocities, inclination angles, and sizes 3:21:52, 12/22/17 - Evab & Jazin
Made program Dr. Pierce worthy 11:41:45, 1/17/18 - Evab & Jazin
Successfully integrated PeasyCam library into program to allow "looking at" an object without having to
write a translate statement that would give you an aneurysm simply by looking at it 9:26:39, 1/24/18 - Jazin
Realized we have been using -6.67 for G, not 6.67E-11 12:02:14, 2/6/18 - Jazin
Help, current time - Evab & Jazin
*/
void setup() {
size(1440, 855, P3D);
smooth(8);
camera = new PeasyCam(this, 400);
//Zooming makes everything dissappear when closer than 75 units,
//set the scalar to 0 for now so I can just use scaleFactor
camera.setWheelScale(0);
//Only allow pitch and yaw, no roll
camera.setSuppressRollRotationMode();
sunTexture = loadImage("sunTexture.jpg");
mercuryTexture = loadImage("mercuryTexture.jpg");
venusTexture = loadImage("venusTexture.jpg");
earthTexture = loadImage("earthTexture.jpg");
marsTexture = loadImage("marsTexture.jpg");
jupiterTexture = loadImage("jupiterTexture.jpg");
saturnTexture = loadImage("saturnTexture.jpg");
uranusTexture = loadImage("uranusTexture.jpg");
neptuneTexture = loadImage("neptuneTexture.jpg");
star = new Star(frequency);
scaleFactor = 1.5;
scaleStep = 0.1;
rotateX = 0;
rotateY = 0;
center = "Sun";
centerX = 0;
centerY = 0;
centerZ = 0;
solarSystem = new Solar_System();
menu = new Menu(solarSystem.bodies);
//Menu buttons
menuButtons.add(new Button("backButton", 0, 0, 200, 40, "< Back", 15, 2));
menuButtons.add(new Button("menuSliders", -200, 200, 200, 40, "Sliders", 15, 2));
menuButtons.add(new Button("info", -200, 400, 200, 40, "Information", 15, 2));
//Sliders
sliders.add(new Slider("Zoom", scaleFactor, 20, 100, 0.15, 10, 160));
sliders.add(new Slider("Time", timeScale, 20, 200, 0.1, 20, 160));
//listOptions declared in solar system class
dropdownMenus.add(new DropdownMenu("Center of screen:", -200, 300, 160, 25, center, 2, planetListOptions));
}
void draw() {
background(0);
pushMatrix();
for (Body body : solarSystem.bodies) {
if (body.name == center) {
camera.lookAt(body.display_position.x * scaleFactor, body.display_position.y * scaleFactor, body.display_position.z * scaleFactor, 0);
}
}
scale(scaleFactor);
star.star(speed);
solarSystem.exist();
popMatrix();
//keep this in 2D
camera.beginHUD();
menu.run();
camera.endHUD();
}
void mouseWheel(MouseEvent event) {
if (scaleFactor + -event.getCount() * scaleStep >= 0.15
&& scaleFactor + -event.getCount() * scaleStep <= 10) {
scaleFactor += -event.getCount() * scaleStep;
}
}
void keyPressed() {
if (key == 'o') {
scaleFactor += scaleStep;
} else if (key == 'p' && scaleFactor > scaleStep*2) {
scaleFactor -= scaleStep;
} else
if (key == 'm') {
if (menuOpen == false && menuIsMoving == false) {
menu.slideIn();
menuOpen = true;
} else if (menuOpen == true && menuIsMoving == false) {
menu.slideOut();
menuOpen = false;
}
}
if (key=='w') {
timeScale += 1;
}
if (key=='s') {
if (timeScale >= 2) {
timeScale -= 1;
}
}
}
void mouseDragged() {
//set camera inactive when dragging in menu
if (mouseX < 200 && menuOpen) {
camera.setActive(false);
} else {
camera.setActive(true);
}
for (Button b : menuButtons) {
if (!b.contains(mouseX, mouseY)) {
b.clicked = false;
} else if (b.contains(mouseX, mouseY) && mousePressed) {
b.clicked = true;
}
}
for (DropdownMenu d : dropdownMenus) {
for (Button b : d.getListButtons()) {
if (!b.contains(mouseX, mouseY)) {
b.clicked = false;
} else if (b.contains(mouseX, mouseY) && mousePressed) {
b.clicked = true;
}
}
}
}
void mousePressed() {
for (Button b : menuButtons) {
if (b.contains(mouseX, mouseY)) {
b.wasClicked();
}
}
for (Slider s : sliders) {
if (menuState == 1) {
s.check();
}
}
for (DropdownMenu d : dropdownMenus) {
if (d.contains(mouseX, mouseY)) {
d.wasClicked();
}
for (Button b : d.getListButtons()) {
if (b.contains(mouseX, mouseY)) {
b.wasClicked();
}
}
}
}
void mouseReleased() {
for (Button b : menuButtons) {
if (b.contains(mouseX, mouseY)) {
b.wasClicked();
}
}
for (Slider s : sliders) {
if (menuState == 1) {
s.setUndraggable();
}
}
for (DropdownMenu d : dropdownMenus) {
if (d.contains(mouseX, mouseY)) {
d.wasClicked();
}
for (Button b : d.getListButtons()) {
if (b.contains(mouseX, mouseY)) {
b.wasClicked();
}
}
}
}
void keyReleased() {
if (key == 'y' && addPlanet == false) {
solarSystem.addBody(new Body("Planet", "New Planet", new PVector(200*pow(10, 9), 100*pow(10, 9), 100), new PVector(60000, 0, 0), 10, solarSystem.radiusScalar, 120*pow(10, 9), sunTexture));
// String type, String name, PVector position, PVector velocity, float mass, float radiusScalar, float distance, PImage texture
}
}