just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Revision:
12:0de9cd2bced5
Parent:
5:73cd58b58f95
Child:
24:4e52031a495b
diff -r 62f7183a03e7 -r 0de9cd2bced5 classPointMass.cpp
--- a/classPointMass.cpp	Thu Apr 12 05:16:48 2012 +0000
+++ b/classPointMass.cpp	Thu Apr 12 08:38:44 2012 +0000
@@ -9,6 +9,10 @@
 
 #include "classPointMass.h"
 
+// Initialization of static member variables: 
+vector2Df pointMass::maxWall(4095, 4095);
+vector2Df pointMass::minWall(0, 0);
+
 //------------------------------------------------------------
 pointMass::pointMass(){
     setIntegrationStep(.01); // default in case we don't call integration step setting
@@ -35,17 +39,17 @@
 }
 
 //------------------------------------------------------------
-void pointMass::addForce(vector2D forceToAdd){
+void pointMass::addForce(vector2Df forceToAdd){
     totalForce+=forceToAdd;
 }
 
 //------------------------------------------------------------
 void pointMass::addInvSquareForce(float x, float y, float radiusMin, float radiusMax, float scale){
     
-    vector2D posOfForce;
+    vector2Df posOfForce;
     posOfForce.set(x,y);
         
-    vector2D diff    = pos - posOfForce; // note: we use the position AT TIME T, so this force is at time t
+    vector2Df diff    = pos - posOfForce; // note: we use the position AT TIME T, so this force is at time t
     float length    = diff.length();
     
     // check close enough and far enough (to avoid singularities for example):
@@ -57,10 +61,10 @@
 
 void pointMass::addInterInvSquareForce(pointMass &theOtherParticle, float radiusMin, float radiusMax, float scale){
     
-    vector2D posOfForce;
+    vector2Df posOfForce;
     posOfForce.set(theOtherParticle.pos);
     
-    vector2D diff    = pos - posOfForce; // note: we use the position AT TIME T, so this force is at time t
+    vector2Df diff    = pos - posOfForce; // note: we use the position AT TIME T, so this force is at time t
     float length    = diff.length();
     
     // check close enough and far enough (to avoid singularities for example):
@@ -76,12 +80,12 @@
 void pointMass::addSpringForce(float centerx, float centery, float radius, float scale){
     
     // ----------- (1) make a vector of where this particle p is: 
-    vector2D posOfForce;
+    vector2Df posOfForce;
     posOfForce.set(centerx, centery);
     
     // ----------- (2) calculate the difference & length 
     
-    vector2D diff    = pos - posOfForce;
+    vector2Df diff    = pos - posOfForce;
     float length    = diff.length();
     
     // ----------- (3) check close enough
@@ -105,12 +109,12 @@
 void pointMass::addInterSpringForce(pointMass &theOtherParticle, float radius, float scale){
     
     // ----------- (1) make a vector of where this particle p is: 
-    vector2D posOfForce;
+    vector2Df posOfForce;
     posOfForce.set(theOtherParticle.pos);
     
     // ----------- (2) calculate the difference & length 
     
-    vector2D diff    = pos - posOfForce;
+    vector2Df diff    = pos - posOfForce;
     float length    = diff.length();
     
     // ----------- (3) check close enough
@@ -147,7 +151,7 @@
 }
 
 //------------------------------------------------------------
-void pointMass::setInitialCondition(vector2D _pos, vector2D _speed) {
+void pointMass::setInitialCondition(vector2Df _pos, vector2Df _speed) {
     setInitialCondition(_pos.x, _pos.y, _speed.x, _speed.y); 
 }
 void pointMass::setInitialCondition(float px, float py, float vx, float vy){
@@ -164,14 +168,14 @@
 }
 
 //-------------------------------------------------------
-vector2D pointMass::getSpeed() {
+vector2Df pointMass::getSpeed() {
     // this will give an estimate of the speed (not computed explicitly using the Verlet integration):
     //speed=(posNew-posOld)/(2*dt); // the variable speed is also updated (note: it is private)
     speed=(pos-posOld)/dt; // less approximate than the above, but we avoid having a global posNew variable (remember we will have many particles...)
     return(speed); 
 }
 
-void pointMass::setSpeed(const vector2D& vel) { // VERY IMPORTANT! in the case of verlet integration, we need to set dt BEFORE setting the initial speed. 
+void pointMass::setSpeed(const vector2Df& vel) { // VERY IMPORTANT! in the case of verlet integration, we need to set dt BEFORE setting the initial speed. 
     speed.set(vel); // enough for EULER METHOD
    
    // NECESSARY for VERLET METHOD (we assume posOld known):
@@ -215,21 +219,21 @@
        // acc=0;//
         // The following equations are for VERLET integration with pseudo-damping:
           //Without damping this is just:
-        //vector2D posNew=posOld*2 - pos + acc*dt*dt; // i.e., dampMotion=0;
+        //vector2Df posNew=posOld*2 - pos + acc*dt*dt; // i.e., dampMotion=0;
         // With damping: 
-//         vector2D posNew=(pos*(2.0-dampMotion)-posOld*(1.0-dampMotion)+acc*dt*dt); // BAD!!! THIS NOTATION will introduce precision artefacts!!!
-        vector2D posNew=pos+(pos-posOld)*(1-dampMotion)+acc*dt*dt;
+//         vector2Df posNew=(pos*(2.0-dampMotion)-posOld*(1.0-dampMotion)+acc*dt*dt); // BAD!!! THIS NOTATION will introduce precision artefacts!!!
+        vector2Df posNew=pos+(pos-posOld)*(1-dampMotion)+acc*dt*dt;
         
         // ATTENTION: because of the precision of the float or double used, it may be that (pos - posNew) is not 0, when it should ( this produces VERY strange motion artefacts).
         // So, I will test if that difference is smaller than an arbitrary tollerance in this numerical implementation (for each coordinate), and if so, will FORCE posNew to be equal to pos. 
         // Note: no need to compute the norm of the difference (in fact, we need the abs difference for each component of the difference vector). Fortunately, nothing is needed here, because we can put the 
         // expression in a better way that automatically makes 0 the contribution of something smaller than the precision (so the following is not really necessary) 
-//        vector2D diff=(pos-posOld)*(1-dampMotion);
+//        vector2Df diff=(pos-posOld)*(1-dampMotion);
         // Precision correction (separate axis or not): 
        // if (abs(diff.x)<0.00001) diff.x=diff.x;
        // if (abs(diff.y)<0.00001) diff.y=diff.y;
        //   if (posOld.match(pos, 0.001)==true) {posNew=pos; speed.set(0,0);}
-//        vector2D posNew=pos+diff+acc*dt*dt;
+//        vector2Df posNew=pos+diff+acc*dt*dt;
      
         posOld=pos;
         pos=posNew;
@@ -255,7 +259,7 @@
 //------------------------------------------------------------
 void pointMass::bounceOffWalls(){
     // NOTE: bounce is easy in case of EULER method; in case of VERLET, we need to do some hack on the positions.
-    //Note: the walls are in (vector2D) horizontalLimits and verticalLimits 
+    //Note: the walls are in (vector2Dd) horizontalLimits and verticalLimits 
  
     bWallCollision=false;
     innerCollitionDirection.set(0,0);
@@ -294,7 +298,7 @@
     
 #else // THIS IS FOR VERLET METHOD:
     // we need to estimate the inverted, damped vector for bumping::
-    vector2D bumpVector=getSpeed()*dt*(dampBorder-1.0); // assuming dampBorder<1 of course
+    vector2Df bumpVector=getSpeed()*dt*(dampBorder-1.0); // assuming dampBorder<1 of course
     if (pos.x > maxWall.x){
         //posOld.x=pos.x;
         //pos.x=pos.x+bumpVector.x;