Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
soundSpot.cpp@19:228430f1350e, 2012-04-28 (annotated)
- Committer:
- mbedalvaro
- Date:
- Sat Apr 28 13:42:14 2012 +0000
- Revision:
- 19:228430f1350e
- Parent:
- 18:d72935b13858
- Child:
- 21:bc9b9383f4b6
relatively stable. Now need to make commands to control speed/stiffness/color and size of spot form the computer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:345b3bc7a0ea | 1 | #include "soundSpot.h" |
mbedalvaro | 0:345b3bc7a0ea | 2 | |
mbedalvaro | 0:345b3bc7a0ea | 3 | // Constructor: |
mbedalvaro | 0:345b3bc7a0ea | 4 | soundSpot::soundSpot() { // by default, the child constructor call the parameterless default constructor (we could force another by doing: soundSpot::soundSpot : LivingSpot (params...) { ..} |
mbedalvaro | 0:345b3bc7a0ea | 5 | |
mbedalvaro | 0:345b3bc7a0ea | 6 | // DEFAULT sending mode will be all off: |
mbedalvaro | 0:345b3bc7a0ea | 7 | stopAllSending(); |
mbedalvaro | 0:345b3bc7a0ea | 8 | resetAllSendingModes(); |
mbedalvaro | 0:345b3bc7a0ea | 9 | |
mbedalvaro | 0:345b3bc7a0ea | 10 | initCommonVariables(); |
mbedalvaro | 18:d72935b13858 | 11 | |
mbedalvaro | 18:d72935b13858 | 12 | // initialize timer for sending OSC data: |
mbedalvaro | 18:d72935b13858 | 13 | periodSendingData=25;// by default, we send the data every 25 ms. Note: the "data" to send will of course depend on the kind of blob. That will be therefore re-set when |
mbedalvaro | 18:d72935b13858 | 14 | // instantiating the kind of blob. |
mbedalvaro | 18:d72935b13858 | 15 | measureSendPeriod.start(); |
mbedalvaro | 0:345b3bc7a0ea | 16 | } |
mbedalvaro | 0:345b3bc7a0ea | 17 | |
mbedalvaro | 0:345b3bc7a0ea | 18 | // IMPORTANT: the destructor of the base class is virtual, but it won't be implemented with the same name in the child class; therefore, it |
mbedalvaro | 0:345b3bc7a0ea | 19 | // must be implemented in the base class (and it will be called when using delete of the child, first the delete child, then delete base) |
mbedalvaro | 0:345b3bc7a0ea | 20 | soundSpot::~soundSpot() { |
mbedalvaro | 0:345b3bc7a0ea | 21 | } |
mbedalvaro | 0:345b3bc7a0ea | 22 | |
mbedalvaro | 12:0de9cd2bced5 | 23 | void soundSpot::setColor(unsigned char c) { |
mbedalvaro | 0:345b3bc7a0ea | 24 | blobColor=0x07&c; // we will use the first three bits to set the RGB colors. |
mbedalvaro | 0:345b3bc7a0ea | 25 | } |
mbedalvaro | 0:345b3bc7a0ea | 26 | |
mbedalvaro | 0:345b3bc7a0ea | 27 | void soundSpot::initCommonVariables() { |
mbedalvaro | 0:345b3bc7a0ea | 28 | firstTimeNoTouch=true; |
mbedalvaro | 0:345b3bc7a0ea | 29 | // randomForce.set(1,0);// first time there won't be any force, or random force |
mbedalvaro | 0:345b3bc7a0ea | 30 | // randomForce=randomForce.getRotatedDeg(1.0*(rand()%360)); |
mbedalvaro | 0:345b3bc7a0ea | 31 | // randomForce.normalize(); |
mbedalvaro | 0:345b3bc7a0ea | 32 | |
mbedalvaro | 0:345b3bc7a0ea | 33 | noTouchedCounter=0; |
mbedalvaro | 0:345b3bc7a0ea | 34 | wallCounter=0; |
mbedalvaro | 0:345b3bc7a0ea | 35 | blobWallCollision=false; |
mbedalvaro | 0:345b3bc7a0ea | 36 | //slidingDirection=true; // (will change when touching wall) |
mbedalvaro | 0:345b3bc7a0ea | 37 | |
mbedalvaro | 0:345b3bc7a0ea | 38 | render=true; |
mbedalvaro | 0:345b3bc7a0ea | 39 | standByMode=false; |
mbedalvaro | 0:345b3bc7a0ea | 40 | } |
mbedalvaro | 0:345b3bc7a0ea | 41 | |
mbedalvaro | 0:345b3bc7a0ea | 42 | void soundSpot::resetAllSendingModes() { |
mbedalvaro | 0:345b3bc7a0ea | 43 | // RESET SENDING DATA: |
mbedalvaro | 18:d72935b13858 | 44 | sendingOnlyWhenTouch=false; |
mbedalvaro | 0:345b3bc7a0ea | 45 | // (a) anchor mass data: |
mbedalvaro | 0:345b3bc7a0ea | 46 | sendingAnchorPosition=false; |
mbedalvaro | 0:345b3bc7a0ea | 47 | sendingAnchorForce=false; // this is the total force on the anchor mass, not just the recentering force |
mbedalvaro | 0:345b3bc7a0ea | 48 | sendingAnchorTouchWall=false; |
mbedalvaro | 0:345b3bc7a0ea | 49 | // (b) data from blob points: |
mbedalvaro | 18:d72935b13858 | 50 | sendingLoopPositions=false; |
mbedalvaro | 0:345b3bc7a0ea | 51 | sendingLoopForces=false;// this is not just the forces from light, but all the forces in each particle |
mbedalvaro | 0:345b3bc7a0ea | 52 | sendingLoopForcesLight=false;// forces only from light |
mbedalvaro | 0:345b3bc7a0ea | 53 | sendingLoopRegions=false; // from this we can detect "hits" |
mbedalvaro | 0:345b3bc7a0ea | 54 | sendingLoopTouchWall=false; |
mbedalvaro | 0:345b3bc7a0ea | 55 | // (c) Blob geometry: |
mbedalvaro | 0:345b3bc7a0ea | 56 | sendingBlobArea=false; |
mbedalvaro | 0:345b3bc7a0ea | 57 | sendingBlobNormals=false; |
mbedalvaro | 0:345b3bc7a0ea | 58 | sendingBlobAngles=false; // redundant with sendingBlobNormals, but simplified (only angle of normal) |
mbedalvaro | 19:228430f1350e | 59 | sendingKineticEnergy=false; |
mbedalvaro | 0:345b3bc7a0ea | 60 | // (d) Light sensing statistics: |
mbedalvaro | 0:345b3bc7a0ea | 61 | sendingBlobMaxMin=false; |
mbedalvaro | 0:345b3bc7a0ea | 62 | sendingLightForce=false; // the total light force |
mbedalvaro | 0:345b3bc7a0ea | 63 | sendingTouched=false; |
mbedalvaro | 0:345b3bc7a0ea | 64 | // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known). |
mbedalvaro | 0:345b3bc7a0ea | 65 | sendingRecenteringVector=false; |
mbedalvaro | 0:345b3bc7a0ea | 66 | sendingRecenteringAngle=false; |
mbedalvaro | 0:345b3bc7a0ea | 67 | sendingRecenteringNorm=false; |
mbedalvaro | 0:345b3bc7a0ea | 68 | } |
mbedalvaro | 0:345b3bc7a0ea | 69 | |
mbedalvaro | 0:345b3bc7a0ea | 70 | void soundSpot::stopAllSending() { |
mbedalvaro | 0:345b3bc7a0ea | 71 | // STOP HARDWARE SENDING MODE (per spot): |
mbedalvaro | 0:345b3bc7a0ea | 72 | sendSerial=false; |
mbedalvaro | 0:345b3bc7a0ea | 73 | sendOSC=true; |
mbedalvaro | 0:345b3bc7a0ea | 74 | } |
mbedalvaro | 0:345b3bc7a0ea | 75 | |
mbedalvaro | 0:345b3bc7a0ea | 76 | void soundSpot::sendData(void) { // send data common to all kind of blobs |
mbedalvaro | 18:d72935b13858 | 77 | // send common things, such as testing if it is the right time to send data: |
mbedalvaro | 18:d72935b13858 | 78 | |
mbedalvaro | 18:d72935b13858 | 79 | if (measureSendPeriod.read_ms()>periodSendingData) { |
mbedalvaro | 18:d72935b13858 | 80 | measureSendPeriod.stop(); |
mbedalvaro | 18:d72935b13858 | 81 | measureSendPeriod.reset(); |
mbedalvaro | 18:d72935b13858 | 82 | |
mbedalvaro | 18:d72935b13858 | 83 | // Send data specific to the derived class: |
mbedalvaro | 18:d72935b13858 | 84 | if ((sendingOnlyWhenTouch==false)||(blobWallCollision==true)||(displaySensingBuffer.lightTouched==true)) |
mbedalvaro | 18:d72935b13858 | 85 | sendDataSpecific(); // this will depend on the kind of blob |
mbedalvaro | 18:d72935b13858 | 86 | |
mbedalvaro | 18:d72935b13858 | 87 | measureSendPeriod.start(); |
mbedalvaro | 18:d72935b13858 | 88 | } |
mbedalvaro | 18:d72935b13858 | 89 | |
mbedalvaro | 0:345b3bc7a0ea | 90 | } |
mbedalvaro | 0:345b3bc7a0ea | 91 |