Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
0:345b3bc7a0ea
Child:
1:a4050fee11f7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/elasticLoop.h	Wed Mar 28 14:40:01 2012 +0000
@@ -0,0 +1,128 @@
+/*
+ *  elasticLoop.h
+ *  laserBlobPure
+ *
+ *  Created by CASSINELLI ALVARO on 5/20/11.
+ *  Copyright 2011 TOKYO UNIVERSITY. All rights reserved.
+ *
+ */
+ 
+#ifndef ELASTIC_LOOP
+#define ELASTIC_LOOP
+
+// Include the basic objects to create the loop
+#include "soundSpot.h"
+#include "classPointMass.h"
+#include "classSpring.h"
+
+ #include <vector>
+ using namespace std;
+
+//#define MAX_NUM_MASSES  50
+//#define PI 3.1415926
+
+#define min(a, b) (((a) < (b)) ? (a) : (b))
+#define max(a, b) (((a) > (b)) ? (a) : (b))
+
+enum ElasticLoopMode {RELAX, CONTRACT, CONTRACT_CENTRAL, CONTOUR_FOLLOWING, CONTOUR_FOLLOWING_FAST, BOUNCING};
+
+class elasticLoop : public soundSpot  {
+    
+public:
+    
+    // Constructor and destructor:
+    elasticLoop();
+    ~elasticLoop();
+    
+    // instantiation of the virtual methods of the base class (we don't need to append "virtual", but for clarity I do):
+    virtual void createBlob(int _id, int _elasticBlobMode, vector2D _initPos);
+    virtual void setRegionMotion(int mmix, int mmiy, int mmax, int mmay); // attention: initial position posX and posY should be inside this bounding box...
+    virtual void update();  // update dynamics of the mass loop   
+    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).
+    virtual void computeBoundingBox();
+    virtual void sendDataSpecific(void);
+       
+    // methods that are new to this class (not in base class): 
+    void initSizeBlob(int _numMasses);
+    void createLoopFromScafold(void);
+    void processLoopData(); // process elastic loop data
+    
+    // The loop of masses with springs:
+    int numMasses;
+    vector<pointMass> massesLoop;
+    vector<spring> loopSpringArray;
+    vector<vector2D> hairVector; // the perpendiculars to the loop 
+    vector<vector2D> lightForce;
+    //vector2D totalLightForce; // this belongs to the base class now
+   
+    // For the central anchor point:
+    pointMass anchorMass;
+    vector<spring> centralSpringArray;
+ 
+   // ====================== VARIABLES ======================
+    // Number of particles in the elastic loop (this may or may not be equal to the number of points in the lsdTrajectory)
+   // int numMasses;
+    
+    // Meta-modes for the elastic loop:
+    ElasticLoopMode loopMode;
+    
+    // Detail modes (could be in a struct)
+    // Behaviour mode:
+    bool pseudopodesMode;
+    bool slidingDirection; // for contour following
+    bool springForcesOnLoop;
+    bool lightForcesOnLoop;
+    bool forceBorderOnLoop;
+    bool recenteringForceOnLoop;
+    bool nuclearForceOnLoop;
+    bool interParticleForceOnLoop;
+    bool forceInternalPressureOnLoop;
+    bool recenteringForceOnNucleus;
+        
+    // Recentering vector (obtained by rotating the total light force by an arbitrary angle) for the anchor mass, and for each point in the loop 
+    // ex: if it is 180deg, then the blob just "bounces" on the zone transition; if it is 90, it does contour following... 
+    float angleCorrectionForceLoop;
+    float angleCorrectionForceNucleus;
+    
+    vector2D recenteringVectorNucleus;
+    // the following are common to all blobs:
+   //  vector2D recenteringVectorLoop;
+   // float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop)
+   // float normRecenteringVector;
+     
+    // Numeric parameters: 
+    float massLoopParticle; 
+    float dampMotionMassesLoop;
+    float massAnchor;
+    float dampMotionAnchorMass;
+
+    float interSpringK, interSpringRelax;
+    float centralSpringK, centralSpringRelax;
+    float factorLightForce;
+    float factorRecenteringAnchorMass;
+    float factorRecenteringLoopMass;
+    float factorPressureLoopMass;
+    float factorForceBorder;
+    float  interParticleRange, factorInterParticleForce; // zach like blob force
+    
+  // SOUND SENDING MODES (specific to this kind of blob object): 
+  /*
+  // (a) anchor mass data: 
+  bool sendingAnchorPosition;
+  bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force
+  bool sendingAnchorTouchWall;
+  // (b) data from blob points:
+  bool sendingLoopPositions;
+  bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle
+  bool sendingLoopForcesLight;
+  bool sendingLoopRegions; // from this we can detect "hits"
+  bool sendingLoopTouchWall;
+  // (c) Blob geometry:
+  bool sendingBlobArea;
+  bool sendingBlobNormals;
+  bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal)
+    */
+    
+};
+
+#endif