![](/media/cache/profiles/68a15b5278e4f7c4c056df9d5f1d3b1f.jpg.50x50_q85.jpg)
save loops
classPointMass.h@0:df6fdd9b99f0, 2014-12-02 (annotated)
- Committer:
- mbedalvaro
- Date:
- Tue Dec 02 04:39:15 2014 +0000
- Revision:
- 0:df6fdd9b99f0
this new version of skinGames will have a function that stops scanning as the laser reaches the same position (i.e., loops) with a certain precision. It is for extracting contours for Takashita project. It can then save on a file or send on osc
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:df6fdd9b99f0 | 1 | /* |
mbedalvaro | 0:df6fdd9b99f0 | 2 | * pointMass.h |
mbedalvaro | 0:df6fdd9b99f0 | 3 | * laserBlob |
mbedalvaro | 0:df6fdd9b99f0 | 4 | * |
mbedalvaro | 0:df6fdd9b99f0 | 5 | * Created by CASSINELLI ALVARO on 5/19/11. |
mbedalvaro | 0:df6fdd9b99f0 | 6 | * Copyright 2011 TOKYO UNIVERSITY. All rights reserved. |
mbedalvaro | 0:df6fdd9b99f0 | 7 | * |
mbedalvaro | 0:df6fdd9b99f0 | 8 | */ |
mbedalvaro | 0:df6fdd9b99f0 | 9 | |
mbedalvaro | 0:df6fdd9b99f0 | 10 | #ifndef POINTMASS_H |
mbedalvaro | 0:df6fdd9b99f0 | 11 | #define POINTMASS_H |
mbedalvaro | 0:df6fdd9b99f0 | 12 | |
mbedalvaro | 0:df6fdd9b99f0 | 13 | #include "myVectorClass.h" |
mbedalvaro | 0:df6fdd9b99f0 | 14 | |
mbedalvaro | 0:df6fdd9b99f0 | 15 | #define VERLET_METHOD // comment this to have EULER method |
mbedalvaro | 0:df6fdd9b99f0 | 16 | |
mbedalvaro | 0:df6fdd9b99f0 | 17 | #define MAX_PERMISSIBLE_SPEED 35 |
mbedalvaro | 0:df6fdd9b99f0 | 18 | |
mbedalvaro | 0:df6fdd9b99f0 | 19 | class pointMass |
mbedalvaro | 0:df6fdd9b99f0 | 20 | { |
mbedalvaro | 0:df6fdd9b99f0 | 21 | public: |
mbedalvaro | 0:df6fdd9b99f0 | 22 | |
mbedalvaro | 0:df6fdd9b99f0 | 23 | // ==================================== Static variables and methods ============== |
mbedalvaro | 0:df6fdd9b99f0 | 24 | static vector2Df maxWall, minWall; //equal for ALL THE MASS OBJECTS (declare static). But it could be per-mass. The problem with that approach would be too much wasted memory. |
mbedalvaro | 0:df6fdd9b99f0 | 25 | // NOTE: - a static member variable has the same value in any instance of the class and doesn't even require an instance of the class to exist. |
mbedalvaro | 0:df6fdd9b99f0 | 26 | // - a static class member cannot be initialized inside of the class declaration. In fact, if you decide to put your code in a header file, you cannot even initialize the static variable |
mbedalvaro | 0:df6fdd9b99f0 | 27 | // inside of the header file; do it in a .cpp file instead. Moreover, you are required to initialize the static class member or it will not be in scope. |
mbedalvaro | 0:df6fdd9b99f0 | 28 | // The syntax is a bit weird: "type class_name::static_variable = value", or in this case vector2Df pointMass::maxWall(4095, 4095) |
mbedalvaro | 0:df6fdd9b99f0 | 29 | |
mbedalvaro | 0:df6fdd9b99f0 | 30 | // methods: |
mbedalvaro | 0:df6fdd9b99f0 | 31 | static void setWallLimits(float mminx, float mminy, float mmaxx, float mmaxy); |
mbedalvaro | 0:df6fdd9b99f0 | 32 | |
mbedalvaro | 0:df6fdd9b99f0 | 33 | // ==================================== METHODS ==================================== |
mbedalvaro | 0:df6fdd9b99f0 | 34 | pointMass(); |
mbedalvaro | 0:df6fdd9b99f0 | 35 | virtual ~pointMass(){}; |
mbedalvaro | 0:df6fdd9b99f0 | 36 | |
mbedalvaro | 0:df6fdd9b99f0 | 37 | // Adding forces to total force: |
mbedalvaro | 0:df6fdd9b99f0 | 38 | void resetForce(); |
mbedalvaro | 0:df6fdd9b99f0 | 39 | void addForce(float x, float y); |
mbedalvaro | 0:df6fdd9b99f0 | 40 | void addForce(vector2Df force); |
mbedalvaro | 0:df6fdd9b99f0 | 41 | void addDampingForce(); |
mbedalvaro | 0:df6fdd9b99f0 | 42 | void addInvSquareForce(float x, float y, float radiusMax, float radiusMin, float scale); |
mbedalvaro | 0:df6fdd9b99f0 | 43 | void addInterInvSquareForce(pointMass &p, float radiusMin, float radiusMax, float scale); |
mbedalvaro | 0:df6fdd9b99f0 | 44 | |
mbedalvaro | 0:df6fdd9b99f0 | 45 | // (a blob object could be defined by a "cord" of chained particles, plus a center) |
mbedalvaro | 0:df6fdd9b99f0 | 46 | void addSpringForce(float x, float y, float radius, float scale); |
mbedalvaro | 0:df6fdd9b99f0 | 47 | void addInterSpringForce(pointMass &p, float radius, float scale); |
mbedalvaro | 0:df6fdd9b99f0 | 48 | //void addClockwiseForce(particle &p, float radius, float scale); |
mbedalvaro | 0:df6fdd9b99f0 | 49 | //void addCounterClockwiseForce(particle &p, float radius, float scale); |
mbedalvaro | 0:df6fdd9b99f0 | 50 | |
mbedalvaro | 0:df6fdd9b99f0 | 51 | //void addDampingForce(); // this work in the case of the euler integration; in case of Verlet, we need to do pseudo-damping while calculating |
mbedalvaro | 0:df6fdd9b99f0 | 52 | // the acceleration... |
mbedalvaro | 0:df6fdd9b99f0 | 53 | |
mbedalvaro | 0:df6fdd9b99f0 | 54 | // Set parameters: |
mbedalvaro | 0:df6fdd9b99f0 | 55 | void setInitialCondition(float px, float py, float vx, float vy); |
mbedalvaro | 0:df6fdd9b99f0 | 56 | void setInitialCondition(vector2Df _pos, vector2Df _speed); |
mbedalvaro | 0:df6fdd9b99f0 | 57 | void setIntegrationStep(float _dt); |
mbedalvaro | 0:df6fdd9b99f0 | 58 | |
mbedalvaro | 0:df6fdd9b99f0 | 59 | void setPos(float px, float py); // assuming the speed is unchanged (must do some tweaking in case of Verlet integration) |
mbedalvaro | 0:df6fdd9b99f0 | 60 | |
mbedalvaro | 0:df6fdd9b99f0 | 61 | // dynamic update: |
mbedalvaro | 0:df6fdd9b99f0 | 62 | void update(); |
mbedalvaro | 0:df6fdd9b99f0 | 63 | |
mbedalvaro | 0:df6fdd9b99f0 | 64 | // kinematic constraints (could be based on a force too...) |
mbedalvaro | 0:df6fdd9b99f0 | 65 | //void setWallLimits(float mminx, float mminy, float mmaxx, float mmaxy); // DECLARED STATIC |
mbedalvaro | 0:df6fdd9b99f0 | 66 | void bounceOffWalls(); |
mbedalvaro | 0:df6fdd9b99f0 | 67 | |
mbedalvaro | 0:df6fdd9b99f0 | 68 | vector2Df getSpeed(); // get an estimation of the speed (also update speed variable - this variable is not needed in case of VERLET) |
mbedalvaro | 0:df6fdd9b99f0 | 69 | void setSpeed(const vector2Df& vel); |
mbedalvaro | 0:df6fdd9b99f0 | 70 | void setSpeed(float vx, float vy); |
mbedalvaro | 0:df6fdd9b99f0 | 71 | |
mbedalvaro | 0:df6fdd9b99f0 | 72 | // ==================================== VARIABLES ==================================== |
mbedalvaro | 0:df6fdd9b99f0 | 73 | |
mbedalvaro | 0:df6fdd9b99f0 | 74 | int identifier; // this may be needed in particular in case we don't use vector<> (case of poor C Arduino compiler) |
mbedalvaro | 0:df6fdd9b99f0 | 75 | |
mbedalvaro | 0:df6fdd9b99f0 | 76 | // kinematic variables: |
mbedalvaro | 0:df6fdd9b99f0 | 77 | vector2Df pos, posOld; // I will use verlet integration (perhaps we could have a switch to choose the integration method?) |
mbedalvaro | 0:df6fdd9b99f0 | 78 | //vector2D speed; // speed at time t (this is not explicitly calculated in case of verlet method, HENCE PRIVATE) |
mbedalvaro | 0:df6fdd9b99f0 | 79 | vector2Df acc; // Acceleration at time t (equal to the total force divided by the mass). No real need to have it here, but convenient to check. |
mbedalvaro | 0:df6fdd9b99f0 | 80 | vector2Df totalForce; // this is just for convenience and speeding up calculation when adding forces, before computing acc. |
mbedalvaro | 0:df6fdd9b99f0 | 81 | |
mbedalvaro | 0:df6fdd9b99f0 | 82 | // integration step: |
mbedalvaro | 0:df6fdd9b99f0 | 83 | float dt; |
mbedalvaro | 0:df6fdd9b99f0 | 84 | |
mbedalvaro | 0:df6fdd9b99f0 | 85 | // physical parameters: |
mbedalvaro | 0:df6fdd9b99f0 | 86 | float dampMotion; |
mbedalvaro | 0:df6fdd9b99f0 | 87 | float dampBorder; |
mbedalvaro | 0:df6fdd9b99f0 | 88 | float mass; |
mbedalvaro | 0:df6fdd9b99f0 | 89 | bool bFixed; // these could act as control points that could be loaded (letters...). In fact, we could use mass to set this (like mass=-1) |
mbedalvaro | 0:df6fdd9b99f0 | 90 | |
mbedalvaro | 0:df6fdd9b99f0 | 91 | // other things: |
mbedalvaro | 0:df6fdd9b99f0 | 92 | bool bWallCollision; // this is generic (detect any collision with a side) |
mbedalvaro | 0:df6fdd9b99f0 | 93 | vector2Df innerCollitionDirection; // this is smarter than a boolean, because I can detect which side was touched and do different things (but may be memory consuming) |
mbedalvaro | 0:df6fdd9b99f0 | 94 | |
mbedalvaro | 0:df6fdd9b99f0 | 95 | protected: |
mbedalvaro | 0:df6fdd9b99f0 | 96 | |
mbedalvaro | 0:df6fdd9b99f0 | 97 | private: |
mbedalvaro | 0:df6fdd9b99f0 | 98 | vector2Df speed; // speed at time t (this is not explicitly calculated in case of verlet method, HENCE MAY BE PRIVATE) |
mbedalvaro | 0:df6fdd9b99f0 | 99 | |
mbedalvaro | 0:df6fdd9b99f0 | 100 | }; |
mbedalvaro | 0:df6fdd9b99f0 | 101 | |
mbedalvaro | 0:df6fdd9b99f0 | 102 | |
mbedalvaro | 0:df6fdd9b99f0 | 103 | #endif //POINTMASS_H |