Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
soundSpot.cpp@31:5f039cbddee8, 2012-09-23 (annotated)
- Committer:
- mbedalvaro
- Date:
- Sun Sep 23 10:11:43 2012 +0000
- Revision:
- 31:5f039cbddee8
- Parent:
- 30:d8af03f01cd4
- Child:
- 32:52273c3291fe
this is quite nice, but I am going to make a deep modification of the bouncing principle: instead of depending on the penetration, it will just be a factor over the speed (perfect elastic bouncing being factorElastic=1, and perfectly absorption=0);
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 31:5f039cbddee8 | 1 | #include "soundSpot.h" |
mbedalvaro | 31:5f039cbddee8 | 2 | |
mbedalvaro | 31:5f039cbddee8 | 3 | // Constructor: |
mbedalvaro | 31:5f039cbddee8 | 4 | soundSpot::soundSpot() { // by default, the child constructor call the parameterless default constructor (we could force another by doing: soundSpot::soundSpot : LivingSpot (params...) { ..} |
mbedalvaro | 31:5f039cbddee8 | 5 | |
mbedalvaro | 31:5f039cbddee8 | 6 | // DEFAULT sending mode will be all off: |
mbedalvaro | 31:5f039cbddee8 | 7 | stopAllSending(); |
mbedalvaro | 31:5f039cbddee8 | 8 | resetAllSendingModes(); |
mbedalvaro | 31:5f039cbddee8 | 9 | |
mbedalvaro | 31:5f039cbddee8 | 10 | initCommonVariables(); |
mbedalvaro | 31:5f039cbddee8 | 11 | |
mbedalvaro | 31:5f039cbddee8 | 12 | // initialize timer for sending OSC data: |
mbedalvaro | 31:5f039cbddee8 | 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 | 31:5f039cbddee8 | 14 | // instantiating the kind of blob. |
mbedalvaro | 31:5f039cbddee8 | 15 | measureSendPeriod.start(); |
mbedalvaro | 31:5f039cbddee8 | 16 | } |
mbedalvaro | 31:5f039cbddee8 | 17 | |
mbedalvaro | 31:5f039cbddee8 | 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 | 31:5f039cbddee8 | 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 | 31:5f039cbddee8 | 20 | soundSpot::~soundSpot() { |
mbedalvaro | 31:5f039cbddee8 | 21 | } |
mbedalvaro | 31:5f039cbddee8 | 22 | |
mbedalvaro | 31:5f039cbddee8 | 23 | void soundSpot::setColor(unsigned char c) { |
mbedalvaro | 31:5f039cbddee8 | 24 | blobColor=0x07&c; // we will use the first three bits to set the RGB colors. |
mbedalvaro | 31:5f039cbddee8 | 25 | // NOTE: it may be better to have always the red on? |
mbedalvaro | 31:5f039cbddee8 | 26 | } |
mbedalvaro | 31:5f039cbddee8 | 27 | |
mbedalvaro | 31:5f039cbddee8 | 28 | void soundSpot::initCommonVariables() { |
mbedalvaro | 31:5f039cbddee8 | 29 | firstTimeNoTouch=true; |
mbedalvaro | 31:5f039cbddee8 | 30 | // randomForce.set(1,0);// first time there won't be any force, or random force |
mbedalvaro | 31:5f039cbddee8 | 31 | // randomForce=randomForce.getRotatedDeg(1.0*(rand()%360)); |
mbedalvaro | 31:5f039cbddee8 | 32 | // randomForce.normalize(); |
mbedalvaro | 31:5f039cbddee8 | 33 | |
mbedalvaro | 31:5f039cbddee8 | 34 | noTouchedCounter=0; |
mbedalvaro | 31:5f039cbddee8 | 35 | wallCounter=0; |
mbedalvaro | 31:5f039cbddee8 | 36 | blobWallCollision=false; |
mbedalvaro | 31:5f039cbddee8 | 37 | //slidingDirection=true; // (will change when touching wall) |
mbedalvaro | 31:5f039cbddee8 | 38 | |
mbedalvaro | 31:5f039cbddee8 | 39 | gravity.set(0,0); |
mbedalvaro | 31:5f039cbddee8 | 40 | |
mbedalvaro | 31:5f039cbddee8 | 41 | render=true; |
mbedalvaro | 31:5f039cbddee8 | 42 | standByMode=true; // ALWAYS START IN STANDBY MODE |
mbedalvaro | 31:5f039cbddee8 | 43 | } |
mbedalvaro | 31:5f039cbddee8 | 44 | |
mbedalvaro | 31:5f039cbddee8 | 45 | void soundSpot::resetAllSendingModes() { |
mbedalvaro | 31:5f039cbddee8 | 46 | // RESET SENDING DATA: |
mbedalvaro | 31:5f039cbddee8 | 47 | sendingOnlyWhenTouch=false; |
mbedalvaro | 31:5f039cbddee8 | 48 | // (a) anchor mass data: |
mbedalvaro | 31:5f039cbddee8 | 49 | sendingAnchorPosition=false; |
mbedalvaro | 31:5f039cbddee8 | 50 | sendingAnchorForce=false; // this is the total force on the anchor mass, not just the recentering force |
mbedalvaro | 31:5f039cbddee8 | 51 | sendingAnchorTouchWall=false; |
mbedalvaro | 31:5f039cbddee8 | 52 | // (b) data from blob points: |
mbedalvaro | 31:5f039cbddee8 | 53 | sendingLoopPositions=false; |
mbedalvaro | 31:5f039cbddee8 | 54 | sendingLoopForces=false;// this is not just the forces from light, but all the forces in each particle |
mbedalvaro | 31:5f039cbddee8 | 55 | sendingLoopForcesLight=false;// forces only from light |
mbedalvaro | 31:5f039cbddee8 | 56 | sendingLoopRegions=false; // from this we can detect "hits" |
mbedalvaro | 31:5f039cbddee8 | 57 | sendingLoopTouchWall=false; |
mbedalvaro | 31:5f039cbddee8 | 58 | // (c) Blob geometry: |
mbedalvaro | 31:5f039cbddee8 | 59 | sendingBlobArea=false; |
mbedalvaro | 31:5f039cbddee8 | 60 | sendingBlobNormals=false; |
mbedalvaro | 31:5f039cbddee8 | 61 | sendingBlobAngles=false; // redundant with sendingBlobNormals, but simplified (only angle of normal) |
mbedalvaro | 31:5f039cbddee8 | 62 | sendingKineticEnergy=false; |
mbedalvaro | 31:5f039cbddee8 | 63 | // (d) Light sensing statistics: |
mbedalvaro | 31:5f039cbddee8 | 64 | sendingBlobMaxMin=false; |
mbedalvaro | 31:5f039cbddee8 | 65 | sendingLightForce=false; // the total light force |
mbedalvaro | 31:5f039cbddee8 | 66 | sendingTouched=false; |
mbedalvaro | 31:5f039cbddee8 | 67 | // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known). |
mbedalvaro | 31:5f039cbddee8 | 68 | sendingRecenteringVector=false; |
mbedalvaro | 31:5f039cbddee8 | 69 | sendingRecenteringAngle=false; |
mbedalvaro | 31:5f039cbddee8 | 70 | sendingRecenteringNorm=false; |
mbedalvaro | 31:5f039cbddee8 | 71 | } |
mbedalvaro | 31:5f039cbddee8 | 72 | |
mbedalvaro | 31:5f039cbddee8 | 73 | void soundSpot::stopAllSending() { |
mbedalvaro | 31:5f039cbddee8 | 74 | // STOP HARDWARE SENDING MODE (per spot): |
mbedalvaro | 31:5f039cbddee8 | 75 | sendSerial=false; |
mbedalvaro | 31:5f039cbddee8 | 76 | sendOSC=true; |
mbedalvaro | 31:5f039cbddee8 | 77 | } |
mbedalvaro | 31:5f039cbddee8 | 78 | |
mbedalvaro | 31:5f039cbddee8 | 79 | void soundSpot::sendData(void) { // send data common to all kind of blobs |
mbedalvaro | 31:5f039cbddee8 | 80 | // send common things, such as testing if it is the right time to send data: |
mbedalvaro | 31:5f039cbddee8 | 81 | |
mbedalvaro | 31:5f039cbddee8 | 82 | if (measureSendPeriod.read_ms()>periodSendingData) { |
mbedalvaro | 31:5f039cbddee8 | 83 | measureSendPeriod.stop(); |
mbedalvaro | 31:5f039cbddee8 | 84 | measureSendPeriod.reset(); |
mbedalvaro | 31:5f039cbddee8 | 85 | |
mbedalvaro | 31:5f039cbddee8 | 86 | // Send data specific to the derived class: |
mbedalvaro | 31:5f039cbddee8 | 87 | if ((sendingOnlyWhenTouch==false)||(blobWallCollision==true)||(displaySensingBuffer.lightTouched==true)) |
mbedalvaro | 31:5f039cbddee8 | 88 | sendDataSpecific(); // this will depend on the kind of blob |
mbedalvaro | 31:5f039cbddee8 | 89 | |
mbedalvaro | 31:5f039cbddee8 | 90 | measureSendPeriod.start(); |
mbedalvaro | 31:5f039cbddee8 | 91 | } |
mbedalvaro | 31:5f039cbddee8 | 92 | |
mbedalvaro | 31:5f039cbddee8 | 93 | } |
mbedalvaro | 31:5f039cbddee8 | 94 |