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

SCM Repository

[diderot] Diff of /branches/lamont/test/boids/boids.diderot
ViewVC logotype

Diff of /branches/lamont/test/boids/boids.diderot

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

revision 2414, Mon Aug 19 05:02:14 2013 UTC revision 2415, Mon Aug 19 12:53:28 2013 UTC
# Line 1  Line 1 
1  real{} initVelocities = load("velocities.nrrd");  real{} initVelocities = load("velocities.nrrd");
2  real{} initPosns = load("posns.nrrd");  real{} initPosns = load("posns.nrrd");
3  int numBoids = length(initVelocities)/2;  int numBoids = 100;
4  real boidRadius = 2;  real boidRadius = 2;
5  real queryRadius = 50;  real queryRadius = 50;
6  int DESIRED_SEPARTION = 30;  int DESIRED_SEPARTION = 30;
# Line 49  Line 49 
49              cohereVec += neighbor.pos;              cohereVec += neighbor.pos;
50              alignVec += neighbor.vel;              alignVec += neighbor.vel;
51              count+=1;              count+=1;
52                 if(d < DESIRED_SEPARTION && d > 0) {
              if(d < DESIRED_SEPARTION) {  
53                 seperateVec = seperateVec + (normalize(pos-neighbor.pos)/d);                 seperateVec = seperateVec + (normalize(pos-neighbor.pos)/d);
54                     count2+=1;                     count2+=1;
55               }               }
56          }          }
57    
58    
59    
60          if(count > 0) {          if(count > 0) {
61                 cohereVec /= real(count);                 cohereVec /= real(count);
62             alignVec /= real(count);             alignVec /= real(count);
# Line 100  Line 101 
101    
102    
103          vec2 acceleration = cohereVec + alignVec + seperateVec;          vec2 acceleration = cohereVec + alignVec + seperateVec;
104    
105              vel += acceleration;              vel += acceleration;
106    
107              if (|vel| > MAX_SPEED){            /* if (|vel| > MAX_SPEED){
108                      isZero = cohereVec • cohereVec;
109                      if(isZero != 0) {
110                  vel = normalize(cohereVec);                  vel = normalize(cohereVec);
             vel *= MAX_SPEED;  
111              }              }
112                vel *= MAX_SPEED;
113                } */
114    
115    
116          pos += vel;          pos += vel;
117    
118    
119          //Wrapping Code, if a boid goes outside the window          //Wrapping Code, if a boid goes outside the window
120          real posX = wrapDimensions[EAST] if pos[0] < wrapDimensions[WEST]          real posX = wrapDimensions[EAST] if pos[0] < wrapDimensions[WEST]
121                                           else wrapDimensions[WEST] if pos[0] > wrapDimensions[EAST]                                           else wrapDimensions[WEST] if pos[0] > wrapDimensions[EAST]
# Line 120  Line 127 
127    
128          pos = [posX,posY];          pos = [posX,posY];
129    
130    
131    
132    
133           boidInfo = [pos[0],pos[1], vel[0], vel[1]];           boidInfo = [pos[0],pos[1], vel[0], vel[1]];
134    
135    

Legend:
Removed from v.2414  
changed lines
  Added in v.2415

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