Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
classPointMass.h@48:7633d8e7b0d3, 2014-12-02 (annotated)
- Committer:
- mbedalvaro
- Date:
- Tue Dec 02 04:28:42 2014 +0000
- Revision:
- 48:7633d8e7b0d3
- Parent:
- 35:35af5086ab4f
this is the working version of the skin games sowtware (aka, scorelight but with pre-determined "games")
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 35:35af5086ab4f | 1 | /* |
mbedalvaro | 35:35af5086ab4f | 2 | * pointMass.h |
mbedalvaro | 35:35af5086ab4f | 3 | * laserBlob |
mbedalvaro | 35:35af5086ab4f | 4 | * |
mbedalvaro | 35:35af5086ab4f | 5 | * Created by CASSINELLI ALVARO on 5/19/11. |
mbedalvaro | 35:35af5086ab4f | 6 | * Copyright 2011 TOKYO UNIVERSITY. All rights reserved. |
mbedalvaro | 35:35af5086ab4f | 7 | * |
mbedalvaro | 35:35af5086ab4f | 8 | */ |
mbedalvaro | 35:35af5086ab4f | 9 | |
mbedalvaro | 35:35af5086ab4f | 10 | #ifndef POINTMASS_H |
mbedalvaro | 35:35af5086ab4f | 11 | #define POINTMASS_H |
mbedalvaro | 35:35af5086ab4f | 12 | |
mbedalvaro | 35:35af5086ab4f | 13 | #include "myVectorClass.h" |
mbedalvaro | 35:35af5086ab4f | 14 | |
mbedalvaro | 35:35af5086ab4f | 15 | #define VERLET_METHOD // comment this to have EULER method |
mbedalvaro | 35:35af5086ab4f | 16 | |
mbedalvaro | 35:35af5086ab4f | 17 | #define MAX_PERMISSIBLE_SPEED 35 |
mbedalvaro | 35:35af5086ab4f | 18 | |
mbedalvaro | 35:35af5086ab4f | 19 | class pointMass |
mbedalvaro | 35:35af5086ab4f | 20 | { |
mbedalvaro | 35:35af5086ab4f | 21 | public: |
mbedalvaro | 35:35af5086ab4f | 22 | |
mbedalvaro | 35:35af5086ab4f | 23 | // ==================================== Static variables and methods ============== |
mbedalvaro | 35:35af5086ab4f | 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 | 35:35af5086ab4f | 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 | 35:35af5086ab4f | 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 | 35:35af5086ab4f | 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 | 35:35af5086ab4f | 28 | // The syntax is a bit weird: "type class_name::static_variable = value", or in this case vector2Df pointMass::maxWall(4095, 4095) |
mbedalvaro | 35:35af5086ab4f | 29 | |
mbedalvaro | 35:35af5086ab4f | 30 | // methods: |
mbedalvaro | 35:35af5086ab4f | 31 | static void setWallLimits(float mminx, float mminy, float mmaxx, float mmaxy); |
mbedalvaro | 35:35af5086ab4f | 32 | |
mbedalvaro | 35:35af5086ab4f | 33 | // ==================================== METHODS ==================================== |
mbedalvaro | 35:35af5086ab4f | 34 | pointMass(); |
mbedalvaro | 35:35af5086ab4f | 35 | virtual ~pointMass(){}; |
mbedalvaro | 35:35af5086ab4f | 36 | |
mbedalvaro | 35:35af5086ab4f | 37 | // Adding forces to total force: |
mbedalvaro | 35:35af5086ab4f | 38 | void resetForce(); |
mbedalvaro | 35:35af5086ab4f | 39 | void addForce(float x, float y); |
mbedalvaro | 35:35af5086ab4f | 40 | void addForce(vector2Df force); |
mbedalvaro | 35:35af5086ab4f | 41 | void addDampingForce(); |
mbedalvaro | 35:35af5086ab4f | 42 | void addInvSquareForce(float x, float y, float radiusMax, float radiusMin, float scale); |
mbedalvaro | 35:35af5086ab4f | 43 | void addInterInvSquareForce(pointMass &p, float radiusMin, float radiusMax, float scale); |
mbedalvaro | 35:35af5086ab4f | 44 | |
mbedalvaro | 35:35af5086ab4f | 45 | // (a blob object could be defined by a "cord" of chained particles, plus a center) |
mbedalvaro | 35:35af5086ab4f | 46 | void addSpringForce(float x, float y, float radius, float scale); |
mbedalvaro | 35:35af5086ab4f | 47 | void addInterSpringForce(pointMass &p, float radius, float scale); |
mbedalvaro | 35:35af5086ab4f | 48 | //void addClockwiseForce(particle &p, float radius, float scale); |
mbedalvaro | 35:35af5086ab4f | 49 | //void addCounterClockwiseForce(particle &p, float radius, float scale); |
mbedalvaro | 35:35af5086ab4f | 50 | |
mbedalvaro | 35:35af5086ab4f | 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 | 35:35af5086ab4f | 52 | // the acceleration... |
mbedalvaro | 35:35af5086ab4f | 53 | |
mbedalvaro | 35:35af5086ab4f | 54 | // Set parameters: |
mbedalvaro | 35:35af5086ab4f | 55 | void setInitialCondition(float px, float py, float vx, float vy); |
mbedalvaro | 35:35af5086ab4f | 56 | void setInitialCondition(vector2Df _pos, vector2Df _speed); |
mbedalvaro | 35:35af5086ab4f | 57 | void setIntegrationStep(float _dt); |
mbedalvaro | 35:35af5086ab4f | 58 | |
mbedalvaro | 35:35af5086ab4f | 59 | void setPos(float px, float py); // assuming the speed is unchanged (must do some tweaking in case of Verlet integration) |
mbedalvaro | 35:35af5086ab4f | 60 | |
mbedalvaro | 35:35af5086ab4f | 61 | // dynamic update: |
mbedalvaro | 35:35af5086ab4f | 62 | void update(); |
mbedalvaro | 35:35af5086ab4f | 63 | |
mbedalvaro | 35:35af5086ab4f | 64 | // kinematic constraints (could be based on a force too...) |
mbedalvaro | 35:35af5086ab4f | 65 | //void setWallLimits(float mminx, float mminy, float mmaxx, float mmaxy); // DECLARED STATIC |
mbedalvaro | 35:35af5086ab4f | 66 | void bounceOffWalls(); |
mbedalvaro | 35:35af5086ab4f | 67 | |
mbedalvaro | 35:35af5086ab4f | 68 | vector2Df getSpeed(); // get an estimation of the speed (also update speed variable - this variable is not needed in case of VERLET) |
mbedalvaro | 35:35af5086ab4f | 69 | void setSpeed(const vector2Df& vel); |
mbedalvaro | 35:35af5086ab4f | 70 | void setSpeed(float vx, float vy); |
mbedalvaro | 35:35af5086ab4f | 71 | |
mbedalvaro | 35:35af5086ab4f | 72 | // ==================================== VARIABLES ==================================== |
mbedalvaro | 35:35af5086ab4f | 73 | |
mbedalvaro | 35:35af5086ab4f | 74 | int identifier; // this may be needed in particular in case we don't use vector<> (case of poor C Arduino compiler) |
mbedalvaro | 35:35af5086ab4f | 75 | |
mbedalvaro | 35:35af5086ab4f | 76 | // kinematic variables: |
mbedalvaro | 35:35af5086ab4f | 77 | vector2Df pos, posOld; // I will use verlet integration (perhaps we could have a switch to choose the integration method?) |
mbedalvaro | 35:35af5086ab4f | 78 | //vector2D speed; // speed at time t (this is not explicitly calculated in case of verlet method, HENCE PRIVATE) |
mbedalvaro | 35:35af5086ab4f | 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 | 35:35af5086ab4f | 80 | vector2Df totalForce; // this is just for convenience and speeding up calculation when adding forces, before computing acc. |
mbedalvaro | 35:35af5086ab4f | 81 | |
mbedalvaro | 35:35af5086ab4f | 82 | // integration step: |
mbedalvaro | 35:35af5086ab4f | 83 | float dt; |
mbedalvaro | 35:35af5086ab4f | 84 | |
mbedalvaro | 35:35af5086ab4f | 85 | // physical parameters: |
mbedalvaro | 35:35af5086ab4f | 86 | float dampMotion; |
mbedalvaro | 35:35af5086ab4f | 87 | float dampBorder; |
mbedalvaro | 35:35af5086ab4f | 88 | float mass; |
mbedalvaro | 35:35af5086ab4f | 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 | 35:35af5086ab4f | 90 | |
mbedalvaro | 35:35af5086ab4f | 91 | // other things: |
mbedalvaro | 35:35af5086ab4f | 92 | bool bWallCollision; // this is generic (detect any collision with a side) |
mbedalvaro | 35:35af5086ab4f | 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 | 35:35af5086ab4f | 94 | |
mbedalvaro | 35:35af5086ab4f | 95 | protected: |
mbedalvaro | 35:35af5086ab4f | 96 | |
mbedalvaro | 35:35af5086ab4f | 97 | private: |
mbedalvaro | 35:35af5086ab4f | 98 | vector2Df speed; // speed at time t (this is not explicitly calculated in case of verlet method, HENCE MAY BE PRIVATE) |
mbedalvaro | 35:35af5086ab4f | 99 | |
mbedalvaro | 35:35af5086ab4f | 100 | }; |
mbedalvaro | 35:35af5086ab4f | 101 | |
mbedalvaro | 35:35af5086ab4f | 102 | |
mbedalvaro | 0:345b3bc7a0ea | 103 | #endif //POINTMASS_H |