just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
28:44b7b6e35548
Parent:
27:1ce994629ffc
Child:
29:2fc8c12822eb
--- a/rigidLoop.cpp	Mon Jun 18 15:09:25 2012 +0000
+++ b/rigidLoop.cpp	Tue Jun 19 11:22:46 2012 +0000
@@ -75,7 +75,7 @@
             setColor(0x04);
 
             // default (initial) shape (the scafold belongs to the base class):
-            saccadeRadius=40;
+            saccadeRadius=25;
             bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
 
             // Note: We may assume NO MASS for the center of the contour following loop. Adding mass may be interesting though (smooth motion).
@@ -109,13 +109,45 @@
             
             gravity.set(0,0);
 
-            saccadeRadius=65;//+rand()%20;
+            saccadeRadius=35;//+rand()%20;
             // default (initial) shape (the scafold belongs to the base class):
             bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
 
             // Numeric parameters for the simulated mechanical system:
             massCenter=0.0008;//+0.000005*(rand()%100);
-            dampMotionCenterMass=0.00045;//0.00015;//00003;
+            dampMotionCenterMass=0.0006;//0.00015;//00003;
+            factorBouncingForce=0.0018; // this is because we will use a force on the central mass
+
+            // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
+            createLoopFromScafold();
+
+            // per-blob mirror delay (if things were well adjusted - in particular mirror waiting times, then this could be 0.
+            // But in case of unique blobs, it may be interesting to accelerate display AND correct the delay by software).
+            // Even more interesting: in case of rigid circular blob, this can be coorected using angleCorrectionForceLoop:
+            displaySensingBuffer.setDelayMirrors(3);
+            angleCorrectionForceLoop=-5;// in degrees
+
+            break;
+            
+            case  SPOT_AIR_HOCKEY:
+            // Name of this kind of spot:
+            sprintf(spotName,"air_hockey");
+
+            //startCenter.set(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y);
+            //startSpeed.set(0,0); 
+
+            //setColor(0x07);//0x04+0x02>>i);
+            setColor(0x04);
+            
+            gravity.set(0,0);
+
+            saccadeRadius=50;//+rand()%20;
+            // default (initial) shape (the scafold belongs to the base class):
+            bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
+
+            // Numeric parameters for the simulated mechanical system:
+            massCenter=0.0008;//+0.000005*(rand()%100);
+            dampMotionCenterMass=0.00065;//0.00015;//00003;
             factorBouncingForce=0.0018; // this is because we will use a force on the central mass
 
             // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
@@ -136,14 +168,14 @@
             //setColor(0x07);//0x04+0x02>>i);
             setColor(0x04);
 
-            saccadeRadius=40;//+rand()%20;
+            saccadeRadius=25;//+rand()%20;
             // default (initial) shape (the scafold belongs to the base class):
-            bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos,vector2D _vel, int _numScafoldPoints);
+            bluePrint.buildCircularScafold(saccadeRadius, vector2Dd(0,0), 18); //(float _radius, vector2D _pos, int _numScafoldPoints);
 
             // Numeric parameters for the simulated mechanical system:
             massCenter=0.0005;//+0.000005*(rand()%100);
-            dampMotionCenterMass=0.00045;//0.00015;//00003;
-            factorBouncingForce=0.0018; // this is because we will use a force on the central mass
+            dampMotionCenterMass=0.001;//0.00015;//00003;
+            factorBouncingForce=0.0015; // this is because we will use a force on the central mass
 
             // Finally, we can create the loop (not much to do in this case, only set the central position, and some other things):
             createLoopFromScafold();
@@ -315,6 +347,15 @@
            //      transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
            // else 
             transientBlobColor=blobColor; // just the original blob color
+              
+        // change sliding direction (for countour following):
+        if (blobWallCollision) {
+            if (wallCounter>5) {
+              slidingDirection=!slidingDirection;
+            wallCounter=0;
+            }
+        }
+        wallCounter++;
 
             break;
 
@@ -370,7 +411,7 @@
              
             break;
             
-            case  SPOT_FOUNTAIN:
+            case  SPOT_AIR_HOCKEY:
             // this is very simple: we need to give a force to the centralMass that is OPPOSITE to the recenteringVectorLoop vector
             centerMass.resetForce();
 
@@ -387,10 +428,18 @@
              
             }
             
-            // RADIAL GRAVITY for the "fountain mode":
-            vector2Df centerAttraction(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_X); 
-            vector2Df dist=centerMass.pos-centerAttraction;
-            centerMass.addForce(dist.normalize()*centerMass.mass*0.5);
+            // Gravity? - side or central attraction?
+            //centerMass.addForce(gravity*centerMass.mass); 
+            
+            // or central spring attraction;
+            //vector2Df centerAttraction(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_X); 
+            //vector2Df dist=centerMass.pos-centerAttraction;
+            //centerMass.addForce(-dist*centerMass.mass*0.0007);
+            
+            // or "radial gravity":
+            //vector2Df centerAttraction(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_X); 
+            //vector2Df dist=centerMass.pos-centerAttraction;
+            //centerMass.addForce(dist.normalize()*centerMass.mass*0.5);
           
 
             // update dynamics for the central mass:
@@ -411,22 +460,68 @@
                  transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
             else 
                  transientBlobColor=blobColor; // just the original blob color
+             
+             // In case of "air hockey mode", reset position to initial positions and speeds when the spot touches two opposites sides:
+             if ((centerMass.innerCollitionDirection.y==1)||( centerMass.innerCollitionDirection.y==-1)) 
+                centerMass.setInitialCondition(startCenter, startSpeed);  
+        
+             
+            break;
             
-            // In case of "fountain mode", reset position to initial positions and speeds:
-             if (blobWallCollision) centerMass.setInitialCondition(startCenter, startSpeed);  
+            case  SPOT_FOUNTAIN:
+            // this is very simple: we need to give a force to the centralMass that is OPPOSITE to the recenteringVectorLoop vector
+            centerMass.resetForce();
+
+        if (displaySensingBuffer.lightTouched) {
+            // add force; MANY POSSIBILITIES:
+            // (1) Constant in norm:
+            //centerMass.addForce(unitTowardsLight*saccadeRadius*factorBouncingForce);
+            // Exactly what is needed to have an elastic bouncing:
+            
+            // Proportional to the penetration depth in the dark zone (spring):
+             centerMass.addForce(recenteringVectorLoop*factorBouncingForce);
+             // Or proportional to the square (or something else) of the penetration:
+             //centerMass.addForce(recenteringVectorLoop*normRecenteringVector*factorBouncingForce);
              
+            }
+            
+            // RADIAL GRAVITY for the "fountain mode":
+           // vector2Df centerAttraction(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_X); 
+           // vector2Df radialVector=centerMass.pos-centerAttraction;
+           // radialVector.rotateDeg(slidingDirection? 80 : 260);
+           // centerMass.addForce(radialVector.normalize()*centerMass.mass*0.5);
+           
+            // bubble chamber? LORENTZ FORCE:
+            vector2Df speedmass=centerMass.getSpeed();
+            centerMass.addForce( speedmass.getRotatedDeg(90)*0.000002*speedContourFollowing);
+           
+            // update dynamics for the central mass:
+#ifndef VERLET_METHOD
+            centerMass.addDampingForce();  // // only in case of EULER method (damping in VERLET mode is done automatically when updating)
+#endif
+
+            centerMass.update();  // unconstrained
+            centerMass.bounceOffWalls(); // constrain position (and compute wall "hit")
+            
+             if (displaySensingBuffer.lightTouched) {
+            // do collision damping:
+               centerMass.setSpeed(centerMass.getSpeed()*0.99);
+             }
+             
+            // Change color with touch? YES
+            if (displaySensingBuffer.lightTouched)  
+                 transientBlobColor=blobColor|0x02; // set green ON on the trajectory, regardless of the initial color
+            else 
+                 transientBlobColor=blobColor; // just the original blob color
+            
+            // In case of "fountain mode", reset position to initial positions and speeds, or change gravity sign:
+           //  if (blobWallCollision) centerMass.setInitialCondition(startCenter, startSpeed);  
+             if (blobWallCollision) slidingDirection=!slidingDirection;
+            
+            
             break;
     }
     
-    
-    // change sliding direction (for countour following):
-    if (blobWallCollision) {
-        if (wallCounter>5) {
-            slidingDirection=!slidingDirection;
-            wallCounter=0;
-        }
-    }
-    wallCounter++;
 }