Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers elasticLoop.h Source File

elasticLoop.h

00001 /*
00002  *  elasticLoop.h
00003  *  laserBlobPure
00004  *
00005  *  Created by CASSINELLI ALVARO on 5/20/11.
00006  *  Copyright 2011 TOKYO UNIVERSITY. All rights reserved.
00007  *
00008  */
00009  
00010 #ifndef ELASTIC_LOOP
00011 #define ELASTIC_LOOP
00012 
00013 // Include the basic objects to create the loop
00014 #include "soundSpot.h"
00015 #include "classPointMass.h"
00016 #include "classSpring.h"
00017 
00018  #include <vector>
00019  using namespace std;
00020 
00021 //#define MAX_NUM_MASSES  50
00022 //#define PI 3.1415926
00023 
00024 enum ElasticLoopMode {RELAX, CONTRACT, CONTRACT_CENTRAL, CONTRACT_CENTRAL_FAST, CONTOUR_FOLLOWING, CONTOUR_FOLLOWING_FAST, BOUNCING};
00025 
00026 class elasticLoop : public soundSpot  {
00027     
00028 public:
00029     
00030     // Constructor and destructor:
00031     elasticLoop();
00032     virtual ~elasticLoop();
00033     
00034     // instantiation of the virtual methods of the base class (we don't need to append "virtual", but for clarity I do):
00035     void createBlob(int _id, ElasticLoopMode _elasticBlobMode, vector2Df _initPos, vector2Df _initSpeed);
00036     virtual void setRegionMotion(float mmix, float mmiy, float mmax, float mmay); // attention: initial position posX and posY should be inside this bounding box...
00037     virtual void update(vector2Df referencePos);  // update dynamics of the mass loop   
00038     virtual void draw(void);  // draw the blob (renders on the laser trajectory object lsdTrajectory from the base class, using the openGL laser renderer - not yet done).
00039     virtual void computeBoundingBox();
00040     virtual void sendDataSpecific(void);
00041     // Some behaviour parameters:
00042     virtual void setSpeed(float speed) {};// do nothing in the case of elastic loop for the time being...
00043     virtual void setSize(float size) {}; // do nothing in the case of elastic loop for the time being...
00044     virtual void speedFactor(float speedfactor);
00045     virtual void sizeFactor(float sizeFactor) {}; // do nothing in the case of elastic loop for the time being...
00046        
00047     virtual void explosion() {}; // nothing for the time being 
00048     virtual vector2Df getCenter() {}; // nothing for the time being
00049     virtual void resetPositionSpeed() {};// nothing for the time being 
00050     virtual void setPositionSpeed(vector2Df _pos, vector2Df _spe) {};// nothing for the time being 
00051  
00052     virtual void showChildParameters();
00053  
00054     // methods that are new to this class (not in base class): 
00055     void initSizeBlob(int _numMasses);
00056     void createLoopFromScafold(void);
00057     void processLoopData(); // process elastic loop data
00058     
00059        // ====================== VARIABLES ======================
00060 
00061     //ElasticLoopMode loopMode;
00062 
00063     // The loop of masses with springs:
00064     int numMasses; // Number of particles in the elastic loop (this may or may not be equal to the number of points in the lsdTrajectory)
00065     float integrationStepLoop;
00066     vector<pointMass> massesLoop;
00067     vector<spring> loopSpringArray;
00068     // NOTE: to save memory, we can drop hairVector (use lightForce instead, and then normalize it when required)
00069     vector<vector2Df> hairVector; // the perpendiculars to the loop 
00070     vector<vector2Df> lightForce;
00071     //vector2D totalLightForce; // this belongs to the base class now
00072    
00073     // For the central anchor point:
00074     pointMass anchorMass;
00075     float  integrationStepAnchor;
00076     vector<spring> centralSpringArray;
00077     
00078     // Detail modes (could be in a struct)
00079     // Behaviour mode:
00080     bool pseudopodesMode;
00081     bool slidingDirection; // for contour following
00082     bool springForcesOnLoop;
00083     bool lightForcesOnLoop;
00084     bool forceBorderOnLoop;
00085     bool recenteringForceOnLoop;
00086     bool nuclearForceOnLoop;
00087     bool interParticleForceOnLoop;
00088     bool forceInternalPressureOnLoop;
00089     bool recenteringForceOnNucleus;
00090         
00091     // Recentering vector (obtained by rotating the total light force by an arbitrary angle) for the anchor mass, and for each point in the loop 
00092     // ex: if it is 180deg, then the blob just "bounces" on the zone transition; if it is 90, it does contour following... 
00093   
00094     // The following are common to all blobs:
00095    //  float angleCorrectionForceLoop;
00096    // vector2D recenteringVectorLoop;
00097    // float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop)
00098    // float normRecenteringVector;
00099    
00100     float angleCorrectionForceNucleus;
00101     vector2Df recenteringVectorNucleus;
00102      
00103     // Numeric parameters: 
00104     float massLoopParticle; 
00105     float dampMotionMassesLoop;
00106     float massAnchor;
00107     float dampMotionAnchorMass;
00108     
00109     // initial size, position and center-mass speed of the elastic loop:
00110     float startRadius;
00111     //vector2D startCenter; // this belongs to the base class
00112     // vector2D startSpeed; // this belongs to base class
00113     
00114     float interSpringK, interSpringRelax;
00115     float centralSpringK, centralSpringRelax;
00116     float factorLightForce;
00117     float factorRecenteringAnchorMass;
00118     float factorRecenteringLoopMass;
00119     float factorPressureLoopMass;
00120     float factorForceBorder;
00121     float interParticleRange, factorInterParticleForce; // zach like blob force
00122     
00123   // SOUND SENDING MODES (specific to this kind of blob object): 
00124   /*
00125   // (a) anchor mass data: 
00126   bool sendingAnchorPosition;
00127   bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force
00128   bool sendingAnchorTouchWall;
00129   // (b) data from blob points:
00130   bool sendingLoopPositions;
00131   bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle
00132   bool sendingLoopForcesLight;
00133   bool sendingLoopRegions; // from this we can detect "hits"
00134   bool sendingLoopTouchWall;
00135   // (c) Blob geometry:
00136   bool sendingBlobArea;
00137   bool sendingBlobNormals;
00138   bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal)
00139     */
00140     
00141 };
00142 
00143 #endif