Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
0:345b3bc7a0ea
Child:
1:a4050fee11f7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/blobConfig.cpp	Wed Mar 28 14:40:01 2012 +0000
@@ -0,0 +1,151 @@
+
+#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* pLoopRelax= new elasticLoop();
+  pLoopRelax->createBlob(blobArray.size(), RELAX, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
+  // add this relaxing loop to the present config:
+  blobArray.push_back(pLoopRelax);
+  
+  // update auxiliary variable numBlobs (just for easy reference): 
+  numBlobs=blobArray.size();
+ 
+}
+
+
+void blobConfig::addOneElasticLoopContract(){
+  elasticLoop* pLoopRelax= new elasticLoop();
+  pLoopRelax->createBlob(blobArray.size(), CONTRACT, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
+  // add this relaxing loop to the present config:
+  blobArray.push_back(pLoopRelax);
+  
+   // update auxiliary variable numBlobs (just for easy reference): 
+  numBlobs=blobArray.size();
+}
+
+void blobConfig::addOneElasticLoopContractCentral(){
+  elasticLoop* pLoopRelax= new elasticLoop();
+  pLoopRelax->createBlob(blobArray.size(), CONTRACT_CENTRAL, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
+   // add this relaxing loop to the present config:
+  blobArray.push_back(pLoopRelax);
+  
+   // update auxiliary variable numBlobs (just for easy reference): 
+  numBlobs=blobArray.size();
+}
+
+void blobConfig::addOneElasticContourFollowing(){
+  
+  elasticLoop* pLoopRelax= new elasticLoop();
+  pLoopRelax->createBlob(blobArray.size(), CONTOUR_FOLLOWING, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
+  // add this relaxing loop to the present config:
+  blobArray.push_back(pLoopRelax);
+  
+   // update auxiliary variable numBlobs (just for easy reference): 
+  numBlobs=blobArray.size();
+}
+
+
+void blobConfig:: addOneElasticContourFollowingFAST(){
+  elasticLoop* pLoopRelax= new elasticLoop();
+  pLoopRelax->createBlob(blobArray.size(), CONTOUR_FOLLOWING_FAST, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
+    // add this relaxing loop to the present config:
+  blobArray.push_back(pLoopRelax);
+  
+   // update auxiliary variable numBlobs (just for easy reference): 
+  numBlobs=blobArray.size();
+}
+
+void blobConfig::addOneElasticBouncing(){
+  elasticLoop* pLoopRelax= new elasticLoop();
+  pLoopRelax->createBlob(blobArray.size(), BOUNCING, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
+    // add this relaxing loop to the present config:
+  blobArray.push_back(pLoopRelax);
+  
+   // 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]->render==true)&&(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)
+  }
+}
+
+
+
+