Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
elasticLoop.h@0:345b3bc7a0ea, 2012-03-28 (annotated)
- Committer:
- mbedalvaro
- Date:
- Wed Mar 28 14:40:01 2012 +0000
- Revision:
- 0:345b3bc7a0ea
- Child:
- 1:a4050fee11f7
This version (using rigid frame, base and child classes, etc) works, but the blob is strangely smaller. Need to check this.
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 | 0:345b3bc7a0ea | 24 | #define min(a, b) (((a) < (b)) ? (a) : (b)) |
mbedalvaro | 0:345b3bc7a0ea | 25 | #define max(a, b) (((a) > (b)) ? (a) : (b)) |
mbedalvaro | 0:345b3bc7a0ea | 26 | |
mbedalvaro | 0:345b3bc7a0ea | 27 | enum ElasticLoopMode {RELAX, CONTRACT, CONTRACT_CENTRAL, CONTOUR_FOLLOWING, CONTOUR_FOLLOWING_FAST, BOUNCING}; |
mbedalvaro | 0:345b3bc7a0ea | 28 | |
mbedalvaro | 0:345b3bc7a0ea | 29 | class elasticLoop : public soundSpot { |
mbedalvaro | 0:345b3bc7a0ea | 30 | |
mbedalvaro | 0:345b3bc7a0ea | 31 | public: |
mbedalvaro | 0:345b3bc7a0ea | 32 | |
mbedalvaro | 0:345b3bc7a0ea | 33 | // Constructor and destructor: |
mbedalvaro | 0:345b3bc7a0ea | 34 | elasticLoop(); |
mbedalvaro | 0:345b3bc7a0ea | 35 | ~elasticLoop(); |
mbedalvaro | 0:345b3bc7a0ea | 36 | |
mbedalvaro | 0:345b3bc7a0ea | 37 | // instantiation of the virtual methods of the base class (we don't need to append "virtual", but for clarity I do): |
mbedalvaro | 0:345b3bc7a0ea | 38 | virtual void createBlob(int _id, int _elasticBlobMode, vector2D _initPos); |
mbedalvaro | 0:345b3bc7a0ea | 39 | virtual void setRegionMotion(int mmix, int mmiy, int mmax, int mmay); // attention: initial position posX and posY should be inside this bounding box... |
mbedalvaro | 0:345b3bc7a0ea | 40 | virtual void update(); // update dynamics of the mass loop |
mbedalvaro | 0:345b3bc7a0ea | 41 | 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 | 42 | virtual void computeBoundingBox(); |
mbedalvaro | 0:345b3bc7a0ea | 43 | virtual void sendDataSpecific(void); |
mbedalvaro | 0:345b3bc7a0ea | 44 | |
mbedalvaro | 0:345b3bc7a0ea | 45 | // methods that are new to this class (not in base class): |
mbedalvaro | 0:345b3bc7a0ea | 46 | void initSizeBlob(int _numMasses); |
mbedalvaro | 0:345b3bc7a0ea | 47 | void createLoopFromScafold(void); |
mbedalvaro | 0:345b3bc7a0ea | 48 | void processLoopData(); // process elastic loop data |
mbedalvaro | 0:345b3bc7a0ea | 49 | |
mbedalvaro | 0:345b3bc7a0ea | 50 | // The loop of masses with springs: |
mbedalvaro | 0:345b3bc7a0ea | 51 | int numMasses; |
mbedalvaro | 0:345b3bc7a0ea | 52 | vector<pointMass> massesLoop; |
mbedalvaro | 0:345b3bc7a0ea | 53 | vector<spring> loopSpringArray; |
mbedalvaro | 0:345b3bc7a0ea | 54 | vector<vector2D> hairVector; // the perpendiculars to the loop |
mbedalvaro | 0:345b3bc7a0ea | 55 | vector<vector2D> lightForce; |
mbedalvaro | 0:345b3bc7a0ea | 56 | //vector2D totalLightForce; // this belongs to the base class now |
mbedalvaro | 0:345b3bc7a0ea | 57 | |
mbedalvaro | 0:345b3bc7a0ea | 58 | // For the central anchor point: |
mbedalvaro | 0:345b3bc7a0ea | 59 | pointMass anchorMass; |
mbedalvaro | 0:345b3bc7a0ea | 60 | vector<spring> centralSpringArray; |
mbedalvaro | 0:345b3bc7a0ea | 61 | |
mbedalvaro | 0:345b3bc7a0ea | 62 | // ====================== VARIABLES ====================== |
mbedalvaro | 0:345b3bc7a0ea | 63 | // 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 | 64 | // int numMasses; |
mbedalvaro | 0:345b3bc7a0ea | 65 | |
mbedalvaro | 0:345b3bc7a0ea | 66 | // Meta-modes for the elastic loop: |
mbedalvaro | 0:345b3bc7a0ea | 67 | ElasticLoopMode loopMode; |
mbedalvaro | 0:345b3bc7a0ea | 68 | |
mbedalvaro | 0:345b3bc7a0ea | 69 | // Detail modes (could be in a struct) |
mbedalvaro | 0:345b3bc7a0ea | 70 | // Behaviour mode: |
mbedalvaro | 0:345b3bc7a0ea | 71 | bool pseudopodesMode; |
mbedalvaro | 0:345b3bc7a0ea | 72 | bool slidingDirection; // for contour following |
mbedalvaro | 0:345b3bc7a0ea | 73 | bool springForcesOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 74 | bool lightForcesOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 75 | bool forceBorderOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 76 | bool recenteringForceOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 77 | bool nuclearForceOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 78 | bool interParticleForceOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 79 | bool forceInternalPressureOnLoop; |
mbedalvaro | 0:345b3bc7a0ea | 80 | bool recenteringForceOnNucleus; |
mbedalvaro | 0:345b3bc7a0ea | 81 | |
mbedalvaro | 0:345b3bc7a0ea | 82 | // 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 | 83 | // ex: if it is 180deg, then the blob just "bounces" on the zone transition; if it is 90, it does contour following... |
mbedalvaro | 0:345b3bc7a0ea | 84 | float angleCorrectionForceLoop; |
mbedalvaro | 0:345b3bc7a0ea | 85 | float angleCorrectionForceNucleus; |
mbedalvaro | 0:345b3bc7a0ea | 86 | |
mbedalvaro | 0:345b3bc7a0ea | 87 | vector2D recenteringVectorNucleus; |
mbedalvaro | 0:345b3bc7a0ea | 88 | // the following are common to all blobs: |
mbedalvaro | 0:345b3bc7a0ea | 89 | // vector2D recenteringVectorLoop; |
mbedalvaro | 0:345b3bc7a0ea | 90 | // float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop) |
mbedalvaro | 0:345b3bc7a0ea | 91 | // float normRecenteringVector; |
mbedalvaro | 0:345b3bc7a0ea | 92 | |
mbedalvaro | 0:345b3bc7a0ea | 93 | // Numeric parameters: |
mbedalvaro | 0:345b3bc7a0ea | 94 | float massLoopParticle; |
mbedalvaro | 0:345b3bc7a0ea | 95 | float dampMotionMassesLoop; |
mbedalvaro | 0:345b3bc7a0ea | 96 | float massAnchor; |
mbedalvaro | 0:345b3bc7a0ea | 97 | float dampMotionAnchorMass; |
mbedalvaro | 0:345b3bc7a0ea | 98 | |
mbedalvaro | 0:345b3bc7a0ea | 99 | float interSpringK, interSpringRelax; |
mbedalvaro | 0:345b3bc7a0ea | 100 | float centralSpringK, centralSpringRelax; |
mbedalvaro | 0:345b3bc7a0ea | 101 | float factorLightForce; |
mbedalvaro | 0:345b3bc7a0ea | 102 | float factorRecenteringAnchorMass; |
mbedalvaro | 0:345b3bc7a0ea | 103 | float factorRecenteringLoopMass; |
mbedalvaro | 0:345b3bc7a0ea | 104 | float factorPressureLoopMass; |
mbedalvaro | 0:345b3bc7a0ea | 105 | float factorForceBorder; |
mbedalvaro | 0:345b3bc7a0ea | 106 | float interParticleRange, factorInterParticleForce; // zach like blob force |
mbedalvaro | 0:345b3bc7a0ea | 107 | |
mbedalvaro | 0:345b3bc7a0ea | 108 | // SOUND SENDING MODES (specific to this kind of blob object): |
mbedalvaro | 0:345b3bc7a0ea | 109 | /* |
mbedalvaro | 0:345b3bc7a0ea | 110 | // (a) anchor mass data: |
mbedalvaro | 0:345b3bc7a0ea | 111 | bool sendingAnchorPosition; |
mbedalvaro | 0:345b3bc7a0ea | 112 | bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force |
mbedalvaro | 0:345b3bc7a0ea | 113 | bool sendingAnchorTouchWall; |
mbedalvaro | 0:345b3bc7a0ea | 114 | // (b) data from blob points: |
mbedalvaro | 0:345b3bc7a0ea | 115 | bool sendingLoopPositions; |
mbedalvaro | 0:345b3bc7a0ea | 116 | bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle |
mbedalvaro | 0:345b3bc7a0ea | 117 | bool sendingLoopForcesLight; |
mbedalvaro | 0:345b3bc7a0ea | 118 | bool sendingLoopRegions; // from this we can detect "hits" |
mbedalvaro | 0:345b3bc7a0ea | 119 | bool sendingLoopTouchWall; |
mbedalvaro | 0:345b3bc7a0ea | 120 | // (c) Blob geometry: |
mbedalvaro | 0:345b3bc7a0ea | 121 | bool sendingBlobArea; |
mbedalvaro | 0:345b3bc7a0ea | 122 | bool sendingBlobNormals; |
mbedalvaro | 0:345b3bc7a0ea | 123 | bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal) |
mbedalvaro | 0:345b3bc7a0ea | 124 | */ |
mbedalvaro | 0:345b3bc7a0ea | 125 | |
mbedalvaro | 0:345b3bc7a0ea | 126 | }; |
mbedalvaro | 0:345b3bc7a0ea | 127 | |
mbedalvaro | 0:345b3bc7a0ea | 128 | #endif |