diff options
author | N.N. <nimon@users.sourceforge.net> | 2005-04-26 16:10:08 +0000 |
---|---|---|
committer | N.N. <nimon@users.sourceforge.net> | 2005-04-26 16:10:08 +0000 |
commit | 2d390319a45282ffa6fcc5da41bbac81eb26fb3c (patch) | |
tree | 52905a8f94ff4ee05ed30ae6412f13944c7deacd /msd/main.cpp | |
parent | 3d7f8e6f9f4c708c6130ea0a63c2eb139f34327a (diff) |
MSD Version 0.04
svn path=/trunk/externals/nusmuk/; revision=2826
Diffstat (limited to 'msd/main.cpp')
-rwxr-xr-x | msd/main.cpp | 188 |
1 files changed, 108 insertions, 80 deletions
diff --git a/msd/main.cpp b/msd/main.cpp index 69dfbd5..f74ba3d 100755 --- a/msd/main.cpp +++ b/msd/main.cpp @@ -30,7 +30,7 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Version 0.03 -- 21.04.2005 + Version 0.04 -- 26.04.2005 */ // include flext header @@ -38,7 +38,7 @@ #include <math.h> // define constants -#define MSD_VERSION 0.03 +#define MSD_VERSION 0.04 #define nb_max_link 4000 #define nb_max_mass 4000 #define Id_length 20 @@ -135,7 +135,9 @@ protected: t_float F=0,Fx=0,distance,vitesse, X_new; t_int i; struct _mass mass_1, mass_2; - + + + for (i=0; i<nb_link; i++) { // compute link forces distance = link[i]->mass1->posX-link[i]->mass2->posX; // L[n] = x1 - x2 @@ -154,10 +156,10 @@ protected: link[i]->mass2->forceX += Fx; // Fx2[n] = Fx link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1] link[i]->distance_old = distance; // L[n-1] = L[n] - - } + + for (i=0; i<nb_mass; i++) // compute new masses position only if mobile = 1 if (mass[i]->mobile == 1) { @@ -198,7 +200,7 @@ protected: mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1] mass[nb_mass]->forceX = 0; // Fx[n] mass[nb_mass]->nbr = id_mass; // id number - nb_mass++ ; + nb_mass++; id_mass++; nb_mass = min ( nb_max_mass -1, nb_mass ); SetFloat((sortie[0]),id_mass-1); @@ -350,51 +352,65 @@ protected: { t_atom sortie[7], aux[2]; t_int i; - - if (argc < 6 || argc > 8) - error("link : Id Nomass1 Nomass2 K D1 D2 (Lmin Lmax)"); - link[nb_link] = new t_link; // New pointer - link[nb_link]->Id = GetSymbol(argv[0]); // ID - for (i=0; i<nb_mass;i++) - if (mass[i]->nbr==GetAInt(argv[1])) // pointer to mass1 - link[nb_link]->mass1 = mass[i]; - else if(mass[i]->nbr==GetAInt(argv[2])) // pointer to mass2 - link[nb_link]->mass2 = mass[i]; - link[nb_link]->K1 = GetFloat(argv[3]); // K1 - link[nb_link]->D1 = GetFloat(argv[4]); // D1 - link[nb_link]->D2 = GetFloat(argv[5]); // D2 - link[nb_link]->longx = link[nb_link]->mass1->posX - link[nb_link]->mass2->posX; // Lx[0] - if (link[nb_link]->longx < 0) - link[nb_link]->longueur = -link[nb_link]->longx; - else - link[nb_link]->longueur = link[nb_link]->longx ;// L[0] - link[nb_link]->nbr = id_link; // id number - link[nb_link]->distance_old = link[nb_link]->longueur; // L[n-1] - switch (argc) { - case 6 : - link[nb_link]->long_max = 32768; - link[nb_link]->long_min = 0; - break; - case 7 : - link[nb_link]->long_min = GetFloat(argv[6]); - link[nb_link]->long_max = 32768; - break; - case 8 : - link[nb_link]->long_min = GetFloat(argv[6]); - link[nb_link]->long_max = GetFloat(argv[7]); - break; - } - nb_link++; - id_link++; - nb_link = min ( nb_max_link -1, nb_link ); - SetFloat((sortie[0]),id_link-1); - SetSymbol((sortie[1]),link[nb_link-1]->Id); - SetFloat((sortie[2]),GetInt(argv[1])); - SetFloat((sortie[3]),GetInt(argv[2])); - SetFloat((sortie[4]),link[nb_link-1]->K1); - SetFloat((sortie[5]),link[nb_link-1]->D1); - SetFloat((sortie[6]),link[nb_link-1]->D2); - ToOutAnything(1,S_Link,7,sortie); + t_mass *mass1 = NULL; + t_mass *mass2 = NULL; + + if (argc < 6 || argc > 8) + error("link : Id Nomass1 Nomass2 K D1 D2 (Lmin Lmax)"); + + // check for existence of link masses: + for (i=0; i<nb_mass;i++) + if (mass[i]->nbr==GetInt(argv[1])) // pointer to mass1 + // we found mass1 + mass1 = mass[i]; + else if (mass[i]->nbr==GetInt(argv[2])) // pointer to mass2 + // ... and mass2 + mass2 = mass[i]; + + if (mass1 and mass2) + { + link[nb_link] = new t_link; // New pointer + link[nb_link]->Id = GetSymbol(argv[0]); // ID + link[nb_link]->mass1 = mass1; // pointer to mass1 + link[nb_link]->mass2 = mass2; // pointer to mass2 + link[nb_link]->K1 = GetFloat(argv[3]); // K1 + link[nb_link]->D1 = GetFloat(argv[4]); // D1 + link[nb_link]->D2 = GetFloat(argv[5]); // D2 + link[nb_link]->longx = link[nb_link]->mass1->posX - link[nb_link]->mass2->posX; // Lx[0] + if (link[nb_link]->longx < 0) + link[nb_link]->longueur = -link[nb_link]->longx; + else + link[nb_link]->longueur = link[nb_link]->longx ;// L[0] + link[nb_link]->nbr = id_link; // id number + link[nb_link]->distance_old = link[nb_link]->longueur; // L[n-1] + switch (argc) { + case 6 : + link[nb_link]->long_max = 32768; + link[nb_link]->long_min = 0; + break; + case 7 : + link[nb_link]->long_min = GetFloat(argv[6]); + link[nb_link]->long_max = 32768; + break; + case 8 : + link[nb_link]->long_min = GetFloat(argv[6]); + link[nb_link]->long_max = GetFloat(argv[7]); + break; + } + nb_link++; + id_link++; + nb_link = min ( nb_max_link -1, nb_link ); + SetFloat((sortie[0]),id_link-1); + SetSymbol((sortie[1]),link[nb_link-1]->Id); + SetFloat((sortie[2]),GetInt(argv[1])); + SetFloat((sortie[3]),GetInt(argv[2])); + SetFloat((sortie[4]),link[nb_link-1]->K1); + SetFloat((sortie[5]),link[nb_link-1]->D1); + SetFloat((sortie[6]),link[nb_link-1]->D2); + ToOutAnything(1,S_Link,7,sortie); + } + else + error("link : Cannot create link: Not all masses for this link have been created yet."); } void m_ilink(int argc,t_atom *argv) @@ -533,35 +549,39 @@ protected: { t_int i,j; t_symbol *auxarg,*auxarg2, *auxtype; - t_atom sortie[4]; + t_atom sortie[3]; auxtype = GetSymbol(argv[0]); auxarg = GetASymbol(argv[1]); //auxarg : & symbol, 0 else if (argc == 1) { if (auxtype == S_massesPos) // get all masses positions for (i=0; i<nb_mass; i++) - { - SetFloat(sortie[0],mass[i]->posX); - ToOutAnything(0,S_massesPos,1,sortie); + { + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->posX); + ToOutAnything(0,S_massesPos,2,sortie); } else if (auxtype == S_massesForces) // get all masses forces for (i=0; i<nb_mass; i++) { - SetFloat(sortie[0],mass[i]->out_forceX); - ToOutAnything(0,S_massesForces,1,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->out_forceX); + ToOutAnything(0,S_massesForces,2,sortie); } else if (auxtype == S_linksPos) // get all links positions for (i=0; i<nb_link; i++) { - SetFloat(sortie[0],link[i]->mass1->posX); - SetFloat(sortie[1],link[i]->mass2->posX); - ToOutAnything(0,S_linksPos,2,sortie); + SetFloat(sortie[0],link[i]->nbr); + SetFloat(sortie[1],link[i]->mass1->posX); + SetFloat(sortie[2],link[i]->mass2->posX); + ToOutAnything(0,S_linksPos,3,sortie); } else // get all masses speeds for (i=0; i<nb_mass; i++) { - SetFloat(sortie[0],mass[i]->speedX); - ToOutAnything(0,S_massesSpeeds,1,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->speedX); + ToOutAnything(0,S_massesSpeeds,2,sortie); } } else if (auxtype == S_massesPos) // get mass positions @@ -572,8 +592,9 @@ protected: for (i=0;i<nb_mass;i++) if (mass[i]->nbr==GetInt(argv[j])) { - SetFloat(sortie[0],mass[i]->posX); - ToOutAnything(0,S_massesPosNo,1,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->posX); + ToOutAnything(0,S_massesPosNo,2,sortie); } } else //symbol @@ -585,8 +606,9 @@ protected: { if (auxarg2==mass[i]->Id) { - SetFloat(sortie[0],mass[i]->posX); - ToOutAnything(0,S_massesPosId,1,sortie); + SetSymbol(sortie[0],mass[i]->Id); + SetFloat(sortie[1],mass[i]->posX); + ToOutAnything(0,S_massesPosId,2,sortie); } } } @@ -600,8 +622,9 @@ protected: for (i=0;i<nb_mass;i++) if (mass[i]->nbr==GetInt(argv[j])) { - SetFloat(sortie[0],mass[i]->out_forceX); - ToOutAnything(0,S_massesForcesNo,1,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->out_forceX); + ToOutAnything(0,S_massesForcesNo,2,sortie); } } else //string @@ -613,8 +636,9 @@ protected: { if (auxarg2==mass[i]->Id) { - SetFloat(sortie[0],mass[i]->out_forceX); - ToOutAnything(0,S_massesForcesId,1,sortie); + SetSymbol(sortie[0],mass[i]->Id); + SetFloat(sortie[1],mass[i]->out_forceX); + ToOutAnything(0,S_massesForcesId,2,sortie); } } } @@ -628,9 +652,10 @@ protected: for (i=0;i<nb_link;i++) if (link[i]->nbr==GetInt(argv[j])) { - SetFloat(sortie[0],link[i]->mass1->posX); - SetFloat(sortie[1],link[i]->mass2->posX); - ToOutAnything(0,S_linksPosNo,2,sortie); + SetFloat(sortie[0],link[i]->nbr); + SetFloat(sortie[1],link[i]->mass1->posX); + SetFloat(sortie[2],link[i]->mass2->posX); + ToOutAnything(0,S_linksPosNo,3,sortie); } } else //symbol @@ -642,9 +667,10 @@ protected: { if (auxarg2==link[i]->Id) { - SetFloat(sortie[0],link[i]->mass1->posX); - SetFloat(sortie[1],link[i]->mass2->posX); - ToOutAnything(0,S_linksPosId,2,sortie); + SetSymbol(sortie[0],link[i]->Id); + SetFloat(sortie[1],link[i]->mass1->posX); + SetFloat(sortie[2],link[i]->mass2->posX); + ToOutAnything(0,S_linksPosId,3,sortie); } } } @@ -658,8 +684,9 @@ protected: for (i=0;i<nb_mass;i++) if (mass[i]->nbr==GetInt(argv[j])) { - SetFloat(sortie[0],mass[i]->speedX); - ToOutAnything(0,S_massesSpeedsNo,1,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->speedX); + ToOutAnything(0,S_massesSpeedsNo,2,sortie); } } else //symbol @@ -671,8 +698,9 @@ protected: { if (auxarg2==mass[i]->Id) { - SetFloat(sortie[0],mass[i]->speedX); - ToOutAnything(0,S_massesSpeedsId,1,sortie); + SetSymbol(sortie[0],mass[i]->Id); + SetFloat(sortie[1],mass[i]->speedX); + ToOutAnything(0,S_massesSpeedsId,2,sortie); } } } |