diff lump.mm @ 4:79c7cf39a0a0

Fixed new mesh crash - static array bounds. Made home made mutex for wavetable access. Less clicks?
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Mon, 10 Dec 2012 13:00:03 +0000
parents c667dfe12d47
children 085d80989ba7
line wrap: on
line diff
--- a/lump.mm	Fri Dec 07 19:20:57 2012 +0000
+++ b/lump.mm	Mon Dec 10 13:00:03 2012 +0000
@@ -16,7 +16,7 @@
 //int Lump::numLumps = 0;
 //--------------------------------------------------------------
 // default constr
-Lump::Lump() : maxSprings(100){
+Lump::Lump(){
 	//cout << "constructing a default lump" << endl;
 	mass = 10.0;
 	inverseMass = 1.0/mass; // not needed - used csquared for force
@@ -34,45 +34,40 @@
 	totalForceMag = 0.0;
 	size = 3; //sqrt(mass/3.0);
     isInScanPath = false;
+    isScanPathStart = false;
+    isScanPathEnd = false;
+    
     previousPosition.setCoord(0.5,0.5);
     zeroRefPos.setCoord(0.0,0.0);
     constrainMode = NOT_CONSTRAINED;
-    
-    attachedSprings = new Spring*[maxSprings];
+
     
     grabID = -1;
-	//myIndex = Lump::numLumps++;
-    //cout << numAttachedSprings << endl;
 	
 }
 //--------------------------------------------------------------
 // arg constructor
-Lump::Lump(double aMass,double aFriction, double positionX, double positionY) : maxSprings(100){
+Lump::Lump(double aMass,double aFriction, double positionX, double positionY){
 		// set members
 
 }
 
 //--------------------------------------------------------------
 Lump::~Lump(){
-    
-    delete [] attachedSprings;
+
 }
 //--------------------------------------------------------------
 void Lump::attachSpring(Spring* aSpring){
 	
-	// stick pointer in array
-	if(numAttachedSprings < maxSprings){
-		attachedSprings[numAttachedSprings] = aSpring;
-		numAttachedSprings++;
-	}else{
-		cout << "cant attach another spring as mass already has " << maxSprings << endl;
-		return;
-	}
+    
+    attachedSprings.push_back(aSpring);
+    numAttachedSprings++;
+
 }
 //--------------------------------------------------------------
 Spring * Lump::checkConnectedTo(Lump * otherLump){
     // loop thru all attached springs looking at other end
-    for(int i = 0; i<numAttachedSprings; i++){
+    for(int i = 0; i<attachedSprings.size(); i++){
         if(attachedSprings[i]->getLumpOnOtherEnd(this) == otherLump){
             return attachedSprings[i];
         }
@@ -122,7 +117,18 @@
         int xpos = position.x * ofGetHeight() + globalUI.borderSize;
         int ypos = position.y * ofGetHeight();
         ofEllipse(xpos,ypos, 6, 6);
-        
+        if(isScanPathEnd){
+            ofSetColor(255, 255, 0);
+            ofNoFill();
+            ofCircle(xpos, ypos, 6.0);
+            ofFill();
+        }
+        if(isScanPathStart){
+            ofSetColor(0, 255, 255);
+            ofNoFill();
+            ofCircle(xpos, ypos, 7.0);
+            ofFill();
+        }
         // code to display restpos and displacement
         /*
         ofSetColor(0, 0, 0);
@@ -141,7 +147,10 @@
         int ypos = position.y * ofGetHeight();
         ofEllipse(xpos,ypos, 2, 2);
 	}else if (constrained){
-		ofSetColor(200,23,23);
+		ofSetColor(200,5,5);
+        int xpos = position.x * ofGetHeight() + globalUI.borderSize;
+        int ypos = position.y * ofGetHeight();
+        ofEllipse(xpos,ypos, 2, 2);
 	}else{
         // dont draw 'normal ' lumps
         return;
@@ -166,7 +175,7 @@
 	TwoVector totalForce(0.0,0.0);
 	
 	// sum up force from each attached spring
-	for(int i = 0;i<numAttachedSprings; i++){
+	for(int i = 0;i<attachedSprings.size(); i++){
 
         springForce = (attachedSprings[i])->getForce(this);
         
@@ -260,14 +269,14 @@
     if (constrained || grabbed) return;
     double avx = 0.0, avy = 0.0;
     // average the position of all the attached lumps
-    for(int i = 0;i<numAttachedSprings; i++){
+    for(int i = 0;i<attachedSprings.size(); i++){
         
         Lump* otherLump = attachedSprings[i]->getLumpOnOtherEnd(this);
         avx += otherLump->position.x;
         avy += otherLump->position.y;
 	}
-    avx /= numAttachedSprings;
-    avy /= numAttachedSprings;
+    avx /= attachedSprings.size();
+    avy /= attachedSprings.size();
     
     // mix in the average with the 'real'
     position.x = (1 - amt)*position.x + amt*avx;
@@ -281,14 +290,14 @@
     //TODO what if edges unconstrained? this is why filtered unconstrained just ends up as a line...
 
     // average the position of all the attached lumps
-    for(int i = 0;i<numAttachedSprings; i++){
+    for(int i = 0;i<attachedSprings.size(); i++){
         
         Lump* otherLump = attachedSprings[i]->getLumpOnOtherEnd(this);
         av.x += otherLump->position.x;
         av.y += otherLump->position.y;
 	}
-    av.x /= numAttachedSprings;
-    av.y /= numAttachedSprings;
+    av.x /= attachedSprings.size();
+    av.y /= attachedSprings.size();
     
     return av;