Gl Graph

Gl Graph Source of nbodysimulation.cpp


#include "nbodysimulation.h"
#include "math.h"
 
NBodySimulation::NBodySimulation()
{
}
 
float NBodySimulation::getMinX()
{
    return -10;
}
 
float NBodySimulation::getMaxX()
{
    return 10;
}
 
float NBodySimulation::getMinY()
{
    return -10;
}
 
float NBodySimulation::getMaxY()
{
    return 10;
}
 
float genrandom() {
    return (rand()%1000)/1000.0f;
}
 
void NBodySimulation::initManyBody()
{
    float m=3000000.0;
 
    Vec3f z=Vec3f(0,0,1);
 
    int nbstep=20;
    float xstart=-5;
    float xend=5;
    float ystart=-5;
    float yend=5;
    float xsize=xend-xstart;
    float ysize=yend-ystart;
    float xstep=xsize/nbstep;
    float ystep=ysize/nbstep;
    srand(time(0));
    for (int j=0; j<nbstep+1; j++)
        for (int i=0; i<nbstep+1; i++)
        {
            Vec3f pos=Vec3f(xstart+i*xstep,ystart+j*ystep,0);
            Vec3f speed;
            speed.cross(pos,z);
            speed=0.05*speed;
            float size=0.1*genrandom();
            float masse=m*(genrandom()+0.5);
            parts.add(new GlParticule(pos,speed,Vec3f(0,0,0),masse,size));
        }
 
}
 
void NBodySimulation::initBody()
{
    float m=3000000.0;
    parts.add(new GlParticule(Vec3f(-2,0,0),Vec3f(0.1,0,0),Vec3f(0,0,0),m,0.1));
    parts.add(new GlParticule(Vec3f(2,0,0),Vec3f(-0.1,0,0),Vec3f(0,0,0),m,0.1));
}
 
void NBodySimulation::init()
{
    //glCamera->setAnimationMode(true);
}
 
void NBodySimulation::draw()
{
    glUseProgram(0);
 
    parts.run();
    parts.draw();
}