Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Thu Apr 05 12:29:14 2012 +0000
Revision:
5:73cd58b58f95
Parent:
4:f9d364f10335
Child:
12:0de9cd2bced5
Something very strange happens in the class laserSensingTrajectory: adding a:;  float lightRatio; as member variable makes the blob dissapear...

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