Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

blobConfig.cpp

Committer:
mbedalvaro
Date:
2012-04-12
Revision:
14:0fc33a3a7b4b
Parent:
12:0de9cd2bced5
Child:
18:d72935b13858

File content as of revision 14:0fc33a3a7b4b:


#include "blobConfig.h"
#include "hardwareIO.h" // this is in fact only to get to know the initial position of the spots, as well as the mirror limits to set the bounding box for the blobs

blobConfig::blobConfig(): numBlobs(0) {
    //blobArray.clear();// there is no need to do this, the vector does not contains anything here.

}

blobConfig::~blobConfig() {
    clearConfig();

}

// =========================================== STANDARD CONFIGURATIONS =============================================================================

void blobConfig::computeBoundingBox() {
    for (int i=0; i<blobArray.size(); i++) {
        blobArray[i]->computeBoundingBox();
    }
}

void blobConfig::clearConfig() {
    for (int i=0; i<blobArray.size(); i++) delete blobArray[i]; // we must delete the pointer created with new, so the memory for the object is liberated (calls its destructor)
    blobArray.clear();
    numBlobs=0;// this is just equal to blobArray.size()
}

void blobConfig::addOneElasticLoopRelax() {
    elasticLoop* pBlob= new elasticLoop();
    pBlob->createBlob(blobArray.size(), RELAX, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
    // add this relaxing loop to the present config:
    blobArray.push_back(pBlob);

    // update auxiliary variable numBlobs (just for easy reference):
    numBlobs=blobArray.size();

}


void blobConfig::addOneElasticLoopContract() {
    elasticLoop* pBlob= new elasticLoop();
    pBlob->createBlob(blobArray.size(), CONTRACT, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
    // add this relaxing loop to the present config:
    blobArray.push_back(pBlob);

    // update auxiliary variable numBlobs (just for easy reference):
    numBlobs=blobArray.size();
}

void blobConfig::addOneElasticLoopContractCentral() {
    elasticLoop* pBlob= new elasticLoop();
    pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
    // add this relaxing loop to the present config:
    blobArray.push_back(pBlob);

    // update auxiliary variable numBlobs (just for easy reference):
    numBlobs=blobArray.size();
}

void blobConfig::addOneElasticContourFollowing() {

    elasticLoop* pBlob= new elasticLoop();
    pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING, vector2Df(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()), vector2Df(0,0));
    // add this relaxing loop to the present config:
    blobArray.push_back(pBlob);

    // update auxiliary variable numBlobs (just for easy reference):
    numBlobs=blobArray.size();
}


void blobConfig:: addOneElasticContourFollowingFAST() {
    elasticLoop* pBlob= new elasticLoop();
    pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING_FAST, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
    // add this relaxing loop to the present config:
    blobArray.push_back(pBlob);

    // update auxiliary variable numBlobs (just for easy reference):
    numBlobs=blobArray.size();
}

void blobConfig::addOneElasticBouncing() {
    elasticLoop* pBlob= new elasticLoop();
    pBlob->createBlob(blobArray.size(), BOUNCING, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(1,1));
    // add this relaxing loop to the present config:
    blobArray.push_back(pBlob);

    // update auxiliary variable numBlobs (just for easy reference):
    numBlobs=blobArray.size();
}

void blobConfig::addOneRigidLoopBouncing() {
    rigidLoop* pBlob= new rigidLoop();
    pBlob->createBlob(blobArray.size(), SPOT_BOUNCING, vector2Df(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()), vector2Df(0,0));
    // add this relaxing loop to the present config:
    blobArray.push_back(pBlob);

    // update auxiliary variable numBlobs (just for easy reference):
    numBlobs=blobArray.size();
}

void blobConfig::addOneRigidLoopFollowing() {
    rigidLoop* pBlob= new rigidLoop();
    pBlob->createBlob(blobArray.size(), SPOT_FOLLOWING, vector2Df(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()), vector2Df(0,0));
    // add this relaxing loop to the present config:
    blobArray.push_back(pBlob);

    // update auxiliary variable numBlobs (just for easy reference):
    numBlobs=blobArray.size();
}

void blobConfig::addOneRigidLoopTest() {
    rigidLoop* pBlob= new rigidLoop();
    pBlob->createBlob(blobArray.size(), SPOT_TEST, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0));
    // add this relaxing loop to the present config:
    blobArray.push_back(pBlob);

    // update auxiliary variable numBlobs (just for easy reference):
    numBlobs=blobArray.size();
}


// ==================================================================================================================================================


void blobConfig::allKill() { // this put all the blobs in "dead" mode, meaning that neither rendering nor update is done (but they are not deleted).
    for (int i=0; i<blobArray.size(); i++) {
        blobArray[i]->render = false;
        blobArray[i]->standByMode = false;
    }
}
void blobConfig::allAlive() {
    for (int i=0; i<blobArray.size(); i++) {
        blobArray[i]->render = true;
        blobArray[i]->standByMode = true;
    }
}

void blobConfig::allStandBy() {
    for (int i=0; i<blobArray.size(); i++) blobArray[i]->standByMode = true;
}

void blobConfig::allResume() {
    for (int i=0; i<blobArray.size(); i++) blobArray[i]->standByMode = false;
}

void blobConfig::allVisible() {
    for (int i=0; i<blobArray.size(); i++) blobArray[i]->render = true;
}

void blobConfig::allInvisible() { // note that they may continue to evolve
    for (int i=0; i<blobArray.size(); i++) blobArray[i]->render = false;
}

void blobConfig::update() { // update dynamics of the blob
    for (int i=0; i<blobArray.size(); i++) {
        if (blobArray[i]->standByMode==false) blobArray[i]->update();
    }
}

void blobConfig::draw() { // draw uses the opengl like renderer (if any), and save projected trajectory in the LaserSensingTrajectory object of each blob
    for (int i=0; i<blobArray.size(); i++) {
        if (blobArray[i]->render==true) blobArray[i]->draw();
    }
}

void blobConfig::sendConfData() {
// For the time being, only "per blob" data sending:
// (b) Per-spot sending of data (note: both are NOT exclusive; so if we want just packaged data, we need to make all the spot STOP sending data.
    for (int i=0; i<blobArray.size(); i++) {
        if (blobArray[i]->render==true) blobArray[i]->sendData(); // a blob that is in stand-by mode may send data (good for testing with a fixed loop)
    }
}