Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of scoreLight_Advanced by
soundSpot.cpp@12:0de9cd2bced5, 2012-04-12 (annotated)
- Committer:
- mbedalvaro
- Date:
- Thu Apr 12 08:38:44 2012 +0000
- Revision:
- 12:0de9cd2bced5
- Parent:
- 4:f9d364f10335
- Child:
- 18:d72935b13858
1) template class vector works fine. This way, I have more memory (by defining a rigid scafold using unsigned shorts). I can now make an elastic blob of at least 50 points. ; ; To do: double buffering (this will again take memory, but it may be ok becaus...
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 | 0:345b3bc7a0ea | 11 | } |
mbedalvaro | 0:345b3bc7a0ea | 12 | |
mbedalvaro | 0:345b3bc7a0ea | 13 | // 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 | 14 | // 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 | 15 | soundSpot::~soundSpot() { |
mbedalvaro | 0:345b3bc7a0ea | 16 | } |
mbedalvaro | 0:345b3bc7a0ea | 17 | |
mbedalvaro | 12:0de9cd2bced5 | 18 | void soundSpot::setColor(unsigned char c) { |
mbedalvaro | 0:345b3bc7a0ea | 19 | blobColor=0x07&c; // we will use the first three bits to set the RGB colors. |
mbedalvaro | 0:345b3bc7a0ea | 20 | } |
mbedalvaro | 0:345b3bc7a0ea | 21 | |
mbedalvaro | 0:345b3bc7a0ea | 22 | void soundSpot::initCommonVariables() { |
mbedalvaro | 0:345b3bc7a0ea | 23 | firstTimeNoTouch=true; |
mbedalvaro | 0:345b3bc7a0ea | 24 | // randomForce.set(1,0);// first time there won't be any force, or random force |
mbedalvaro | 0:345b3bc7a0ea | 25 | // randomForce=randomForce.getRotatedDeg(1.0*(rand()%360)); |
mbedalvaro | 0:345b3bc7a0ea | 26 | // randomForce.normalize(); |
mbedalvaro | 0:345b3bc7a0ea | 27 | |
mbedalvaro | 0:345b3bc7a0ea | 28 | noTouchedCounter=0; |
mbedalvaro | 0:345b3bc7a0ea | 29 | wallCounter=0; |
mbedalvaro | 0:345b3bc7a0ea | 30 | blobWallCollision=false; |
mbedalvaro | 0:345b3bc7a0ea | 31 | //slidingDirection=true; // (will change when touching wall) |
mbedalvaro | 0:345b3bc7a0ea | 32 | |
mbedalvaro | 0:345b3bc7a0ea | 33 | render=true; |
mbedalvaro | 0:345b3bc7a0ea | 34 | standByMode=false; |
mbedalvaro | 0:345b3bc7a0ea | 35 | } |
mbedalvaro | 0:345b3bc7a0ea | 36 | |
mbedalvaro | 0:345b3bc7a0ea | 37 | void soundSpot::resetAllSendingModes() { |
mbedalvaro | 0:345b3bc7a0ea | 38 | // RESET SENDING DATA: |
mbedalvaro | 0:345b3bc7a0ea | 39 | // (a) anchor mass data: |
mbedalvaro | 0:345b3bc7a0ea | 40 | sendingAnchorPosition=false; |
mbedalvaro | 0:345b3bc7a0ea | 41 | sendingAnchorForce=false; // this is the total force on the anchor mass, not just the recentering force |
mbedalvaro | 0:345b3bc7a0ea | 42 | sendingAnchorTouchWall=false; |
mbedalvaro | 0:345b3bc7a0ea | 43 | // (b) data from blob points: |
mbedalvaro | 0:345b3bc7a0ea | 44 | sendingLoopPositions=true; |
mbedalvaro | 0:345b3bc7a0ea | 45 | sendingLoopForces=false;// this is not just the forces from light, but all the forces in each particle |
mbedalvaro | 0:345b3bc7a0ea | 46 | sendingLoopForcesLight=false;// forces only from light |
mbedalvaro | 0:345b3bc7a0ea | 47 | sendingLoopRegions=false; // from this we can detect "hits" |
mbedalvaro | 0:345b3bc7a0ea | 48 | sendingLoopTouchWall=false; |
mbedalvaro | 0:345b3bc7a0ea | 49 | // (c) Blob geometry: |
mbedalvaro | 0:345b3bc7a0ea | 50 | sendingBlobArea=false; |
mbedalvaro | 0:345b3bc7a0ea | 51 | sendingBlobNormals=false; |
mbedalvaro | 0:345b3bc7a0ea | 52 | sendingBlobAngles=false; // redundant with sendingBlobNormals, but simplified (only angle of normal) |
mbedalvaro | 0:345b3bc7a0ea | 53 | // (d) Light sensing statistics: |
mbedalvaro | 0:345b3bc7a0ea | 54 | sendingBlobMaxMin=false; |
mbedalvaro | 0:345b3bc7a0ea | 55 | sendingLightForce=false; // the total light force |
mbedalvaro | 0:345b3bc7a0ea | 56 | sendingTouched=false; |
mbedalvaro | 0:345b3bc7a0ea | 57 | // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known). |
mbedalvaro | 0:345b3bc7a0ea | 58 | sendingRecenteringVector=false; |
mbedalvaro | 0:345b3bc7a0ea | 59 | sendingRecenteringAngle=false; |
mbedalvaro | 0:345b3bc7a0ea | 60 | sendingRecenteringNorm=false; |
mbedalvaro | 0:345b3bc7a0ea | 61 | } |
mbedalvaro | 0:345b3bc7a0ea | 62 | |
mbedalvaro | 0:345b3bc7a0ea | 63 | void soundSpot::stopAllSending() { |
mbedalvaro | 0:345b3bc7a0ea | 64 | // STOP HARDWARE SENDING MODE (per spot): |
mbedalvaro | 0:345b3bc7a0ea | 65 | sendSerial=false; |
mbedalvaro | 0:345b3bc7a0ea | 66 | sendOSC=true; |
mbedalvaro | 0:345b3bc7a0ea | 67 | } |
mbedalvaro | 0:345b3bc7a0ea | 68 | |
mbedalvaro | 0:345b3bc7a0ea | 69 | void soundSpot::sendData(void) { // send data common to all kind of blobs |
mbedalvaro | 0:345b3bc7a0ea | 70 | // send common things: |
mbedalvaro | 0:345b3bc7a0ea | 71 | // .. TO DO |
mbedalvaro | 0:345b3bc7a0ea | 72 | |
mbedalvaro | 0:345b3bc7a0ea | 73 | // Send data specific to the derived class: |
mbedalvaro | 0:345b3bc7a0ea | 74 | sendDataSpecific(); // this will depend on the kind of blob |
mbedalvaro | 0:345b3bc7a0ea | 75 | } |
mbedalvaro | 0:345b3bc7a0ea | 76 |