-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathmain.cpp
41 lines (32 loc) · 1.56 KB
/
main.cpp
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
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include "solarsystem.h"
#include "euler.h"
using namespace std;
int main(int numArguments, char **arguments)
{
int numTimesteps = 1000;
if(numArguments >= 2) numTimesteps = atoi(arguments[1]);
SolarSystem solarSystem;
// We create new bodies like this. Note that the createCelestialBody function returns a reference to the newly created body
// This can then be used to modify properties or print properties of the body if desired
// Use with: solarSystem.createCelestialBody( position, velocity, mass );
solarSystem.createCelestialBody( vec3(0,0,0), vec3(0,0,0), 1.0 );
// We don't need to store the reference, but just call the function without a left hand side
solarSystem.createCelestialBody( vec3(1, 0, 0), vec3(0, 2*M_PI, 0), 3e-6 );
// To get a list (a reference, not copy) of all the bodies in the solar system, we use the .bodies() function
vector<CelestialBody> &bodies = solarSystem.bodies();
for(int i = 0; i<bodies.size(); i++) {
CelestialBody &body = bodies[i]; // Reference to this body
cout << "The position of this object is " << body.position << " with velocity " << body.velocity << endl;
}
double dt = 0.001;
Euler integrator(dt);
for(int timestep=0; timestep<numTimesteps; timestep++) {
integrator.integrateOneStep(solarSystem);
solarSystem.writeToFile("positions.xyz");
}
cout << "I just created my first solar system that has " << solarSystem.bodies().size() << " objects." << endl;
return 0;
}