Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
soundSpot.h@33:43e8bc451ef0, 2012-11-05 (annotated)
- Committer:
- mbedalvaro
- Date:
- Mon Nov 05 06:08:35 2012 +0000
- Revision:
- 33:43e8bc451ef0
- Parent:
- 32:52273c3291fe
- Child:
- 44:46e25fa1669b
added resizing functions, as well as better control on the thresholding modes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 31:5f039cbddee8 | 1 | #ifndef SOUNDSPOT_H |
mbedalvaro | 31:5f039cbddee8 | 2 | #define SOUNDSPOT_H |
mbedalvaro | 31:5f039cbddee8 | 3 | |
mbedalvaro | 31:5f039cbddee8 | 4 | //#define SEND_AS_BLOB // for test (sending positions in a single OSC blob chunk) |
mbedalvaro | 31:5f039cbddee8 | 5 | //#define SEND_AS_STRING |
mbedalvaro | 31:5f039cbddee8 | 6 | #define SEND_AS_POINTS |
mbedalvaro | 31:5f039cbddee8 | 7 | |
mbedalvaro | 31:5f039cbddee8 | 8 | // The global object OSC for sending/receiving messages: |
mbedalvaro | 31:5f039cbddee8 | 9 | #include "mbedOSC.h" |
mbedalvaro | 31:5f039cbddee8 | 10 | extern OSCMessage recMes; |
mbedalvaro | 31:5f039cbddee8 | 11 | extern OSCMessage sendMes; |
mbedalvaro | 31:5f039cbddee8 | 12 | extern OSCClass osc; |
mbedalvaro | 31:5f039cbddee8 | 13 | |
mbedalvaro | 31:5f039cbddee8 | 14 | extern DigitalOut myled2; // for tests... |
mbedalvaro | 31:5f039cbddee8 | 15 | |
mbedalvaro | 31:5f039cbddee8 | 16 | #include "classLaserSensingTrajectory.h" |
mbedalvaro | 31:5f039cbddee8 | 17 | #include "classRigidScafold.h" |
mbedalvaro | 31:5f039cbddee8 | 18 | |
mbedalvaro | 31:5f039cbddee8 | 19 | |
mbedalvaro | 31:5f039cbddee8 | 20 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
mbedalvaro | 31:5f039cbddee8 | 21 | #define max(a, b) (((a) > (b)) ? (a) : (b)) |
mbedalvaro | 31:5f039cbddee8 | 22 | |
mbedalvaro | 31:5f039cbddee8 | 23 | // This is a polymorphic class, and elasticLoop, livingSpot are derived classes that |
mbedalvaro | 31:5f039cbddee8 | 24 | // instantiate particular methods (update, etc). |
mbedalvaro | 31:5f039cbddee8 | 25 | class soundSpot { |
mbedalvaro | 31:5f039cbddee8 | 26 | protected: // (note: protected means that the child classes will have access to these variables/methods; private means that only this class members have access) |
mbedalvaro | 31:5f039cbddee8 | 27 | |
mbedalvaro | 31:5f039cbddee8 | 28 | // number of points of this blob: |
mbedalvaro | 31:5f039cbddee8 | 29 | int numPoints; // this in fact is equal to sensingTrajectory.size() for instance. |
mbedalvaro | 31:5f039cbddee8 | 30 | Timer measureSendPeriod; |
mbedalvaro | 31:5f039cbddee8 | 31 | |
mbedalvaro | 31:5f039cbddee8 | 32 | public: |
mbedalvaro | 31:5f039cbddee8 | 33 | |
mbedalvaro | 31:5f039cbddee8 | 34 | // CONSTRUCTOR AND DESTRUCTOR -------------------------------------------------------------------------------------------------------------- |
mbedalvaro | 31:5f039cbddee8 | 35 | soundSpot(); |
mbedalvaro | 31:5f039cbddee8 | 36 | // Destructor (virtual, because one can only delete an object of a derived type |
mbedalvaro | 31:5f039cbddee8 | 37 | // through a pointer to one of its base classes IF the base class has a virtual destructor) |
mbedalvaro | 31:5f039cbddee8 | 38 | virtual ~soundSpot();// { cout<<"Destroying Base";} |
mbedalvaro | 31:5f039cbddee8 | 39 | |
mbedalvaro | 31:5f039cbddee8 | 40 | // METHODS ------------------------------------------------------------------------------------------------------------- |
mbedalvaro | 31:5f039cbddee8 | 41 | // COMMON methods to all the kind of blobs: |
mbedalvaro | 31:5f039cbddee8 | 42 | // (1) properties of the visible loop: |
mbedalvaro | 31:5f039cbddee8 | 43 | void setColor(unsigned char c); |
mbedalvaro | 32:52273c3291fe | 44 | void setGreenColor(unsigned char c); |
mbedalvaro | 32:52273c3291fe | 45 | void setBlueColor(unsigned char c); |
mbedalvaro | 32:52273c3291fe | 46 | |
mbedalvaro | 31:5f039cbddee8 | 47 | // (2) Sending modes: |
mbedalvaro | 31:5f039cbddee8 | 48 | void stopAllSending(void); |
mbedalvaro | 31:5f039cbddee8 | 49 | void resetAllSendingModes(void); |
mbedalvaro | 31:5f039cbddee8 | 50 | void initCommonVariables(); |
mbedalvaro | 31:5f039cbddee8 | 51 | void sendData(void); // send data common to all kind of blobs |
mbedalvaro | 31:5f039cbddee8 | 52 | |
mbedalvaro | 31:5f039cbddee8 | 53 | // VIRTUAL METHODS (common to all blobs, but each type of blob will implement it differently): |
mbedalvaro | 31:5f039cbddee8 | 54 | // Blob creation: |
mbedalvaro | 31:5f039cbddee8 | 55 | virtual void setRegionMotion(float mmix, float mmiy, float mmax, float mmay)=0; |
mbedalvaro | 31:5f039cbddee8 | 56 | // virtual void createBlob()=0; // note: the number of masses in the blob will be given from the scafold. |
mbedalvaro | 31:5f039cbddee8 | 57 | // virtual void createBlob(int _id, ElasticLoopMode _elasticBlobMode, vector2D _initPos)=0; |
mbedalvaro | 31:5f039cbddee8 | 58 | // Update: |
mbedalvaro | 31:5f039cbddee8 | 59 | virtual void update(vector2Df referencePos=vector2Df(0,0))=0; |
mbedalvaro | 31:5f039cbddee8 | 60 | virtual void computeBoundingBox(void)=0; // this is virtual because the displayed blob may be the scafold itself (in case of laser spot), or the elastic loop. |
mbedalvaro | 31:5f039cbddee8 | 61 | // Draw (on lsdTrajectory): |
mbedalvaro | 31:5f039cbddee8 | 62 | virtual void draw(void)=0; // NOTE: this method actually "renders" the trajectory using the laser renderer (not yet done) |
mbedalvaro | 31:5f039cbddee8 | 63 | // Send data through OSC: |
mbedalvaro | 31:5f039cbddee8 | 64 | virtual void sendDataSpecific(void)=0; // send data specific to each blob |
mbedalvaro | 33:43e8bc451ef0 | 65 | |
mbedalvaro | 31:5f039cbddee8 | 66 | // Some parameters (very different treatement for each type of blob): |
mbedalvaro | 33:43e8bc451ef0 | 67 | virtual void setSpeed(float speed=7.0)=0; |
mbedalvaro | 33:43e8bc451ef0 | 68 | virtual void setSize(float size=20.0)=0; |
mbedalvaro | 31:5f039cbddee8 | 69 | virtual void speedFactor(float speedfactor=100.0)=0; |
mbedalvaro | 32:52273c3291fe | 70 | virtual void sizeFactor(float sizeFactor=100.0)=0; |
mbedalvaro | 31:5f039cbddee8 | 71 | |
mbedalvaro | 31:5f039cbddee8 | 72 | virtual void explosion()=0; // not very nice programming style, it should be a MODE instead or something like that. |
mbedalvaro | 31:5f039cbddee8 | 73 | virtual vector2Df getCenter()=0; |
mbedalvaro | 31:5f039cbddee8 | 74 | virtual void resetPositionSpeed()=0; |
mbedalvaro | 31:5f039cbddee8 | 75 | virtual void setPositionSpeed(vector2Df _pos, vector2Df _spe)=0; |
mbedalvaro | 31:5f039cbddee8 | 76 | |
mbedalvaro | 31:5f039cbddee8 | 77 | // DATA -------------------------------------------------------------------------------------------------------------- |
mbedalvaro | 31:5f039cbddee8 | 78 | int identifier; //0, 1, 2... |
mbedalvaro | 31:5f039cbddee8 | 79 | char spotName[20]; //spot, elastic,... (this may be useful to set particular variables by forcing type cast (bad, but couldn't find a more elegant solution for the moment) |
mbedalvaro | 31:5f039cbddee8 | 80 | unsigned char blobColor, transientBlobColor; // transient blob color is the color of the blob when touching something for instance. |
mbedalvaro | 31:5f039cbddee8 | 81 | |
mbedalvaro | 31:5f039cbddee8 | 82 | // initial position and speed of the blob: |
mbedalvaro | 31:5f039cbddee8 | 83 | vector2Df startCenter; |
mbedalvaro | 31:5f039cbddee8 | 84 | vector2Df startSpeed; |
mbedalvaro | 31:5f039cbddee8 | 85 | |
mbedalvaro | 31:5f039cbddee8 | 86 | // Special fields: |
mbedalvaro | 31:5f039cbddee8 | 87 | vector2Df gravity; |
mbedalvaro | 31:5f039cbddee8 | 88 | |
mbedalvaro | 31:5f039cbddee8 | 89 | // SCAFOLD (rigid structure of points, with a center and methods to create it): |
mbedalvaro | 31:5f039cbddee8 | 90 | RigidScafold bluePrint; |
mbedalvaro | 31:5f039cbddee8 | 91 | |
mbedalvaro | 31:5f039cbddee8 | 92 | // LASER DISPLAY/SENSING-TRAJECTORY with DATA BUFFER for each blob: |
mbedalvaro | 31:5f039cbddee8 | 93 | LaserSensingTrajectory displaySensingBuffer; |
mbedalvaro | 31:5f039cbddee8 | 94 | |
mbedalvaro | 31:5f039cbddee8 | 95 | // the following are common to all kind of blobs, but the way these quantities are calculated (in the update() method) differs greatly: |
mbedalvaro | 31:5f039cbddee8 | 96 | vector2Df totalLightForce; |
mbedalvaro | 31:5f039cbddee8 | 97 | vector2Df recenteringVectorLoop; |
mbedalvaro | 31:5f039cbddee8 | 98 | float angleCorrectionForceLoop; |
mbedalvaro | 31:5f039cbddee8 | 99 | float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop) |
mbedalvaro | 31:5f039cbddee8 | 100 | float normRecenteringVector; |
mbedalvaro | 31:5f039cbddee8 | 101 | |
mbedalvaro | 31:5f039cbddee8 | 102 | // Geometry/kinematics of the loop: |
mbedalvaro | 31:5f039cbddee8 | 103 | float cx, cy, w, h; |
mbedalvaro | 31:5f039cbddee8 | 104 | float area, approxArea; |
mbedalvaro | 31:5f039cbddee8 | 105 | float totalKineticEnergy; |
mbedalvaro | 31:5f039cbddee8 | 106 | |
mbedalvaro | 31:5f039cbddee8 | 107 | bool render; // when false, the blob is NOT RENDERED |
mbedalvaro | 31:5f039cbddee8 | 108 | bool standByMode; // when true, the blob is NOT UPDATED |
mbedalvaro | 31:5f039cbddee8 | 109 | |
mbedalvaro | 31:5f039cbddee8 | 110 | // something touched the blob: |
mbedalvaro | 31:5f039cbddee8 | 111 | bool searchActive; |
mbedalvaro | 31:5f039cbddee8 | 112 | bool firstTimeNoTouch; |
mbedalvaro | 31:5f039cbddee8 | 113 | //bool lightTouched; // belongs to the lsdTrajectory |
mbedalvaro | 31:5f039cbddee8 | 114 | int noTouchedCounter; |
mbedalvaro | 31:5f039cbddee8 | 115 | vector2Df randomForce; |
mbedalvaro | 31:5f039cbddee8 | 116 | |
mbedalvaro | 31:5f039cbddee8 | 117 | // the blob touched the wall limits (these variables are updated in the "update" method, and implemented differently for each blob) |
mbedalvaro | 31:5f039cbddee8 | 118 | bool blobWallCollision; |
mbedalvaro | 31:5f039cbddee8 | 119 | int wallCounter; |
mbedalvaro | 31:5f039cbddee8 | 120 | |
mbedalvaro | 31:5f039cbddee8 | 121 | // HARDWARE SENDING MODE (can be changed by serial or osc commands): |
mbedalvaro | 31:5f039cbddee8 | 122 | unsigned short periodSendingData; // max data rate for sending data (in ms) |
mbedalvaro | 31:5f039cbddee8 | 123 | bool sendSerial; |
mbedalvaro | 31:5f039cbddee8 | 124 | bool sendOSC; |
mbedalvaro | 31:5f039cbddee8 | 125 | bool sendingOnlyWhenTouch; // when this is "true", data will be send ONLY when something touches the blob (border or light touch). Note that the max speed of sending |
mbedalvaro | 31:5f039cbddee8 | 126 | // will be limited to periodSendingData. |
mbedalvaro | 31:5f039cbddee8 | 127 | // SENDING modes for things COMMON TO ALL THE KIND OF BLOBS: |
mbedalvaro | 31:5f039cbddee8 | 128 | // (d) Light sensing statistics: |
mbedalvaro | 31:5f039cbddee8 | 129 | bool sendingBlobMaxMin; // max and min intensities are calculated directly from the lsdTrajectory |
mbedalvaro | 31:5f039cbddee8 | 130 | bool sendingTouched; // when someone touches the blob (can be calculated directly from the lsdTrajectory) |
mbedalvaro | 31:5f039cbddee8 | 131 | bool sendingLightForce; // the total light force (note: this CANNOT be calculated on the lsdTrajectory, but on the update method, particular to each loop). |
mbedalvaro | 31:5f039cbddee8 | 132 | // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known). |
mbedalvaro | 31:5f039cbddee8 | 133 | bool sendingRecenteringVector; |
mbedalvaro | 31:5f039cbddee8 | 134 | bool sendingRecenteringAngle; |
mbedalvaro | 31:5f039cbddee8 | 135 | bool sendingRecenteringNorm; |
mbedalvaro | 31:5f039cbddee8 | 136 | |
mbedalvaro | 31:5f039cbddee8 | 137 | // SPECIFIC TO EACH BLOB (move this from here, use virtual methods to set their values): |
mbedalvaro | 31:5f039cbddee8 | 138 | // (a) anchor mass data: |
mbedalvaro | 31:5f039cbddee8 | 139 | bool sendingAnchorPosition; |
mbedalvaro | 31:5f039cbddee8 | 140 | bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force |
mbedalvaro | 31:5f039cbddee8 | 141 | bool sendingAnchorTouchWall; |
mbedalvaro | 31:5f039cbddee8 | 142 | // (b) data from blob points: |
mbedalvaro | 31:5f039cbddee8 | 143 | bool sendingLoopPositions; |
mbedalvaro | 31:5f039cbddee8 | 144 | bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle |
mbedalvaro | 31:5f039cbddee8 | 145 | bool sendingLoopForcesLight; |
mbedalvaro | 31:5f039cbddee8 | 146 | bool sendingLoopRegions; // from this we can detect "hits" |
mbedalvaro | 31:5f039cbddee8 | 147 | bool sendingLoopTouchWall; |
mbedalvaro | 31:5f039cbddee8 | 148 | // (c) Blob geometry/kinematics: |
mbedalvaro | 31:5f039cbddee8 | 149 | bool sendingBlobArea; |
mbedalvaro | 31:5f039cbddee8 | 150 | bool sendingKineticEnergy; |
mbedalvaro | 31:5f039cbddee8 | 151 | bool sendingBlobNormals; |
mbedalvaro | 31:5f039cbddee8 | 152 | bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal) |
mbedalvaro | 31:5f039cbddee8 | 153 | }; |
mbedalvaro | 31:5f039cbddee8 | 154 | |
mbedalvaro | 0:345b3bc7a0ea | 155 | #endif |