just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Tue Dec 02 04:28:42 2014 +0000
Revision:
48:7633d8e7b0d3
Parent:
47:2312a8dc9658
this is the working version of the skin games sowtware (aka, scorelight but with pre-determined "games")

Who changed what in which revision?

UserRevisionLine numberNew 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 44:46e25fa1669b 71
mbedalvaro 44:46e25fa1669b 72 void addAngleCorrection(float _moreAngleCorrection);
mbedalvaro 44:46e25fa1669b 73 void setAngleCorrection(float _angleCorrection);
mbedalvaro 31:5f039cbddee8 74
mbedalvaro 31:5f039cbddee8 75 virtual void explosion()=0; // not very nice programming style, it should be a MODE instead or something like that.
mbedalvaro 31:5f039cbddee8 76 virtual vector2Df getCenter()=0;
mbedalvaro 31:5f039cbddee8 77 virtual void resetPositionSpeed()=0;
mbedalvaro 31:5f039cbddee8 78 virtual void setPositionSpeed(vector2Df _pos, vector2Df _spe)=0;
mbedalvaro 46:90516893793a 79
mbedalvaro 47:2312a8dc9658 80 virtual void showChildParameters()=0;
mbedalvaro 47:2312a8dc9658 81 void printParameters(); // first show common parameters, then call the virtual method:
mbedalvaro 31:5f039cbddee8 82
mbedalvaro 31:5f039cbddee8 83 // DATA --------------------------------------------------------------------------------------------------------------
mbedalvaro 31:5f039cbddee8 84 int identifier; //0, 1, 2...
mbedalvaro 31:5f039cbddee8 85 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 86 unsigned char blobColor, transientBlobColor; // transient blob color is the color of the blob when touching something for instance.
mbedalvaro 45:a3b984a79d5d 87 bool blueTouch; // this is equivalent to "debugDelayMirrors" #define, but per-blob (ie. blue active in dark zones). Good for elastic loops...
mbedalvaro 45:a3b984a79d5d 88
mbedalvaro 31:5f039cbddee8 89 // initial position and speed of the blob:
mbedalvaro 31:5f039cbddee8 90 vector2Df startCenter;
mbedalvaro 31:5f039cbddee8 91 vector2Df startSpeed;
mbedalvaro 31:5f039cbddee8 92
mbedalvaro 31:5f039cbddee8 93 // Special fields:
mbedalvaro 31:5f039cbddee8 94 vector2Df gravity;
mbedalvaro 31:5f039cbddee8 95
mbedalvaro 31:5f039cbddee8 96 // SCAFOLD (rigid structure of points, with a center and methods to create it):
mbedalvaro 31:5f039cbddee8 97 RigidScafold bluePrint;
mbedalvaro 31:5f039cbddee8 98
mbedalvaro 31:5f039cbddee8 99 // LASER DISPLAY/SENSING-TRAJECTORY with DATA BUFFER for each blob:
mbedalvaro 31:5f039cbddee8 100 LaserSensingTrajectory displaySensingBuffer;
mbedalvaro 31:5f039cbddee8 101
mbedalvaro 31:5f039cbddee8 102 // 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 103 vector2Df totalLightForce;
mbedalvaro 31:5f039cbddee8 104 vector2Df recenteringVectorLoop;
mbedalvaro 31:5f039cbddee8 105 float angleCorrectionForceLoop;
mbedalvaro 31:5f039cbddee8 106 float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop)
mbedalvaro 31:5f039cbddee8 107 float normRecenteringVector;
mbedalvaro 31:5f039cbddee8 108
mbedalvaro 31:5f039cbddee8 109 // Geometry/kinematics of the loop:
mbedalvaro 31:5f039cbddee8 110 float cx, cy, w, h;
mbedalvaro 31:5f039cbddee8 111 float area, approxArea;
mbedalvaro 31:5f039cbddee8 112 float totalKineticEnergy;
mbedalvaro 31:5f039cbddee8 113
mbedalvaro 31:5f039cbddee8 114 bool render; // when false, the blob is NOT RENDERED
mbedalvaro 31:5f039cbddee8 115 bool standByMode; // when true, the blob is NOT UPDATED
mbedalvaro 31:5f039cbddee8 116
mbedalvaro 31:5f039cbddee8 117 // something touched the blob:
mbedalvaro 31:5f039cbddee8 118 bool searchActive;
mbedalvaro 31:5f039cbddee8 119 bool firstTimeNoTouch;
mbedalvaro 31:5f039cbddee8 120 //bool lightTouched; // belongs to the lsdTrajectory
mbedalvaro 31:5f039cbddee8 121 int noTouchedCounter;
mbedalvaro 31:5f039cbddee8 122 vector2Df randomForce;
mbedalvaro 31:5f039cbddee8 123
mbedalvaro 31:5f039cbddee8 124 // the blob touched the wall limits (these variables are updated in the "update" method, and implemented differently for each blob)
mbedalvaro 31:5f039cbddee8 125 bool blobWallCollision;
mbedalvaro 31:5f039cbddee8 126 int wallCounter;
mbedalvaro 31:5f039cbddee8 127
mbedalvaro 31:5f039cbddee8 128 // HARDWARE SENDING MODE (can be changed by serial or osc commands):
mbedalvaro 31:5f039cbddee8 129 unsigned short periodSendingData; // max data rate for sending data (in ms)
mbedalvaro 31:5f039cbddee8 130 bool sendSerial;
mbedalvaro 31:5f039cbddee8 131 bool sendOSC;
mbedalvaro 31:5f039cbddee8 132 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 133 // will be limited to periodSendingData.
mbedalvaro 31:5f039cbddee8 134 // SENDING modes for things COMMON TO ALL THE KIND OF BLOBS:
mbedalvaro 31:5f039cbddee8 135 // (d) Light sensing statistics:
mbedalvaro 31:5f039cbddee8 136 bool sendingBlobMaxMin; // max and min intensities are calculated directly from the lsdTrajectory
mbedalvaro 31:5f039cbddee8 137 bool sendingTouched; // when someone touches the blob (can be calculated directly from the lsdTrajectory)
mbedalvaro 31:5f039cbddee8 138 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 139 // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known).
mbedalvaro 31:5f039cbddee8 140 bool sendingRecenteringVector;
mbedalvaro 31:5f039cbddee8 141 bool sendingRecenteringAngle;
mbedalvaro 31:5f039cbddee8 142 bool sendingRecenteringNorm;
mbedalvaro 31:5f039cbddee8 143
mbedalvaro 31:5f039cbddee8 144 // SPECIFIC TO EACH BLOB (move this from here, use virtual methods to set their values):
mbedalvaro 31:5f039cbddee8 145 // (a) anchor mass data:
mbedalvaro 31:5f039cbddee8 146 bool sendingAnchorPosition;
mbedalvaro 31:5f039cbddee8 147 bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force
mbedalvaro 31:5f039cbddee8 148 bool sendingAnchorTouchWall;
mbedalvaro 31:5f039cbddee8 149 // (b) data from blob points:
mbedalvaro 31:5f039cbddee8 150 bool sendingLoopPositions;
mbedalvaro 31:5f039cbddee8 151 bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle
mbedalvaro 31:5f039cbddee8 152 bool sendingLoopForcesLight;
mbedalvaro 31:5f039cbddee8 153 bool sendingLoopRegions; // from this we can detect "hits"
mbedalvaro 31:5f039cbddee8 154 bool sendingLoopTouchWall;
mbedalvaro 31:5f039cbddee8 155 // (c) Blob geometry/kinematics:
mbedalvaro 31:5f039cbddee8 156 bool sendingBlobArea;
mbedalvaro 31:5f039cbddee8 157 bool sendingKineticEnergy;
mbedalvaro 31:5f039cbddee8 158 bool sendingBlobNormals;
mbedalvaro 31:5f039cbddee8 159 bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal)
mbedalvaro 31:5f039cbddee8 160 };
mbedalvaro 31:5f039cbddee8 161
mbedalvaro 0:345b3bc7a0ea 162 #endif