void displayevent(void) {
    // limpia la escena (ventana)
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    loadSkyBox();
     // inicializa la Matriz de transformación de coordenadas (Matriz del Modelo)
    glLoadIdentity();
    // verfica superficies visibles
    glEnable( GL_DEPTH_TEST );
    
    menuChoise( );

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    
    //Dibujamos los planetas
    sol ( sol_[0],sol_[1],sol_[2] );
    mercurio ( mercurio_[0], mercurio_[1], mercurio_[2] );
    venus ( venus_[0], venus_[1], venus_[2] );
    tierra ( tierra_[0], tierra_[1], tierra_[2] );
    marte ( marte_[0], marte_[1], marte_[2] );
    jupiter ( jupiter_[0], jupiter_[1], jupiter_[2] );
    saturno ( saturno_[0], saturno_[1], saturno_[2] );
    urano ( urano_[0], urano_[1], urano_[2] );
    neptuno ( neptuno_[0], neptuno_[1], neptuno_[2] );
    pluton ( pluton_[0], pluton_[1], pluton_[2] );
    glutSwapBuffers();
}
void display(void)
{
	lPosition();

	///////////////////////////////////////////////////////////////////////////////////////////////////////
	glClear (GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glColor3f (1.0, 1.0, 1.0);
	glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);			//Texturing Contour Anchored To The Object
	glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_OBJECT_LINEAR);			//Texturing Contour Anchored To The Object

	//glEnable(GL_TEXTURE_GEN_S);										//Auto Texture Generation
	//glEnable(GL_TEXTURE_GEN_T);										//Auto Texture Generation
	glEnable(GL_TEXTURE_2D);
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	stars();
	//glBindTexture(GL_TEXTURE_2D, g_cactus[1]);
	//gluSphere(g_text,0.4,48,48);
	stars();
	sun();
	adam();
	hesper();
	earth();
	mars();
	jupiter();
	saturn();
	uranus();
	neptune();
	///////////////////////////////////////////////////////////////////////////////////////////////////////
	glDisable(GL_TEXTURE_2D);		
	//glDisable(GL_TEXTURE_GEN_S);										//Auto Texture Generation
	//glDisable(GL_TEXTURE_GEN_T);
	glutSwapBuffers();
}
Esempio n. 3
0
int main(int argc, char* argv[]) {
    double sun_mass     = 1.00000000e-00; //mass sun
    double mercury_mass = 1.65956463e-07; //mass mercury
    double venus_mass   = 2.44699613e-06; //mass venus
    double earth_mass   = 3.00245840e-06; //mass earth
    double mars_mass    = 3.00245840e-07; //mass mars
    double jupiter_mass = 9.54265748e-04; //mass jupiter
    double saturn_mass  = 2.85716656e-04; //mass saturn
    double uranus_mass  = 4.36430044e-05; //mass uranus
    double neptune_mass = 5.14855965e-05; //mass neptune
    double pluto_mass   = 6.58086572e-09; //mass pluto

    arma::vec mercury_position = {0.466697,0.,0.};
    arma::vec mercury_velocity = {0.,9.99077808,0.};

    arma::vec venus_position = {0.728213,0.,0.};
    arma::vec venus_velocity = {0.,7.38729464,0.};

    arma::vec earth_position = {1.,0,0.}; //initial position earth
    arma::vec earth_velocity = {0.,6.28194273,0.}; //initial velocity earth

    arma::vec mars_position {1.6660,0.,0.};
    arma::vec mars_velocity {0.,5.07892327,0.};

    arma::vec jupiter_position = {5.458104,0.,0.};
    arma::vec jupiter_velocity = {0.,2.75705142,0.};

    arma::vec saturn_position = {10.11595804,0.,0.};
    arma::vec saturn_velocity = {0.,2.04405725,0.};

    arma::vec uranus_position = {20.095371,0.,0.};
    arma::vec uranus_velocity = {0.,1.43442614,0.};

    arma::vec neptune_position = {30.331855,0.,0.};
    arma::vec neptune_velocity = {0.,1.14543146,0.};

    arma::vec pluto_position = {39.264,0.,0.};
    arma::vec pluto_velocity = {0.,0.991441599,0.};

    arma::vec velocities[9] = {mercury_velocity, venus_velocity, earth_velocity, mars_velocity, 
        jupiter_velocity, saturn_velocity, neptune_velocity, uranus_velocity, pluto_velocity};

    double masses[9] = {mercury_mass, venus_mass, earth_mass, mars_mass,
        jupiter_mass, saturn_mass, uranus_mass, neptune_mass, pluto_mass};

    double s_vel = 0;

    for(int i=0; i<9 ;i++) {
        s_vel += masses[i]*arma::norm(velocities[i]);
    }

    arma::vec sun_position = {0.,0.,0.}; //initial position sun
    arma::vec sun_velocity = {0.,s_vel,0.}; //initial position sun

    Solarsystem mySolarsystem; //initialize solarsystem

    Body sun    (sun_position, sun_velocity, sun_mass);             //create sun
    Body mercury(mercury_position, mercury_velocity, mercury_mass); //create mercury
    Body venus  (venus_position, venus_velocity, venus_mass);       //create venus
    Body earth  (earth_position, earth_velocity, earth_mass);       //create earth
    Body mars   (mars_position, mars_velocity, mars_mass);          //create mars
    Body jupiter(jupiter_position, jupiter_velocity, jupiter_mass); //create jupiter
    Body saturn (saturn_position, saturn_velocity, saturn_mass);    //create saturn
    Body uranus (uranus_position, uranus_velocity, uranus_mass);    //create uranus
    Body neptune(neptune_position, neptune_velocity, neptune_mass); //create neptune
    Body pluto  (pluto_position, pluto_velocity, pluto_mass);       //create pluto

    mySolarsystem.addBody(sun); //add sun to system
    mySolarsystem.addBody(mercury); //add mercury to system
    mySolarsystem.addBody(venus); //add venus to system
    mySolarsystem.addBody(earth); //add earth to system
    mySolarsystem.addBody(mars); //add mars to system
    mySolarsystem.addBody(jupiter); //add jupiter to system
    mySolarsystem.addBody(saturn); //add saturn to system
    mySolarsystem.addBody(uranus); //add uranus to system
    mySolarsystem.addBody(neptune); //add neptune to system
    mySolarsystem.addBody(pluto); //add pluto to system

    Methods methods = Methods(); //initialize methods

    double T  = std::atof(argv[1]); //total time
    double dt = std::atof(argv[2]); //time-step
    std::string method = argv[3]; //method choice

    if(method == "verlet") {
        /* run verlet */
        methods.verlet_integrate(mySolarsystem, T, dt); //call integrator with made solarsystem
    }
    else if(method == "rk4") {
        /* run rk4 */
        methods.rk4_integrate(mySolarsystem, T, dt);
    }
    else {
        /* standard */
        std::cout << "Specify method" << std::endl;
    }

    return 0;
}
// main func is temporary ugly
int main(int argc, char ** argv)
{
	srand(time(NULL));

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE | GLUT_ACCUM);
	glutInitWindowPosition(glutGet(GLUT_SCREEN_WIDTH) / 14, glutGet(GLUT_SCREEN_HEIGHT) / 21);
	glutInitWindowSize(glutGet(GLUT_SCREEN_WIDTH) * 6 / 7, glutGet(GLUT_SCREEN_HEIGHT) * 6/7);
	int window = glutCreateWindow("Star System");
	//glutFullScreen();

	glEnable(GL_ACCUM);
	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_LINE_SMOOTH);
	//glEnable(GL_CULL_FACE);
	glEnable(GL_LIGHTING);

	//glCullFace(GL_BACK);
	
	//glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

	glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
	TwInit(TW_OPENGL, NULL);

	glutDisplayFunc(GlutCB::Display);
	glutReshapeFunc(GlutCB::Reshape);
	
	glutMouseFunc(GlutCB::Mouse);
	glutMotionFunc(GlutCB::Motion);
	glutPassiveMotionFunc(GlutCB::PassiveMotion);
	glutKeyboardFunc(GlutCB::Keyboard);
	glutKeyboardUpFunc(GlutCB::KeyboardUp);
	glutSpecialFunc(GlutCB::Special);
	glutSpecialUpFunc(GlutCB::SpecialUp);

	TwGLUTModifiersFunc(glutGetModifiers);

	glutTimerFunc(Constants::deltaTime, GlutCB::Timer, 1);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	Star sun("Sun", 2.0e30, 1.4e9, Vector3f(1.0f, 1.0f, 0.0f), Vector3d(0.0, 0.0, 0.0), Vector3d(0.0, 0.0, 0.0));

	Planet mercury("Mercury", 3.3e23, 5.0e6, Vector3f(0.8f, 0.0f, 0.0f), Vector3d(4.6e10, 0.0, 0.0), Vector3d(0.0, 4.7e4, 0.0));

	Planet venus("Venus", 4.8e24, 1.2e7, Vector3f(0.8f, 0.6f, 0.7f), Vector3d(1.0e11, 0.0, 0.0), Vector3d(0.0, 3.5e4, 0.0));

	Planet earth("Earth", 6.0e24, 1.2e7, Vector3f(0.0f, 0.0f, 1.0f), Vector3d(1.5e11, 0.0, 0.0), Vector3d(0.0, 3.0e4, 0.0));
	Sputnik moon("Moon", 7.35e22, 3.4e6, Vector3f(0.7f, 0.7f, 0.7f), &earth, Vector3d(4.0e8, 0.0, 0.0), Vector3d(0.0, 1.0e3, 0.0));

	Planet mars("Mars", 6.4e23, 6.7e6, Vector3f(1.0f, 0.0f, 0.0f), Vector3d(2.0e11, 0.0, 0.0), Vector3d(0.0, 2.4e4, 0.0));

	Teapot rasselsTeapot("RasselsTeapot", 0.0, 0.3, Vector3f(1.0f, 1.0f, 1.0f), Vector3d(3.0e11, 0.0, 0.0), Vector3d(0.0, 2.0e4, 0.0));

	Planet jupiter("Jupiter", 1.9e27, 1.3e8, Vector3f(1.0f, 0.8f, 0.0f), Vector3d(7.4e11, 0.0, 0.0), Vector3d(0.0, 1.3e4, 0.0));

	RenderManager * renderManager = RenderManager::getInstance();
	renderManager->initAll();

	Camera * camera = new Camera();
	
	ControlPane * ctrlPane = ControlPane::getInstance(camera, renderManager);
	ctrlPane->show();

	TwCopyStdStringToClientFunc(CopyStdStringToClient);

	ctrlPane->addSpaceObject(&sun);
	renderManager->renderSpaceObject(&sun);

	ctrlPane->addSpaceObject(&mercury);
	renderManager->renderSpaceObject(&mercury);

	ctrlPane->addSpaceObject(&venus);
	renderManager->renderSpaceObject(&venus);

	ctrlPane->addSpaceObject(&earth);
	renderManager->renderSpaceObject(&earth);

	ctrlPane->addSpaceObject(&moon);
	renderManager->renderSpaceObject(&moon);

	ctrlPane->addSpaceObject(&mars);
	renderManager->renderSpaceObject(&mars);

	ctrlPane->addSpaceObject(&rasselsTeapot);
	renderManager->renderSpaceObject(&rasselsTeapot);

	ctrlPane->addSpaceObject(&jupiter);
	renderManager->renderSpaceObject(&jupiter);

	GlutCBInitializer::init(camera, renderManager);

	glutMainLoop();
	
	delete ctrlPane;
	glutDestroyWindow(window);
	return EXIT_SUCCESS;
}