just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Fri Sep 21 10:02:35 2012 +0000
Revision:
30:d8af03f01cd4
Parent:
29:2fc8c12822eb
Child:
35:35af5086ab4f
first commit. Not yet functional. Added ghost and pacman game modes, but the behaviour of these "rigid spots" is not implemented yet

Who changed what in which revision?

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