Exemplo n.º 1
0
void
reshape(int width, int height)
{
    float black[] = { 0, 0, 0, 0 };

    float red[] = {0.1,0.2,0.3,0};
								//reshape function for the code
    glViewport(0, 0, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60, (float)width/height, 0.1, 1000);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0, 1, 3, 0, 1, 0, 0, 1, 0);
    glFogfv(GL_FOG_COLOR, red); //specifying the attributes for FOG 
    glFogf(GL_FOG_START, 2.5); // fog characteristic increases linearly from fog start, and ends at fog end.
    glFogf(GL_FOG_END, 4); //specifying the terminal attribute for FOG
    glEnable(GL_FOG); //enabling FOG 
    glFogi(GL_FOG_MODE, GL_LINEAR);
    glPointSize(point_size);
    glEnable(GL_POINT_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_COLOR_MATERIAL);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHT0);

    timedelta();
}
Exemplo n.º 2
0
void
menustate(int state)
{
    /* hook up a fake time delta to avoid jumping when menu comes up */
    if (state == GLUT_MENU_NOT_IN_USE)
	timedelta();
}
Exemplo n.º 3
0
void
reshape(int width, int height)
{
    float black[] = { 0, 0, 0, 0 };

    glViewport(0, 0, width, height);/*glViewport specifies the affine transformation of x and y from normalized device coordinates to window coordinates*/
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60, (float)width/height, 0.1, 1000);/*specifies a viewing frustum into the world coordinate system. In general, the aspect ratio in gluPerspective should match the aspect ratio of the associated viewport.*/
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(0, 1, 3, 0, 1, 0, 0, 1, 0);/*gluLookAt creates a viewing matrix derived from an eye point, a reference point indicating the center of the scene, and an UP vector.*/
    glFogfv(GL_FOG_COLOR, black);/*Fog is initially disabled. While enabled, fog affects rasterized geometry, bitmaps, and pixel blocks, but not buffer clear operations. To enable and disable fog, call glEnable and glDisable with argument GL_FOG.*/
    glFogf(GL_FOG_START, 2.5);
    glFogf(GL_FOG_END, 4);
    glEnable(GL_FOG);
    glFogi(GL_FOG_MODE, GL_LINEAR);
    glPointSize(point_size);
    glEnable(GL_POINT_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);/*glBlendFunc defines the operation of blending when it is enabled.*/
    glEnable(GL_COLOR_MATERIAL);/*specifies which material parameters track the current color*/
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHT0);
    timedelta();
}
Exemplo n.º 4
0
void
idle(void)
{
    static int i, j;
    static int living = 0;		/* index to end of live particles */
    static float dt;
    static float last = 0;

    dt = timedelta();
    frame_time += dt;

#if 1
    /* slow the simulation if we can't keep the frame rate up around
       10 fps */
    if (dt > 0.1) {
	slow_down = 1.0/(100*dt);
    } else if (dt < 0.1) {
	slow_down = 1;
    }
#endif

    dt *= slow_down;

    /* resurrect a few particles */
    for (i = 0; i < flow*dt; i++) {
	psNewParticle(&particles[living], dt);
	living++;
	if (living >= num_particles)
	    living = 0;
    }

    for (i = 0; i < num_particles; i++) {
	psTimeStep(&particles[i], dt);

	/* collision with sphere? */
	if (draw_spheres) {
	    for (j = 0; j < draw_spheres; j++) {
		psCollideSphere(&particles[i], &spheres[j]);
	    }
	}

	/* collision with ground? */
	if (particles[i].position[1] <= 0) {
	    psBounce(&particles[i], dt);
	}

	/* dead particle? */
	if (particles[i].position[1] < 0.1 && 
	    fequal(particles[i].velocity[1], 0)) {
	    particles[i].alive = 0;
	}
    }

    glutPostRedisplay();
}