#include #include #include #include #include #include #include "erosion_particle.h" //include "suzie_maths.h" /********************************************************************* * Initialize the openGL viewing area as a two dimensional orthogonal * viewing window. ********************************************************************/ void initialize( void ) { //Set the background colour to white glClearColor( 1.0, 1.0, 1.0, 1.0 ); //Default drawing colour set to red glColor3f( 1.0, 0.0, 0.0 ); //Set up viewing area for a projection viewing area, (frustum) glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluOrtho2D( 0.0, SCREEN, 0.0, SCREEN ); glMatrixMode( GL_MODELVIEW ); } /******************************************************************* * OpenGL display function ******************************************************************/ void display( void ) { int base = BASE, count = 0, count2 = 0, countX, collide; float originX = 0, originY = 0, particleX = 0, particleY; float heightField[NUM_STEPS]; float random, testVariable; int height, total_particles = 0; Particle particle; /* Create the openGL list for a box */ createBox(); glClear( GL_COLOR_BUFFER_BIT ); srand( time(NULL) ); /* Initialize the terrain structure */ createTerrain( heightField ); //fprintf(stderr, "directly after createTerrain: %.2f\n", heightField[20]); //fprintf(stderr, "no. of steps: %d\n", NUM_STEPS); /* Count the total number of particles in the heap */ for( count = 0; count < NUM_STEPS; count++ ) { //fprintf(stderr, "count = %d\n", count ); //fprintf(stderr, "x: %d, y: %.2f\n", count, heightField[count] ); total_particles += heightField[count]/(RADIUS*2); //fprintf(stderr, "total particles at %d is %d\n", count, total_particles ); } glutSwapBuffers(); //printf("still finished with creating terrain\n"); /* While there are still particle left in the pile */ while( total_particles > 0 ) { for( count = 0; count < NUM_STEPS; count++ ) { fprintf(stderr, "looking at column %d\n", count ); /* If the current column has no particles, move to the next */ if( heightField[count] > 0 ) { /* Determine where the particle moves to, if it moves at all */ move_particle( count, heightField, &total_particles ); } glClear( GL_COLOR_BUFFER_BIT ); redrawTerrain( heightField ); //fprintf(stderr, "just redrawn terrain\n"); glutSwapBuffers(); } } } /************************************************************************ * main() ***********************************************************************/ int main( int argc, char** argv ) { FILE* input; if( argc < 2 ) { NUM_STEPS = (int)SCREEN/(RADIUS*2); VELOCITY_X = RADIUS*2; fprintf(stderr, "No input file given, using defaults\n"); } else if( strcmp( argv[1], "help" )== 0 ) { printf("Input file requires an indication of wind strength, given as an integer\n"); printf("between 0 and 10, with 10 being the maximum strength. Probability of an\n"); printf("unprotected particle being shifted is calculated as wind strength over\n"); printf("21 times the radius. This means there will always be some chance that the\n"); printf("particle will not move even in the strongest wind.\n"); printf("Input file is as follows:\n"); printf("radius(float), wind strength(float between 0 and 20)\n"); exit(1); } else { input = fopen( argv[1], "r" ); if( !input ) fprintf(stderr, "input file did not open, using defaults\n"); else { fscanf( input, "%f, %f\n", &RADIUS, &WIND_STRENGTH ); fclose( input ); NUM_STEPS = (int)SCREEN/(RADIUS*2); WIND_STRENGTH *= RADIUS; } } glutInit( &argc, argv ); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB ); glutInitWindowSize( SCREEN, SCREEN ); glutInitWindowPosition( 0, 0); glutCreateWindow("Deposition simulation"); glutDisplayFunc( display ); initialize(); glutMainLoop(); }