Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Wed Apr 04 10:05:25 2012 +0000
Revision:
4:f9d364f10335
Parent:
1:a4050fee11f7
Child:
5:73cd58b58f95
- the new optimized laser output buffer has not been tested, but it compiles; - I am commiting here, because I am planning to change the structure of the classes: soundSpot will not contain an object of type classLaserSensingTrajectory, but be a CHILD o...

Who changed what in which revision?

UserRevisionLine numberNew 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 #include "classLaserSensingTrajectory.h"
mbedalvaro 0:345b3bc7a0ea 17 #include "classRigidScafold.h"
mbedalvaro 0:345b3bc7a0ea 18
mbedalvaro 1:a4050fee11f7 19
mbedalvaro 1:a4050fee11f7 20 #define min(a, b) (((a) < (b)) ? (a) : (b))
mbedalvaro 1:a4050fee11f7 21 #define max(a, b) (((a) > (b)) ? (a) : (b))
mbedalvaro 1:a4050fee11f7 22
mbedalvaro 0:345b3bc7a0ea 23 // This is a polymorphic class, and elasticLoop, livingSpot are derived classes that
mbedalvaro 0:345b3bc7a0ea 24 // instantiate particular methods (update, etc).
mbedalvaro 0:345b3bc7a0ea 25 class soundSpot {
mbedalvaro 0:345b3bc7a0ea 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 0:345b3bc7a0ea 27
mbedalvaro 0:345b3bc7a0ea 28 // number of points of this blob:
mbedalvaro 0:345b3bc7a0ea 29 int numPoints; // this in fact is equal to sensingTrajectory.size() for instance.
mbedalvaro 0:345b3bc7a0ea 30
mbedalvaro 0:345b3bc7a0ea 31 public:
mbedalvaro 0:345b3bc7a0ea 32
mbedalvaro 0:345b3bc7a0ea 33 // CONSTRUCTOR AND DESTRUCTOR --------------------------------------------------------------------------------------------------------------
mbedalvaro 0:345b3bc7a0ea 34 soundSpot();
mbedalvaro 0:345b3bc7a0ea 35 // Destructor (virtual, because one can only delete an object of a derived type
mbedalvaro 0:345b3bc7a0ea 36 // through a pointer to one of its base classes IF the base class has a virtual destructor)
mbedalvaro 0:345b3bc7a0ea 37 virtual ~soundSpot();// { cout<<"Destroying Base";}
mbedalvaro 0:345b3bc7a0ea 38
mbedalvaro 0:345b3bc7a0ea 39 // METHODS -------------------------------------------------------------------------------------------------------------
mbedalvaro 0:345b3bc7a0ea 40 // COMMON methods to all the kind of blobs:
mbedalvaro 0:345b3bc7a0ea 41 // (1) properties of the visible loop:
mbedalvaro 0:345b3bc7a0ea 42 void setColor(char c);
mbedalvaro 0:345b3bc7a0ea 43 // (2) Sending modes:
mbedalvaro 0:345b3bc7a0ea 44 void stopAllSending(void);
mbedalvaro 0:345b3bc7a0ea 45 void resetAllSendingModes(void);
mbedalvaro 0:345b3bc7a0ea 46 void initCommonVariables();
mbedalvaro 0:345b3bc7a0ea 47 void sendData(void); // send data common to all kind of blobs
mbedalvaro 0:345b3bc7a0ea 48
mbedalvaro 0:345b3bc7a0ea 49 // VIRTUAL METHODS (common to all blobs, but each type of blob will implement it differently):
mbedalvaro 0:345b3bc7a0ea 50 // Blob creation:
mbedalvaro 0:345b3bc7a0ea 51 virtual void setRegionMotion(int mmix, int mmiy, int mmax, int mmay)=0;
mbedalvaro 1:a4050fee11f7 52 // virtual void createBlob()=0; // note: the number of masses in the blob will be given from the scafold.
mbedalvaro 1:a4050fee11f7 53 // virtual void createBlob(int _id, ElasticLoopMode _elasticBlobMode, vector2D _initPos)=0;
mbedalvaro 0:345b3bc7a0ea 54 // Update:
mbedalvaro 0:345b3bc7a0ea 55 virtual void update(void)=0;
mbedalvaro 0:345b3bc7a0ea 56 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 57 // Draw (on lsdTrajectory):
mbedalvaro 0:345b3bc7a0ea 58 virtual void draw(void)=0; // NOTE: this method actually "renders" the trajectory using the laser renderer (not yet done)
mbedalvaro 0:345b3bc7a0ea 59 // Send data through OSC:
mbedalvaro 0:345b3bc7a0ea 60 virtual void sendDataSpecific(void)=0; // send data specific to each blob
mbedalvaro 0:345b3bc7a0ea 61
mbedalvaro 0:345b3bc7a0ea 62 // DATA --------------------------------------------------------------------------------------------------------------
mbedalvaro 0:345b3bc7a0ea 63 int identifier; //0, 1, 2...
mbedalvaro 0:345b3bc7a0ea 64 char spotName[20]; //spot, elastic,...
mbedalvaro 0:345b3bc7a0ea 65 char blobColor;
mbedalvaro 0:345b3bc7a0ea 66
mbedalvaro 4:f9d364f10335 67 // initial position and speed of the blob:
mbedalvaro 4:f9d364f10335 68 vector2D startCenter;
mbedalvaro 4:f9d364f10335 69 vector2D startSpeed;
mbedalvaro 4:f9d364f10335 70
mbedalvaro 0:345b3bc7a0ea 71 // SCAFOLD (rigid structure of points, with a center and methods to create it):
mbedalvaro 0:345b3bc7a0ea 72 RigidScafold bluePrint;
mbedalvaro 0:345b3bc7a0ea 73
mbedalvaro 0:345b3bc7a0ea 74 // LASER DISPLAY/SENSING-TRAJECTORY with DATA BUFFER:
mbedalvaro 0:345b3bc7a0ea 75 LaserSensingTrajectory displaySensingBuffer;
mbedalvaro 0:345b3bc7a0ea 76
mbedalvaro 0:345b3bc7a0ea 77 // 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 78 vector2D totalLightForce;
mbedalvaro 0:345b3bc7a0ea 79 vector2D recenteringVectorLoop;
mbedalvaro 1:a4050fee11f7 80 float angleCorrectionForceLoop;
mbedalvaro 0:345b3bc7a0ea 81 float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop)
mbedalvaro 0:345b3bc7a0ea 82 float normRecenteringVector;
mbedalvaro 0:345b3bc7a0ea 83
mbedalvaro 0:345b3bc7a0ea 84 // Statistics of the loop (area and enclosing box):
mbedalvaro 0:345b3bc7a0ea 85 float cx, cy, w, h;
mbedalvaro 0:345b3bc7a0ea 86 float area, approxArea;
mbedalvaro 0:345b3bc7a0ea 87
mbedalvaro 0:345b3bc7a0ea 88 bool render; // when false, the blob is NOT RENDERED
mbedalvaro 0:345b3bc7a0ea 89 bool standByMode; // when true, the blob is NOT UPDATED
mbedalvaro 0:345b3bc7a0ea 90
mbedalvaro 0:345b3bc7a0ea 91 // something touched the blob:
mbedalvaro 0:345b3bc7a0ea 92 bool searchActive;
mbedalvaro 0:345b3bc7a0ea 93 bool firstTimeNoTouch;
mbedalvaro 0:345b3bc7a0ea 94 //bool lightTouched; // belongs to the lsdTrajectory
mbedalvaro 0:345b3bc7a0ea 95 int noTouchedCounter;
mbedalvaro 0:345b3bc7a0ea 96 vector2D randomForce;
mbedalvaro 0:345b3bc7a0ea 97
mbedalvaro 0:345b3bc7a0ea 98 // the blob touched the wall limits (these variables are updated in the "update" method, and implemented differently for each blob)
mbedalvaro 0:345b3bc7a0ea 99 bool blobWallCollision;
mbedalvaro 0:345b3bc7a0ea 100 int wallCounter;
mbedalvaro 0:345b3bc7a0ea 101
mbedalvaro 0:345b3bc7a0ea 102 // HARDWARE SENDING MODE (can be changed by serial or osc commands):
mbedalvaro 0:345b3bc7a0ea 103 bool sendSerial;
mbedalvaro 0:345b3bc7a0ea 104 bool sendOSC;
mbedalvaro 0:345b3bc7a0ea 105 // SENDING modes for things COMMON TO ALL THE KIND OF BLOBS:
mbedalvaro 0:345b3bc7a0ea 106 // (d) Light sensing statistics:
mbedalvaro 0:345b3bc7a0ea 107 bool sendingBlobMaxMin; // max and min intensities are calculated directly from the lsdTrajectory
mbedalvaro 0:345b3bc7a0ea 108 bool sendingTouched; // when someone touches the blob (can be calculated directly from the lsdTrajectory)
mbedalvaro 0:345b3bc7a0ea 109 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 110 // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known).
mbedalvaro 0:345b3bc7a0ea 111 bool sendingRecenteringVector;
mbedalvaro 0:345b3bc7a0ea 112 bool sendingRecenteringAngle;
mbedalvaro 0:345b3bc7a0ea 113 bool sendingRecenteringNorm;
mbedalvaro 0:345b3bc7a0ea 114
mbedalvaro 0:345b3bc7a0ea 115 // SPECIFIC TO EACH BLOB (move this from here, use virtual methods to set their values):
mbedalvaro 0:345b3bc7a0ea 116 // (a) anchor mass data:
mbedalvaro 0:345b3bc7a0ea 117 bool sendingAnchorPosition;
mbedalvaro 0:345b3bc7a0ea 118 bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force
mbedalvaro 0:345b3bc7a0ea 119 bool sendingAnchorTouchWall;
mbedalvaro 0:345b3bc7a0ea 120 // (b) data from blob points:
mbedalvaro 0:345b3bc7a0ea 121 bool sendingLoopPositions;
mbedalvaro 0:345b3bc7a0ea 122 bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle
mbedalvaro 0:345b3bc7a0ea 123 bool sendingLoopForcesLight;
mbedalvaro 0:345b3bc7a0ea 124 bool sendingLoopRegions; // from this we can detect "hits"
mbedalvaro 0:345b3bc7a0ea 125 bool sendingLoopTouchWall;
mbedalvaro 0:345b3bc7a0ea 126 // (c) Blob geometry:
mbedalvaro 0:345b3bc7a0ea 127 bool sendingBlobArea;
mbedalvaro 0:345b3bc7a0ea 128 bool sendingBlobNormals;
mbedalvaro 0:345b3bc7a0ea 129 bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal)
mbedalvaro 0:345b3bc7a0ea 130
mbedalvaro 0:345b3bc7a0ea 131 };
mbedalvaro 0:345b3bc7a0ea 132
mbedalvaro 0:345b3bc7a0ea 133 #endif