Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/lamont/test/flocking/main.c
ViewVC logotype

Diff of /branches/lamont/test/flocking/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2121, Thu Feb 7 13:53:52 2013 UTC revision 2122, Thu Feb 7 18:41:18 2013 UTC
# Line 12  Line 12 
12  #define WIDTH   800  #define WIDTH   800
13  #define HEIGHT  600  #define HEIGHT  600
14    
15    #define NUMBOIDS
16    
17  /* Wrapping dimensions and indices */  /* Wrapping dimensions and indices */
18  #define NORTH 0  #define NORTH 0
19  #define SOUTH 1  #define SOUTH 1
# Line 25  Line 27 
27  #define STEP_SIZE       1  #define STEP_SIZE       1
28  #define SLEEP_MS        250  #define SLEEP_MS        250
29    
30  BOID_World_t *wrld = ISO_Init ();  BOID_World_t *wrld = BOID_Init();
31    bool isInitial = true;
32    
33  // nrrd for getting computational state  // nrrd for getting computational state
34  Nrrd *nData = nrrdNew();  Nrrd *nData = nrrdNew();
35    
# Line 54  Line 58 
58      else if(b[1] > wrapDimensions[SOUTH])      else if(b[1] > wrapDimensions[SOUTH])
59          b[1] = wrapDimensions[NORTH];          b[1] = wrapDimensions[NORTH];
60  }  }
61  void drawBoids(Nrrd *positions)  void DrawBoids(Nrrd *positions)
62  {  {
63      glMatrixMode(GL_MODELVIEW);      glMatrixMode(GL_MODELVIEW);
64      int r = 5;   // "radius" of the triangle      int r = 5;   // "radius" of the triangle
# Line 80  Line 84 
84          glPopMatrix();          glPopMatrix();
85       }       }
86  }  }
87  void display(void)  void Display(void)
88  {  {
89      glClearColor(1.0f, 1.0f, 1.0f, 1.0f);      glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
90      glClear(GL_COLOR_BUFFER_BIT);     // Clear The Screen And The Depth Buffer      glClear(GL_COLOR_BUFFER_BIT);     // Clear The Screen And The Depth Buffer
91      setUpView();      setUpView();
92    
93     // Main loop (repeated while window is not closed and [ESC] is not pressed)      // get and render initial state
94        if(isInitial){
95            GetData (wrld, nData);
96            DrawBoids(nData);
97            isInitial = false;
98            glutSwapBuffers();
99        }else {
100     if(BOID_NumActive(wrld) > 0){     if(BOID_NumActive(wrld) > 0){
101                // step the computation                // step the computation
102                BOID_Run (wrld, STEP_SIZE);                BOID_Run (wrld, STEP_SIZE);
103                // get and render the state                // get and render the state
104                GetData (wrld, nData);                GetData (wrld, nData);
105                drawBoids(nData);              DrawBoids(nData);
106                usleep (SLEEP_MS * 50);  // sleep for a bit              glutSwapBuffers();
107              }              glutTimerFunc(50,flock, 0);
             if (BOID_NumActive(wrld) == 0) {  
               // get and render final state  
                 if (ISO_OutputGet_pos (wrld, nData)) {  
                   // error  
                     fprintf(stderr, "Error getting nrrd data\n");  
                     exit(1);  
                 }  
                 Draw (nData);  
             }  
108          }          }
109      }      }
110    
   // shutdown the world  
     BOID_Shutdown (wrld);  
     glutSwapBuffers();  
     glutTimerFunc(50,flock, 0);  
111  }  }
112  void GetData (BOID_World_t *wrld, Nrrd *nData)  void GetData (BOID_World_t *wrld, Nrrd *nData)
113  {  {
114    // get snapshot of state    // get snapshot of state
115      if (BOID_Snapshot_pos (wrld, nData)) {      if (BOID_Snapshot_boidInfo(wrld, nData)) {
116        // error        // error
117          fprintf(stderr, "Error getting nrrd data\n");          fprintf(stderr, "Error getting nrrd data\n");
118          exit(1);          exit(1);
# Line 127  Line 124 
124      glutInit(&argc, argv);      glutInit(&argc, argv);
125      glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);      glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
126      glutInitWindowSize(CurrentWidth, CurrentHeight);      glutInitWindowSize(CurrentWidth, CurrentHeight);
127      glutCreateWindow("Flocking Program");      glutCreateWindow("Flocking Diderot Program");
128      glutDisplayFunc(&display);      glutDisplayFunc(&Display);
129      glutReshapeFunc(&resizeWindow);      glutReshapeFunc(&resizeWindow);
130    
131      // initialize the Diderot program      // initialize the Diderot program
132      ISO_InVarSet_stepScale (wrld, 0.05);      BOID_InVarSet_width (wrld, CurrentWidth);
133      ISO_InVarSet_stepsMax (wrld, 200);      BOID_InVarSet_height(wrld, CurrentHeight);
134      ISO_Initially (wrld);      BOID_Initially (wrld);
135    
136      glutTimerFunc(50,display, 0);      glutTimerFunc(50,Display, 0);
137    
138      glutMainLoop();      glutMainLoop();
139    
140      return 0;      return 0;
141  }  }

Legend:
Removed from v.2121  
changed lines
  Added in v.2122

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0