How to create objects with the BlobDetection library that 'live and die' with the blobs

edited December 2013 in Library Questions

For every Blob detected by the library I create a new object of my class Metaball.

void createMetaballs() 
{
  Blob blob;
  Metaball mettball;
  int numberOfBlobs = theBlobDetection.getBlobNb(); 
  int numberOfMetaballs = 0;
  float blobX, blobY;
  for (int n=0; n<numberOfBlobs; n++)
  {
    blob=theBlobDetection.getBlob(n);
    blobX=blob.x*width;
    blobY=blob.y*height;
    if (blob != null && numberOfMetaballs <= numberOfBlobs) 
    {
      mettball = new Metaball(blobX, blobY);
      mettball.id = blob.id;
      metaballs.add(mettball);
      numberOfMetaballs++;
    }
  }
  text("Mettbälle: " + metaballs.size() + " / Blobs: " + numberOfBlobs, 10, height-10);
} 

The problem for which I didn't manage to come up with a solution is how to kill the Metaball when a blob 'dies'. I tried to remove them from the arraylist when a blob is null but I didn't worked and the method just creates more metaballs... Somehow I have to compare the metaball with the blob I guess. Any ideas? Highly appreciated

Sign In or Register to comment.