Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
elasticLoop.h@19:228430f1350e, 2012-04-28 (annotated)
- Committer:
- mbedalvaro
- Date:
- Sat Apr 28 13:42:14 2012 +0000
- Revision:
- 19:228430f1350e
- Parent:
- 12:0de9cd2bced5
- Child:
- 24:4e52031a495b
relatively stable. Now need to make commands to control speed/stiffness/color and size of spot form the computer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:345b3bc7a0ea | 1 | /* |
mbedalvaro | 0:345b3bc7a0ea | 2 | * elasticLoop.h |
mbedalvaro | 0:345b3bc7a0ea | 3 | * laserBlobPure |
mbedalvaro | 0:345b3bc7a0ea | 4 | * |
mbedalvaro | 0:345b3bc7a0ea | 5 | * Created by CASSINELLI ALVARO on 5/20/11. |
mbedalvaro | 0:345b3bc7a0ea | 6 | * Copyright 2011 TOKYO UNIVERSITY. All rights reserved. |
mbedalvaro | 0:345b3bc7a0ea | 7 | * |
mbedalvaro | 0:345b3bc7a0ea | 8 | */ |
mbedalvaro | 0:345b3bc7a0ea | 9 | |
mbedalvaro | 0:345b3bc7a0ea | 10 | #ifndef ELASTIC_LOOP |
mbedalvaro | 0:345b3bc7a0ea | 11 | #define ELASTIC_LOOP |
mbedalvaro | 0:345b3bc7a0ea | 12 | |
mbedalvaro | 0:345b3bc7a0ea | 13 | // Include the basic objects to create the loop |
mbedalvaro | 0:345b3bc7a0ea | 14 | #include "soundSpot.h" |
mbedalvaro | 0:345b3bc7a0ea | 15 | #include "classPointMass.h" |
mbedalvaro | 0:345b3bc7a0ea | 16 | #include "classSpring.h" |
mbedalvaro | 0:345b3bc7a0ea | 17 | |
mbedalvaro | 0:345b3bc7a0ea | 18 | #include <vector> |
mbedalvaro | 0:345b3bc7a0ea | 19 | using namespace std; |
mbedalvaro | 0:345b3bc7a0ea | 20 | |
mbedalvaro | 0:345b3bc7a0ea | 21 | //#define MAX_NUM_MASSES 50 |
mbedalvaro | 0:345b3bc7a0ea | 22 | //#define PI 3.1415926 |
mbedalvaro | 0:345b3bc7a0ea | 23 | |
mbedalvaro | 19:228430f1350e | 24 | enum ElasticLoopMode {RELAX, CONTRACT, CONTRACT_CENTRAL, CONTRACT_CENTRAL_FAST, CONTOUR_FOLLOWING, CONTOUR_FOLLOWING_FAST, BOUNCING}; |
mbedalvaro | 0:345b3bc7a0ea | 25 | |
mbedalvaro | 0:345b3bc7a0ea | 26 | class elasticLoop : public soundSpot { |
mbedalvaro | 0:345b3bc7a0ea | 27 | |
mbedalvaro | 0:345b3bc7a0ea | 28 | public: |
mbedalvaro | 0:345b3bc7a0ea | 29 | |
mbedalvaro | 0:345b3bc7a0ea | 30 | // Constructor and destructor: |
mbedalvaro | 0:345b3bc7a0ea | 31 | elasticLoop(); |
mbedalvaro | 0:345b3bc7a0ea | 32 | ~elasticLoop(); |
mbedalvaro | 0:345b3bc7a0ea | 33 | |
mbedalvaro | 0:345b3bc7a0ea | 34 | // instantiation of the virtual methods of the base class (we don't need to append "virtual", but for clarity I do): |
mbedalvaro | 12:0de9cd2bced5 | 35 | void createBlob(int _id, ElasticLoopMode _elasticBlobMode, vector2Df _initPos, vector2Df _initSpeed); |
mbedalvaro | 12:0de9cd2bced5 | 36 | virtual void setRegionMotion(float mmix, float mmiy, float mmax, float mmay); // attention: initial position posX and posY should be inside this bounding box... |
mbedalvaro | 0:345b3bc7a0ea | 37 | virtual void update(); // update dynamics of the mass loop |
mbedalvaro | 0:345b3bc7a0ea | 38 | 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). |
mbedalvaro | 0:345b3bc7a0ea | 39 | virtual void computeBoundingBox(); |
mbedalvaro | 0:345b3bc7a0ea | 40 | virtual void sendDataSpecific(void); |
mbedalvaro | 0:345b3bc7a0ea | 41 | |
mbedalvaro | 0:345b3bc7a0ea | 42 | // methods that are new to this class (not in base class): |
mbedalvaro | 0:345b3bc7a0ea | 43 | void initSizeBlob(int _numMasses); |
mbedalvaro | 0:345b3bc7a0ea | 44 | void createLoopFromScafold(void); |
mbedalvaro | 0:345b3bc7a0ea | 45 | void processLoopData(); // process elastic loop data |
mbedalvaro | 0:345b3bc7a0ea | 46 | |
mbedalvaro | 1:a4050fee11f7 | 47 | // ====================== VARIABLES ====================== |
mbedalvaro | 1:a4050fee11f7 | 48 | |
mbedalvaro | 1:a4050fee11f7 | 49 | //ElasticLoopMode loopMode; |
mbedalvaro | 1:a4050fee11f7 | 50 | |
mbedalvaro | 0:345b3bc7a0ea | 51 | // The loop of masses with springs: |
mbedalvaro | 1:a4050fee11f7 | 52 | int numMasses; // Number of particles in the elastic loop (this may or may not be equal to the number of points in the lsdTrajectory) |
mbedalvaro | 0:345b3bc7a0ea | 53 | vector<pointMass> massesLoop; |
mbedalvaro | 0:345b3bc7a0ea | 54 | vector<spring> loopSpringArray; |
mbedalvaro | 1:a4050fee11f7 | 55 | // NOTE: to save memory, we can drop hairVector (use lightForce instead, and then normalize it when required) |
mbedalvaro | 12:0de9cd2bced5 | 56 | vector<vector2Df> hairVector; // the perpendiculars to the loop |
mbedalvaro | 12:0de9cd2bced5 | 57 | vector<vector2Df> lightForce; |
mbedalvaro | 0:345b3bc7a0ea | 58 | //vector2D totalLightForce; // this belongs to the base class now |
mbedalvaro | 0:345b3bc7a0ea | 59 | |
mbedalvaro | 0:345b3bc7a0ea | 60 | // For the central anchor point: |
mbedalvaro | 0:345b3bc7a0ea | 61 | pointMass anchorMass; |
mbedalvaro | 0:345b3bc7a0ea | 62 | vector<spring> centralSpringArray; |
mbedalvaro | 0:345b3bc7a0ea | 63 | |
mbedalvaro | 0:345b3bc7a0ea | 64 | // Detail modes (could be in a struct) |
mbedalvaro | 0:345b3bc7a0ea | 65 | // Behaviour mode: |
mbedalvaro | 0:345b3bc7a0ea | 66 | bool pseudopodesMode; |
mbedalvaro | 0:345b3bc7a0ea | 67 | bool slidingDirection; // for contour following |
mbedalvaro | 0:345b3bc7a0ea | 68 | bool springForcesOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 69 | bool lightForcesOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 70 | bool forceBorderOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 71 | bool recenteringForceOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 72 | bool nuclearForceOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 73 | bool interParticleForceOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 74 | bool forceInternalPressureOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 75 | bool recenteringForceOnNucleus; |
mbedalvaro | 0:345b3bc7a0ea | 76 | |
mbedalvaro | 0:345b3bc7a0ea | 77 | // Recentering vector (obtained by rotating the total light force by an arbitrary angle) for the anchor mass, and for each point in the loop |
mbedalvaro | 0:345b3bc7a0ea | 78 | // ex: if it is 180deg, then the blob just "bounces" on the zone transition; if it is 90, it does contour following... |
mbedalvaro | 1:a4050fee11f7 | 79 | |
mbedalvaro | 1:a4050fee11f7 | 80 | // The following are common to all blobs: |
mbedalvaro | 1:a4050fee11f7 | 81 | // float angleCorrectionForceLoop; |
mbedalvaro | 1:a4050fee11f7 | 82 | // vector2D recenteringVectorLoop; |
mbedalvaro | 0:345b3bc7a0ea | 83 | // float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop) |
mbedalvaro | 0:345b3bc7a0ea | 84 | // float normRecenteringVector; |
mbedalvaro | 1:a4050fee11f7 | 85 | |
mbedalvaro | 1:a4050fee11f7 | 86 | float angleCorrectionForceNucleus; |
mbedalvaro | 12:0de9cd2bced5 | 87 | vector2Df recenteringVectorNucleus; |
mbedalvaro | 0:345b3bc7a0ea | 88 | |
mbedalvaro | 0:345b3bc7a0ea | 89 | // Numeric parameters: |
mbedalvaro | 0:345b3bc7a0ea | 90 | float massLoopParticle; |
mbedalvaro | 0:345b3bc7a0ea | 91 | float dampMotionMassesLoop; |
mbedalvaro | 0:345b3bc7a0ea | 92 | float massAnchor; |
mbedalvaro | 0:345b3bc7a0ea | 93 | float dampMotionAnchorMass; |
mbedalvaro | 4:f9d364f10335 | 94 | |
mbedalvaro | 4:f9d364f10335 | 95 | // initial size, position and center-mass speed of the elastic loop: |
mbedalvaro | 4:f9d364f10335 | 96 | float startRadius; |
mbedalvaro | 4:f9d364f10335 | 97 | //vector2D startCenter; // this belongs to the base class |
mbedalvaro | 4:f9d364f10335 | 98 | // vector2D startSpeed; // this belongs to base class |
mbedalvaro | 4:f9d364f10335 | 99 | |
mbedalvaro | 0:345b3bc7a0ea | 100 | float interSpringK, interSpringRelax; |
mbedalvaro | 0:345b3bc7a0ea | 101 | float centralSpringK, centralSpringRelax; |
mbedalvaro | 0:345b3bc7a0ea | 102 | float factorLightForce; |
mbedalvaro | 0:345b3bc7a0ea | 103 | float factorRecenteringAnchorMass; |
mbedalvaro | 0:345b3bc7a0ea | 104 | float factorRecenteringLoopMass; |
mbedalvaro | 0:345b3bc7a0ea | 105 | float factorPressureLoopMass; |
mbedalvaro | 0:345b3bc7a0ea | 106 | float factorForceBorder; |
mbedalvaro | 1:a4050fee11f7 | 107 | float interParticleRange, factorInterParticleForce; // zach like blob force |
mbedalvaro | 0:345b3bc7a0ea | 108 | |
mbedalvaro | 0:345b3bc7a0ea | 109 | // SOUND SENDING MODES (specific to this kind of blob object): |
mbedalvaro | 0:345b3bc7a0ea | 110 | /* |
mbedalvaro | 0:345b3bc7a0ea | 111 | // (a) anchor mass data: |
mbedalvaro | 0:345b3bc7a0ea | 112 | bool sendingAnchorPosition; |
mbedalvaro | 0:345b3bc7a0ea | 113 | bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force |
mbedalvaro | 0:345b3bc7a0ea | 114 | bool sendingAnchorTouchWall; |
mbedalvaro | 0:345b3bc7a0ea | 115 | // (b) data from blob points: |
mbedalvaro | 0:345b3bc7a0ea | 116 | bool sendingLoopPositions; |
mbedalvaro | 0:345b3bc7a0ea | 117 | bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle |
mbedalvaro | 0:345b3bc7a0ea | 118 | bool sendingLoopForcesLight; |
mbedalvaro | 0:345b3bc7a0ea | 119 | bool sendingLoopRegions; // from this we can detect "hits" |
mbedalvaro | 0:345b3bc7a0ea | 120 | bool sendingLoopTouchWall; |
mbedalvaro | 0:345b3bc7a0ea | 121 | // (c) Blob geometry: |
mbedalvaro | 0:345b3bc7a0ea | 122 | bool sendingBlobArea; |
mbedalvaro | 0:345b3bc7a0ea | 123 | bool sendingBlobNormals; |
mbedalvaro | 0:345b3bc7a0ea | 124 | bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal) |
mbedalvaro | 0:345b3bc7a0ea | 125 | */ |
mbedalvaro | 0:345b3bc7a0ea | 126 | |
mbedalvaro | 0:345b3bc7a0ea | 127 | }; |
mbedalvaro | 0:345b3bc7a0ea | 128 | |
mbedalvaro | 0:345b3bc7a0ea | 129 | #endif |