Пример #1
0
ENTRYPOINT void
draw_glschool(ModeInfo *mi)
{
	Window					window = MI_WINDOW(mi);
	Display					*dpy = MI_DISPLAY(mi);
	glschool_configuration	*sc = &scs[MI_SCREEN(mi)];

	if (!sc->context) {
		fprintf(stderr, "no context\n");
		return;
	}

	glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(sc->context));

	if ((sc->goalCounter % GoalChgFreq) == 0)
		newGoal(sc->school);
	sc->goalCounter++;

	sc->rotCounter++;
	sc->rotCounter = (sc->rotCounter%360);

	applyMovements(sc->school);
	drawSchool(sc->colors, sc->school, sc->bboxList, sc->goalList, sc->fishList, sc->rotCounter, sc->drawGoal, sc->drawBBox);
	computeAccelerations(sc->school);

	if (mi->fps_p)
		do_fps(mi);

	glFinish();
	glXSwapBuffers(dpy, window);
}
Пример #2
0
void LenJonSim::timeStep() {

    t += dt;
    for (int i = nonMovableParticles; i < N; i++) {

        // integrate using velocity Verlet algorithm
        x[i] += vx[i] * dt + 0.5 * ax[i] * dt * dt;
        y[i] += vy[i] * dt + 0.5 * ay[i] * dt * dt;

        // periodic boundary conditions
//        if (x[i] < 0) x[i] += L;
//        if (x[i] > L) x[i] -= L;
//        if (y[i] < 0) y[i] += L;
//        if (y[i] > L) y[i] -= L;
        vx[i] += 0.5 * ax[i] * dt;
        vy[i] += 0.5 * ay[i] * dt;

        computeAccelerations();

        vx[i] += 0.5 * ax[i] * dt;
        vy[i] += 0.5 * ay[i] * dt;


    }


}
Пример #3
0
void velocityVerlet(double dt) {
    computeAccelerations(methr);
    for (int i = 0; i < N; i++)
        for (int k = 0; k < 3; k++) {
            r[i][k] += v[i][k] * dt + 0.5 *a[i][k] * dt * dt;
                                    // periodic boundary conditions
            if (r[i][k] < 0)
                r[i][k] += boxL;
            if (r[i][k] >= boxL)
                r[i][k] -= boxL;
            v[i][k] += 0.5 * a[i][k] * dt;
        }
    computeAccelerations(methr);
    for (int i = 0; i < N; i++)
        for (int k = 0; k < 3; k++)
            v[i][k] += 0.5 * a[i][k] * dt;
}
void begin_simulation(){
    double t = 0;
    for(t = 0; t < nstep; t++){
	/*For every iteration in the simulation, which is controlled by dt, the time step and the end time which is simulation_time*/
	computeAccelerations();

    }
}
Пример #5
0
void BodySystem::initDemoBodies()
{
	// units in kg, m, m/s
	_bodies.push_back(new Body(1.989e30, sf::Vector2<double>(0, 0), sf::Vector2<double>(0, 0), 30, sf::Color::Yellow)); // sun

	_bodies.push_back(new Body(5.972e24, sf::Vector2<double>(149600000000, 0), // earth
										sf::Vector2<double>(0, 30000), 7));

	_bodies.push_back(new Body(6.39e23, sf::Vector2<double>(227900000000, 0),
		sf::Vector2<double>(0, 24408), 5, sf::Color::Red)); // mars

	_bodies.push_back(new Body(1.89813e27, sf::Vector2<double>(778500000000, 0),
		sf::Vector2<double>(0, 13069), 10, sf::Color::White)); // jupiter

	// init the accelerations for the first step
	computeAccelerations();
}
Пример #6
0
ENTRYPOINT void
init_glschool(ModeInfo *mi)
{
	int						width = MI_WIDTH(mi);
	int						height = MI_HEIGHT(mi);
	Bool					wire = MI_IS_WIREFRAME(mi);
	glschool_configuration	*sc;

	if (!scs) {
		scs = (glschool_configuration *)calloc(MI_NUM_SCREENS(mi), sizeof(glschool_configuration));
		if (!scs) {
			perror("init_glschool: ");
			exit(1);
		}
	}
	sc = &scs[MI_SCREEN(mi)];

	sc->drawGoal = DoDrawGoal;
	sc->drawBBox = DoDrawBBox;

	sc->nColors = 360;
	sc->context = init_GL(mi);
	sc->colors = (XColor *)calloc(sc->nColors, sizeof(XColor));
	make_color_ramp(0, 0,
					0.0, 1.0, 1.0,
					359.0, 1.0, 1.0,
					sc->colors, &sc->nColors,
					False, 0, False);

	sc->school = initSchool(NFish, AccLimit, MaxVel, MinVel, DistExp, Momentum,
							MinRadius, AvoidFact, MatchFact, CenterFact, TargetFact,
							DistComp);
	if (sc->school == (School *)0) {
		fprintf(stderr, "couldn't initialize TheSchool, exiting\n");
		exit(1);
	}

	reshape_glschool(mi, width, height);

	initGLEnv(DoFog);
	initFishes(sc->school);
	createDrawLists(&SCHOOL_BBOX(sc->school), &sc->bboxList, &sc->goalList, &sc->fishList, wire);
	computeAccelerations(sc->school);
}
Пример #7
0
void BodySystem::update(sf::Time deltaTime)
{
	// scale the time step with the deltaTime
	double dt = TIME_STEP * deltaTime.asSeconds();

	// update each body position
	for (unsigned int i = 0; i < _bodies.size(); i++)
	{
		Body* body = _bodies[i];
		body->updatePosition(dt);
		body->updateRender();
	}

	// Recalculate accelerations and update body velocities
	computeAccelerations();

	for (unsigned int i = 0; i < _bodies.size(); i++)
	{
		Body* body = _bodies[i];
		body->updateVelocity(dt);
	}
}
Пример #8
0
void LenJonSim::initialize() {

    computeAccelerations();
}