Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
soundSpot.h@0:345b3bc7a0ea, 2012-03-28 (annotated)
- Committer:
- mbedalvaro
- Date:
- Wed Mar 28 14:40:01 2012 +0000
- Revision:
- 0:345b3bc7a0ea
- Child:
- 1:a4050fee11f7
This version (using rigid frame, base and child classes, etc) works, but the blob is strangely smaller. Need to check this.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:345b3bc7a0ea | 1 | #ifndef SOUNDSPOT_H |
mbedalvaro | 0:345b3bc7a0ea | 2 | #define SOUNDSPOT_H |
mbedalvaro | 0:345b3bc7a0ea | 3 | |
mbedalvaro | 0:345b3bc7a0ea | 4 | //#define SEND_AS_BLOB // for test (sending positions in a single OSC blob chunk) |
mbedalvaro | 0:345b3bc7a0ea | 5 | //#define SEND_AS_STRING |
mbedalvaro | 0:345b3bc7a0ea | 6 | #define SEND_AS_POINTS |
mbedalvaro | 0:345b3bc7a0ea | 7 | |
mbedalvaro | 0:345b3bc7a0ea | 8 | // The global object OSC for sending/receiving messages: |
mbedalvaro | 0:345b3bc7a0ea | 9 | #include "mbedOSC.h" |
mbedalvaro | 0:345b3bc7a0ea | 10 | extern OSCMessage recMes; |
mbedalvaro | 0:345b3bc7a0ea | 11 | extern OSCMessage sendMes; |
mbedalvaro | 0:345b3bc7a0ea | 12 | extern OSCClass osc; |
mbedalvaro | 0:345b3bc7a0ea | 13 | |
mbedalvaro | 0:345b3bc7a0ea | 14 | extern DigitalOut myled2; // for tests... |
mbedalvaro | 0:345b3bc7a0ea | 15 | |
mbedalvaro | 0:345b3bc7a0ea | 16 | |
mbedalvaro | 0:345b3bc7a0ea | 17 | #include "classLaserSensingTrajectory.h" |
mbedalvaro | 0:345b3bc7a0ea | 18 | #include "classRigidScafold.h" |
mbedalvaro | 0:345b3bc7a0ea | 19 | |
mbedalvaro | 0:345b3bc7a0ea | 20 | // This is a polymorphic class, and elasticLoop, livingSpot are derived classes that |
mbedalvaro | 0:345b3bc7a0ea | 21 | // instantiate particular methods (update, etc). |
mbedalvaro | 0:345b3bc7a0ea | 22 | class soundSpot { |
mbedalvaro | 0:345b3bc7a0ea | 23 | 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 | 0:345b3bc7a0ea | 24 | |
mbedalvaro | 0:345b3bc7a0ea | 25 | // number of points of this blob: |
mbedalvaro | 0:345b3bc7a0ea | 26 | int numPoints; // this in fact is equal to sensingTrajectory.size() for instance. |
mbedalvaro | 0:345b3bc7a0ea | 27 | |
mbedalvaro | 0:345b3bc7a0ea | 28 | public: |
mbedalvaro | 0:345b3bc7a0ea | 29 | |
mbedalvaro | 0:345b3bc7a0ea | 30 | // CONSTRUCTOR AND DESTRUCTOR -------------------------------------------------------------------------------------------------------------- |
mbedalvaro | 0:345b3bc7a0ea | 31 | soundSpot(); |
mbedalvaro | 0:345b3bc7a0ea | 32 | // Destructor (virtual, because one can only delete an object of a derived type |
mbedalvaro | 0:345b3bc7a0ea | 33 | // through a pointer to one of its base classes IF the base class has a virtual destructor) |
mbedalvaro | 0:345b3bc7a0ea | 34 | virtual ~soundSpot();// { cout<<"Destroying Base";} |
mbedalvaro | 0:345b3bc7a0ea | 35 | |
mbedalvaro | 0:345b3bc7a0ea | 36 | // METHODS ------------------------------------------------------------------------------------------------------------- |
mbedalvaro | 0:345b3bc7a0ea | 37 | // COMMON methods to all the kind of blobs: |
mbedalvaro | 0:345b3bc7a0ea | 38 | // (1) properties of the visible loop: |
mbedalvaro | 0:345b3bc7a0ea | 39 | void setColor(char c); |
mbedalvaro | 0:345b3bc7a0ea | 40 | // (2) Sending modes: |
mbedalvaro | 0:345b3bc7a0ea | 41 | void stopAllSending(void); |
mbedalvaro | 0:345b3bc7a0ea | 42 | void resetAllSendingModes(void); |
mbedalvaro | 0:345b3bc7a0ea | 43 | void initCommonVariables(); |
mbedalvaro | 0:345b3bc7a0ea | 44 | void sendData(void); // send data common to all kind of blobs |
mbedalvaro | 0:345b3bc7a0ea | 45 | |
mbedalvaro | 0:345b3bc7a0ea | 46 | // VIRTUAL METHODS (common to all blobs, but each type of blob will implement it differently): |
mbedalvaro | 0:345b3bc7a0ea | 47 | // Blob creation: |
mbedalvaro | 0:345b3bc7a0ea | 48 | virtual void setRegionMotion(int mmix, int mmiy, int mmax, int mmay)=0; |
mbedalvaro | 0:345b3bc7a0ea | 49 | virtual void createBlob(int _id, int _elasticBlobMode, vector2D _initPos)=0; // note: the number of masses in the blob will be given from the scafold. |
mbedalvaro | 0:345b3bc7a0ea | 50 | // Update: |
mbedalvaro | 0:345b3bc7a0ea | 51 | virtual void update(void)=0; |
mbedalvaro | 0:345b3bc7a0ea | 52 | 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 | 0:345b3bc7a0ea | 53 | // Draw (on lsdTrajectory): |
mbedalvaro | 0:345b3bc7a0ea | 54 | virtual void draw(void)=0; // NOTE: this method actually "renders" the trajectory using the laser renderer (not yet done) |
mbedalvaro | 0:345b3bc7a0ea | 55 | // Send data through OSC: |
mbedalvaro | 0:345b3bc7a0ea | 56 | virtual void sendDataSpecific(void)=0; // send data specific to each blob |
mbedalvaro | 0:345b3bc7a0ea | 57 | |
mbedalvaro | 0:345b3bc7a0ea | 58 | // DATA -------------------------------------------------------------------------------------------------------------- |
mbedalvaro | 0:345b3bc7a0ea | 59 | int identifier; //0, 1, 2... |
mbedalvaro | 0:345b3bc7a0ea | 60 | char spotName[20]; //spot, elastic,... |
mbedalvaro | 0:345b3bc7a0ea | 61 | char blobColor; |
mbedalvaro | 0:345b3bc7a0ea | 62 | |
mbedalvaro | 0:345b3bc7a0ea | 63 | // SCAFOLD (rigid structure of points, with a center and methods to create it): |
mbedalvaro | 0:345b3bc7a0ea | 64 | RigidScafold bluePrint; |
mbedalvaro | 0:345b3bc7a0ea | 65 | |
mbedalvaro | 0:345b3bc7a0ea | 66 | // LASER DISPLAY/SENSING-TRAJECTORY with DATA BUFFER: |
mbedalvaro | 0:345b3bc7a0ea | 67 | LaserSensingTrajectory displaySensingBuffer; |
mbedalvaro | 0:345b3bc7a0ea | 68 | |
mbedalvaro | 0:345b3bc7a0ea | 69 | // the following are common to all kind of blobs, but the way these quantities are calculated (in the update() method) differs greatly: |
mbedalvaro | 0:345b3bc7a0ea | 70 | vector2D totalLightForce; |
mbedalvaro | 0:345b3bc7a0ea | 71 | vector2D recenteringVectorLoop; |
mbedalvaro | 0:345b3bc7a0ea | 72 | float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop) |
mbedalvaro | 0:345b3bc7a0ea | 73 | float normRecenteringVector; |
mbedalvaro | 0:345b3bc7a0ea | 74 | |
mbedalvaro | 0:345b3bc7a0ea | 75 | // Statistics of the loop (area and enclosing box): |
mbedalvaro | 0:345b3bc7a0ea | 76 | float cx, cy, w, h; |
mbedalvaro | 0:345b3bc7a0ea | 77 | float area, approxArea; |
mbedalvaro | 0:345b3bc7a0ea | 78 | |
mbedalvaro | 0:345b3bc7a0ea | 79 | int delayMirrorSamples; // this is required because it will affect the way the blob behaves - it could be in the laser renderer, but by putting it here we can have more per-blob fine tunning |
mbedalvaro | 0:345b3bc7a0ea | 80 | void setDelayMirrors(int); // in general, the delay will depend on the number of points being DISPLAYED (in other terms, on the size of lsdTrajectory). |
mbedalvaro | 0:345b3bc7a0ea | 81 | |
mbedalvaro | 0:345b3bc7a0ea | 82 | bool render; // when false, the blob is NOT RENDERED |
mbedalvaro | 0:345b3bc7a0ea | 83 | bool standByMode; // when true, the blob is NOT UPDATED |
mbedalvaro | 0:345b3bc7a0ea | 84 | |
mbedalvaro | 0:345b3bc7a0ea | 85 | // something touched the blob: |
mbedalvaro | 0:345b3bc7a0ea | 86 | bool searchActive; |
mbedalvaro | 0:345b3bc7a0ea | 87 | bool firstTimeNoTouch; |
mbedalvaro | 0:345b3bc7a0ea | 88 | //bool lightTouched; // belongs to the lsdTrajectory |
mbedalvaro | 0:345b3bc7a0ea | 89 | int noTouchedCounter; |
mbedalvaro | 0:345b3bc7a0ea | 90 | vector2D randomForce; |
mbedalvaro | 0:345b3bc7a0ea | 91 | |
mbedalvaro | 0:345b3bc7a0ea | 92 | // the blob touched the wall limits (these variables are updated in the "update" method, and implemented differently for each blob) |
mbedalvaro | 0:345b3bc7a0ea | 93 | bool blobWallCollision; |
mbedalvaro | 0:345b3bc7a0ea | 94 | int wallCounter; |
mbedalvaro | 0:345b3bc7a0ea | 95 | |
mbedalvaro | 0:345b3bc7a0ea | 96 | // HARDWARE SENDING MODE (can be changed by serial or osc commands): |
mbedalvaro | 0:345b3bc7a0ea | 97 | bool sendSerial; |
mbedalvaro | 0:345b3bc7a0ea | 98 | bool sendOSC; |
mbedalvaro | 0:345b3bc7a0ea | 99 | // SENDING modes for things COMMON TO ALL THE KIND OF BLOBS: |
mbedalvaro | 0:345b3bc7a0ea | 100 | // (d) Light sensing statistics: |
mbedalvaro | 0:345b3bc7a0ea | 101 | bool sendingBlobMaxMin; // max and min intensities are calculated directly from the lsdTrajectory |
mbedalvaro | 0:345b3bc7a0ea | 102 | bool sendingTouched; // when someone touches the blob (can be calculated directly from the lsdTrajectory) |
mbedalvaro | 0:345b3bc7a0ea | 103 | bool sendingLightForce; // the total light force (note: this CANNOT be calculated on the lsdTrajectory, but on the update method, particular to each loop). |
mbedalvaro | 0:345b3bc7a0ea | 104 | // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known). |
mbedalvaro | 0:345b3bc7a0ea | 105 | bool sendingRecenteringVector; |
mbedalvaro | 0:345b3bc7a0ea | 106 | bool sendingRecenteringAngle; |
mbedalvaro | 0:345b3bc7a0ea | 107 | bool sendingRecenteringNorm; |
mbedalvaro | 0:345b3bc7a0ea | 108 | |
mbedalvaro | 0:345b3bc7a0ea | 109 | // SPECIFIC TO EACH BLOB (move this from here, use virtual methods to set their values): |
mbedalvaro | 0:345b3bc7a0ea | 110 | // (a) anchor mass data: |
mbedalvaro | 0:345b3bc7a0ea | 111 | bool sendingAnchorPosition; |
mbedalvaro | 0:345b3bc7a0ea | 112 | bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force |
mbedalvaro | 0:345b3bc7a0ea | 113 | bool sendingAnchorTouchWall; |
mbedalvaro | 0:345b3bc7a0ea | 114 | // (b) data from blob points: |
mbedalvaro | 0:345b3bc7a0ea | 115 | bool sendingLoopPositions; |
mbedalvaro | 0:345b3bc7a0ea | 116 | bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle |
mbedalvaro | 0:345b3bc7a0ea | 117 | bool sendingLoopForcesLight; |
mbedalvaro | 0:345b3bc7a0ea | 118 | bool sendingLoopRegions; // from this we can detect "hits" |
mbedalvaro | 0:345b3bc7a0ea | 119 | bool sendingLoopTouchWall; |
mbedalvaro | 0:345b3bc7a0ea | 120 | // (c) Blob geometry: |
mbedalvaro | 0:345b3bc7a0ea | 121 | bool sendingBlobArea; |
mbedalvaro | 0:345b3bc7a0ea | 122 | bool sendingBlobNormals; |
mbedalvaro | 0:345b3bc7a0ea | 123 | bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal) |
mbedalvaro | 0:345b3bc7a0ea | 124 | |
mbedalvaro | 0:345b3bc7a0ea | 125 | }; |
mbedalvaro | 0:345b3bc7a0ea | 126 | |
mbedalvaro | 0:345b3bc7a0ea | 127 | #endif |