From 2d390319a45282ffa6fcc5da41bbac81eb26fb3c Mon Sep 17 00:00:00 2001 From: "N.N." Date: Tue, 26 Apr 2005 16:10:08 +0000 Subject: MSD Version 0.04 svn path=/trunk/externals/nusmuk/; revision=2826 --- msd2D/main.cpp | 249 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 146 insertions(+), 103 deletions(-) (limited to 'msd2D/main.cpp') diff --git a/msd2D/main.cpp b/msd2D/main.cpp index 4ab0dff..ccefdc6 100755 --- a/msd2D/main.cpp +++ b/msd2D/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 // define constants -#define MSD2D_VERSION 0.03 +#define MSD2D_VERSION 0.04 #define nb_max_link 4000 #define nb_max_mass 4000 #define Id_length 20 @@ -265,35 +265,52 @@ protected: { // displace mass(es) named Id to a certain position t_int i; - const t_symbol *sym = GetSymbol(argv[0]); + const t_symbol *sym = GetASymbol(argv[0]); if (argc != 2) - error("posX : Idmass value"); + error("posX : Id/Nomass value"); if (GetFloat(argv[1]) < Xmax && GetFloat(argv[1]) > Xmin) - for (i=0; iId) - mass[i]->posX = GetAFloat(argv[1]); - } + if (sym ==0) + for (i=0; inbr) { + mass[i]->posX = GetFloat(argv[1]); + break; + } + } + else + for (i=0; iId) + mass[i]->posX = GetFloat(argv[1]); + } } void m_posY(int argc,t_atom *argv) { // displace mass(es) named Id to a certain position t_int i; - const t_symbol *sym = GetSymbol(argv[0]); + const t_symbol *sym = GetASymbol(argv[0]); if (argc != 2) - error("posY : Idmass value"); + error("posY : Id/Nomass value"); if (GetFloat(argv[1]) < Ymax && GetFloat(argv[1]) > Ymin) - for (i=0; iId) - mass[i]->posY = GetFloat(argv[1]); - } - + if (sym ==0) + for (i=0; inbr) { + mass[i]->posY = GetFloat(argv[1]); + break; + } + } + else + for (i=0; iId) + mass[i]->posY = GetFloat(argv[1]); + } } void m_set_mobile(int argc,t_atom *argv) @@ -410,49 +427,63 @@ 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; inbr==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] - link[nb_link]->longy = link[nb_link]->mass1->posY - link[nb_link]->mass2->posY; // Ly[0] - link[nb_link]->longueur = sqrt(pow(link[nb_link]->longx,2)+pow(link[nb_link]->longy,2)); // 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; inbr==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] + link[nb_link]->longy = link[nb_link]->mass1->posY - link[nb_link]->mass2->posY; // Ly[0] + link[nb_link]->longueur = sqrt(pow(link[nb_link]->longx,2)+pow(link[nb_link]->longy,2)); // 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) @@ -589,7 +620,7 @@ protected: { t_int i,j; t_symbol *auxarg,*auxarg2, *auxtype; - t_atom sortie[4]; + t_atom sortie[5]; auxtype = GetSymbol(argv[0]); auxarg = GetASymbol(argv[1]); //auxarg : & symbol, 0 else @@ -598,32 +629,36 @@ protected: if (auxtype == S_massesPos) // get all masses positions for (i=0; iposX); - SetFloat(sortie[1],mass[i]->posY); - ToOutAnything(0,S_massesPos,2,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->posX); + SetFloat(sortie[2],mass[i]->posY); + ToOutAnything(0,S_massesPos,3,sortie); } else if (auxtype == S_massesForces) // get all masses forces for (i=0; iout_forceX); - SetFloat(sortie[1],mass[i]->out_forceY); - ToOutAnything(0,S_massesForces,2,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->out_forceX); + SetFloat(sortie[2],mass[i]->out_forceY); + ToOutAnything(0,S_massesForces,3,sortie); } else if (auxtype == S_linksPos) // get all links positions for (i=0; imass1->posX); - SetFloat(sortie[1],link[i]->mass1->posY); - SetFloat(sortie[2],link[i]->mass2->posX); - SetFloat(sortie[3],link[i]->mass2->posY); - ToOutAnything(0,S_linksPos,4,sortie); + SetFloat(sortie[0],link[i]->nbr); + SetFloat(sortie[1],link[i]->mass1->posX); + SetFloat(sortie[2],link[i]->mass1->posY); + SetFloat(sortie[3],link[i]->mass2->posX); + SetFloat(sortie[4],link[i]->mass2->posY); + ToOutAnything(0,S_linksPos,5,sortie); } else // get all masses speeds for (i=0; ispeedX); - SetFloat(sortie[1],mass[i]->speedY); - ToOutAnything(0,S_massesSpeeds,2,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->speedX); + SetFloat(sortie[2],mass[i]->speedY); + ToOutAnything(0,S_massesSpeeds,3,sortie); } } else if (auxtype == S_massesPos) // get mass positions @@ -634,9 +669,10 @@ protected: for (i=0;inbr==GetInt(argv[j])) { - SetFloat(sortie[0],mass[i]->posX); - SetFloat(sortie[1],mass[i]->posY); - ToOutAnything(0,S_massesPosNo,2,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->posX); + SetFloat(sortie[2],mass[i]->posY); + ToOutAnything(0,S_massesPosNo,3,sortie); } } else //symbol @@ -648,9 +684,10 @@ protected: { if (auxarg2==mass[i]->Id) { - SetFloat(sortie[0],mass[i]->posX); - SetFloat(sortie[1],mass[i]->posY); - ToOutAnything(0,S_massesPosId,2,sortie); + SetSymbol(sortie[0],mass[i]->Id); + SetFloat(sortie[1],mass[i]->posX); + SetFloat(sortie[2],mass[i]->posY); + ToOutAnything(0,S_massesPosId,3,sortie); } } } @@ -664,9 +701,10 @@ protected: for (i=0;inbr==GetInt(argv[j])) { - SetFloat(sortie[0],mass[i]->out_forceX); - SetFloat(sortie[1],mass[i]->out_forceY); - ToOutAnything(0,S_massesForcesNo,2,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->out_forceX); + SetFloat(sortie[2],mass[i]->out_forceY); + ToOutAnything(0,S_massesForcesNo,3,sortie); } } else //symbol @@ -678,9 +716,10 @@ protected: { if (auxarg2==mass[i]->Id) { - SetFloat(sortie[0],mass[i]->out_forceX); - SetFloat(sortie[1],mass[i]->out_forceY); - ToOutAnything(0,S_massesForcesId,2,sortie); + SetSymbol(sortie[0],mass[i]->Id); + SetFloat(sortie[1],mass[i]->out_forceX); + SetFloat(sortie[2],mass[i]->out_forceY); + ToOutAnything(0,S_massesForcesId,3,sortie); } } } @@ -694,11 +733,12 @@ protected: for (i=0;inbr==GetInt(argv[j])) { - SetFloat(sortie[0],link[i]->mass1->posX); - SetFloat(sortie[1],link[i]->mass1->posY); - SetFloat(sortie[2],link[i]->mass2->posX); - SetFloat(sortie[3],link[i]->mass2->posY); - ToOutAnything(0,S_linksPosNo,4,sortie); + SetFloat(sortie[0],link[i]->nbr); + SetFloat(sortie[1],link[i]->mass1->posX); + SetFloat(sortie[2],link[i]->mass1->posY); + SetFloat(sortie[3],link[i]->mass2->posX); + SetFloat(sortie[4],link[i]->mass2->posY); + ToOutAnything(0,S_linksPosNo,5,sortie); } } else //symbol @@ -710,11 +750,12 @@ protected: { if (auxarg2==link[i]->Id) { - SetFloat(sortie[0],link[i]->mass1->posX); - SetFloat(sortie[1],link[i]->mass1->posY); - SetFloat(sortie[2],link[i]->mass2->posX); - SetFloat(sortie[3],link[i]->mass2->posY); - ToOutAnything(0,S_linksPosId,4,sortie); + SetSymbol(sortie[0],link[i]->Id); + SetFloat(sortie[1],link[i]->mass1->posX); + SetFloat(sortie[2],link[i]->mass1->posY); + SetFloat(sortie[3],link[i]->mass2->posX); + SetFloat(sortie[4],link[i]->mass2->posY); + ToOutAnything(0,S_linksPosId,5,sortie); } } } @@ -728,9 +769,10 @@ protected: for (i=0;inbr==GetInt(argv[j])) { - SetFloat(sortie[0],mass[i]->speedX); - SetFloat(sortie[1],mass[i]->speedY); - ToOutAnything(0,S_massesSpeedsNo,2,sortie); + SetFloat(sortie[0],mass[i]->nbr); + SetFloat(sortie[1],mass[i]->speedX); + SetFloat(sortie[2],mass[i]->speedY); + ToOutAnything(0,S_massesSpeedsNo,3,sortie); } } else //symbol @@ -742,9 +784,10 @@ protected: { if (auxarg2==mass[i]->Id) { - SetFloat(sortie[0],mass[i]->speedX); - SetFloat(sortie[1],mass[i]->speedY); - ToOutAnything(0,S_massesSpeedsId,2,sortie); + SetSymbol(sortie[0],mass[i]->Id); + SetFloat(sortie[1],mass[i]->speedX); + SetFloat(sortie[2],mass[i]->speedY); + ToOutAnything(0,S_massesSpeedsId,3,sortie); } } } -- cgit v1.2.1