1212Swarm::Swarm ()
1313{
1414 // constructor, let's set some defaults
15- nParticles = 0 ;
15+ nParticles = 0 ;
1616 light.setAmbientColor (ofColor (0 ,0 ,0 ));
1717}
1818
@@ -24,23 +24,23 @@ void Swarm::init(int _nParticles, float positionDispersion, float velocityDisper
2424 //
2525 if (nParticles > 0 )
2626 {
27- ofLog (OF_LOG_WARNING, " Swarm: Already initialised" ) ;
28-
27+ ofLog (OF_LOG_WARNING) << " Swarm: Already initialised" ;
28+
2929 // delete[] = delete array from memory
3030 delete[] positions;
3131 delete[] velocities;
3232 delete[] colors;
33-
33+
3434 // superfluous line of code..
3535 nParticles = 0 ;
3636 }
3737 // /////////////////////////////////////////
38-
39-
38+
39+
4040 // Swarm's internal variable set from argument
41- nParticles = _nParticles;
42-
43-
41+ nParticles = _nParticles;
42+
43+
4444 // /////////////////////////////////////////
4545 // SETUP ARRAYS
4646 // /////////////////////////////////////////
@@ -50,8 +50,8 @@ void Swarm::init(int _nParticles, float positionDispersion, float velocityDisper
5050 colors = new ofColor[nParticles];
5151 //
5252 // /////////////////////////////////////////
53-
54-
53+
54+
5555 // /////////////////////////////////////////
5656 // INITIALISE VALUES
5757 // /////////////////////////////////////////
@@ -61,26 +61,26 @@ void Swarm::init(int _nParticles, float positionDispersion, float velocityDisper
6161 positions[i].x = (ofRandom (1 .0f )-0 .5f ) * positionDispersion;
6262 positions[i].y = (ofRandom (1 .0f )-0 .5f ) * positionDispersion;
6363 positions[i].z = (ofRandom (1 .0f )-0 .5f ) * positionDispersion;
64-
64+
6565 velocities[i].x = (ofRandom (1 .0f )-0 .5f ) * velocityDispersion;
6666 velocities[i].y = (ofRandom (1 .0f )-0 .5f ) * velocityDispersion;
6767 velocities[i].z = (ofRandom (1 .0f )-0 .5f ) * velocityDispersion;
68-
68+
6969 colors[i].r = ofRandom (255 .0f );
7070 colors[i].g = ofRandom (255 .0f );
7171 colors[i].b = 150 .0f ;
7272 colors[i].a = 255 .0f ;
7373 }
7474 //
7575 // /////////////////////////////////////////
76-
76+
7777}
7878
7979void Swarm::customDraw ()
8080{
8181 // /we run the update ourselves manually
8282 update ();
83-
83+
8484 // we use the position of the first
8585 // particle as the position of the
8686 // light
@@ -97,17 +97,17 @@ void Swarm::customDraw()
9797 {
9898 ofPushStyle ();
9999 ofSetColor (colors[i]);
100-
100+
101101 ofDrawSphere (positions[i], 1.0 );
102-
102+
103103 ofPopStyle ();
104104 }
105105 //
106106 // /////////////////////////////////////////
107-
107+
108108 light.disable ();
109109 ofDisableLighting ();
110-
110+
111111 // render light as white sphere
112112 ofSetColor (255 , 255 , 255 );
113113 ofDrawSphere (positions[0 ], 2.0 );
@@ -118,16 +118,16 @@ void Swarm::customDraw()
118118
119119void Swarm::update ()
120120{
121-
121+
122122 // calculate time past per frame
123123 float dt = ofGetElapsedTimef () - timeLastUpdate;
124124 timeLastUpdate = ofGetElapsedTimef ();
125-
125+
126126 // update positions, velocities
127127 for (int i=0 ; i< nParticles; i++)
128128 {
129129 // //////////////////////////////
130- //
130+ //
131131 // MOTION MATHS
132132 //
133133 // 'Simple Harmonic Motion'
@@ -159,7 +159,7 @@ void Swarm::update()
159159 // v = v + (dt * a)
160160 // v = v + (dt * -k * x)
161161 //
162- velocities[i] += - SPRING_CONSTANT * positions[i] * dt;
162+ velocities[i] += - SPRING_CONSTANT * positions[i] * dt;
163163 //
164164 // ///////////////////////////////
165165
0 commit comments