void GenMoonDemo() { NUM_BODIES = 3; Body* earth; Body* moon; Body* theSun = new Body(.5f, Vector3(0, 0, 0), Vector3(0,0,0), SUN, program); theSun->Init(); bodies = std::vector<Body*>(); bodies.push_back(theSun); earth = new Body(.05f, Vector3(0, 0, 0), Vector3(0,0,0), PLANET, program); float semiMajLMult = 1; float minRadius = 10; earth->SetOrbit(*theSun, minRadius, Vector3(((rand() % 200 + 1) - 100)*.001f, ((rand() % 200 + 1) - 100)*.001f, ((rand() % 200 + 1) - 100)*.001f), 0, semiMajLMult); earth->Init(); bodies.push_back(earth); moon = new Body(.01f, Vector3(0, 0, 0), Vector3(0,0,0), ASTEROID, program); semiMajLMult = 1; minRadius = earth->radius + moon->radius; moon->SetOrbit(*earth, minRadius*2, Vector3(((rand() % 200 + 1) - 100)*.001f, ((rand() % 200 + 1) - 100)*.001f, ((rand() % 200 + 1) - 100)*.001f), 0, semiMajLMult); moon->Init(); bodies.push_back(moon); }
// No leaks void GenTwoBody() { NUM_BODIES = 2; bodies.clear(); Body* x = new Body(1.0f, Vector3(-5.0f, 0.0f, 0.0f), Vector3(0.0f, 0.0f, 0.0f), PLANET, program); x->Init(); bodies.push_back(x); Body* y = new Body(1.0f, Vector3(5.0f, 0.0f, 0.0f), Vector3(0.f, 0.001f, -0.005f), PLANET, program); y->Init(); bodies.push_back(y); }
void BodyList::Load(const std::string & name) { std::string dir = Config::GetInstance()->GetDataDir() + PATH_SEPARATOR + "body" + PATH_SEPARATOR + name + PATH_SEPARATOR; std::string fn = dir + CONFIG_FN; XmlReader doc; if (!doc.Load(fn)) { std::cerr << "Unable to find file " << fn << std::endl; return; } Body * body = new Body(doc.GetRoot(), dir); body->Init(); list[name] = body; }
// No leaks void GenSystem() { NUM_BODIES = 8; Body* p1; Body* theSun = new Body(3, Vector3(0, 0, 0), Vector3(0,0,0), SUN, program); theSun->Init(); bodies.push_back(theSun); for(int i = 1; i < NUM_BODIES; i++) { float rankScalar = static_cast<float>(i * 0.1f); // further away a planet is, higher the value p1 = new Body((.2f) + ((rand() % 10 + 1) - (5-rankScalar*2.f))*.015f, Vector3(0, 0, 0), Vector3(0,0,0), PLANET, program); //p1 = new Body((.2f) + ((rand() % 10 + 1))*.01f, Vector3(0, 0, 0), Vector3(0,0,0), PLANET, program); bodies.push_back(p1); int semiMajLMult = (rand() % 4 + 1); if(semiMajLMult <= 4) { semiMajLMult = 1; } else { semiMajLMult -= 3; // from 0->1 semiMajLMult *= 4; // from 0->4 semiMajLMult += 1; // from 1->5 } float minRadius; if (i > 1) minRadius = Vector3::dist(theSun->pos, bodies[i - 1]->pos) + bodies[i-1]->radius + p1->radius; else minRadius = theSun->radius + p1->radius; p1->SetOrbit(*theSun, minRadius + (rand() % 10 + 1)*(rankScalar), Vector3(((rand() % 200 + 1) - 100)*.001f, .9f + ((rand() % 200 + 1) - 100)*.001f, ((rand() % 200 + 1) - 100)*.001f), 0, semiMajLMult); p1->Init(); // Clean up p1 = nullptr; } // Clean up theSun = nullptr; }