aboutsummaryrefslogtreecommitdiff
path: root/msd3D/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'msd3D/main.cpp')
-rwxr-xr-xmsd3D/main.cpp257
1 files changed, 173 insertions, 84 deletions
diff --git a/msd3D/main.cpp b/msd3D/main.cpp
index 428a86b..9d0c884 100755
--- a/msd3D/main.cpp
+++ b/msd3D/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.02 -- 15.04.2005
+ Version 0.03 -- 21.04.2005
*/
// include flext header
@@ -38,7 +38,7 @@
#include <math.h>
// define constants
-#define MSD3D_VERSION 0.02
+#define MSD3D_VERSION 0.03
#define nb_max_link 4000
#define nb_max_mass 4000
#define Id_length 20
@@ -79,7 +79,7 @@ typedef struct _link {
t_mass *mass1;
t_mass *mass2;
t_float K1, D1, D2;
- t_float longx, longy, longz, longueur;
+ t_float longx, longy, longz, longueur, long_min, long_max;
t_float distance_old;
} t_link;
@@ -137,12 +137,19 @@ protected:
// compute link forces
distance = sqrt(pow(link[i]->mass1->posX-link[i]->mass2->posX,2) + pow(link[i]->mass1->posY
-link[i]->mass2->posY,2) + pow(link[i]->mass1->posZ-link[i]->mass2->posZ,2)); // L[n]
- F = link[i]->K1 * (distance - link[i]->longueur) ; // F = K1(L[n] - L[0])
- F += link[i]->D1 * (distance - link[i]->distance_old) ; // F = F + D1(L[n] - L[n-1])
- if (distance != 0) {
- Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance; // Fx[n] = F * Lx[n]/L[n]
- Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance; // Fy[n] = F * Ly[n]/L[n]
- Fz = F * (link[i]->mass1->posZ - link[i]->mass2->posZ)/distance; // Fy[n] = F * Lz[n]/L[n]
+ if (distance < link[i]->long_min || distance > link[i]->long_max) {
+ Fx = 0;
+ Fy = 0;
+ Fz = 0;
+ }
+ else {
+ F = link[i]->K1 * (distance - link[i]->longueur) ; // F = K1(L[n] - L[0])
+ F += link[i]->D1 * (distance - link[i]->distance_old) ; // F = F + D1(L[n] - L[n-1])
+ if (distance != 0) {
+ Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance; // Fx[n] = F * Lx[n]/L[n]
+ Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance; // Fy[n] = F * Ly[n]/L[n]
+ Fz = F * (link[i]->mass1->posZ - link[i]->mass2->posZ)/distance; // Fy[n] = F * Lz[n]/L[n]
+ }
}
link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx
link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
@@ -196,6 +203,9 @@ protected:
t_atom sortie[7], aux[2];
t_float M;
+ if (argc != 6)
+ error("mass : Id mobile mass X Y Z");
+
mass[nb_mass] = new t_mass; // new mass
mass[nb_mass]->Id = GetSymbol(argv[0]); // Id
mass[nb_mass]->mobile = GetInt(argv[1]); // mobile
@@ -235,6 +245,9 @@ protected:
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ if (argc != 2)
+ error("forceX : Idmass value");
+
for (i=0; i<nb_mass;i++)
{
if (sym == mass[i]->Id)
@@ -248,6 +261,9 @@ protected:
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ if (argc != 2)
+ error("forceY : Idmass value");
+
for (i=0; i<nb_mass;i++)
{
if (sym == mass[i]->Id)
@@ -261,6 +277,9 @@ protected:
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ if (argc != 2)
+ error("forceZ : Idmass value");
+
for (i=0; i<nb_mass;i++)
{
if (sym == mass[i]->Id)
@@ -274,11 +293,14 @@ protected:
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ if (argc != 2)
+ error("posX : Idmass value");
+
if (GetFloat(argv[1]) < Xmax && GetFloat(argv[1]) > Xmin)
for (i=0; i<nb_mass;i++)
{
if (sym == mass[i]->Id)
- mass[i]->posX = GetFloat(argv[1]);
+ mass[i]->posX = GetAFloat(argv[1]);
}
}
@@ -288,6 +310,9 @@ protected:
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ if (argc != 2)
+ error("posY : Idmass value");
+
if (GetFloat(argv[1]) < Ymax && GetFloat(argv[1]) > Ymin)
for (i=0; i<nb_mass;i++)
{
@@ -303,6 +328,9 @@ protected:
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ if (argc != 2)
+ error("posZ : Idmass value");
+
if (GetFloat(argv[1]) < Zmax && GetFloat(argv[1]) > Zmin)
for (i=0; i<nb_mass;i++)
{
@@ -316,6 +344,9 @@ protected:
{
// set mass No to mobile
t_int i,aux;
+
+ if (argc != 1)
+ error("setMobile : Idmass");
aux = GetInt(argv[0]);
for (i=0; i<nb_mass;i++)
@@ -331,7 +362,10 @@ protected:
// set mass No to fixed
t_int i,aux;
- aux = GetInt(argv[0]);
+ if (argc != 1)
+ error("setFixed : Idmass");
+
+ aux = GetAInt(argv[0]);
for (i=0; i<nb_mass;i++)
{
if (mass[i]->nbr == aux)
@@ -343,100 +377,131 @@ protected:
void m_delete_mass(int argc,t_atom *argv)
{
// Delete mass
- t_int i,nb_link_delete=0;
- t_atom sortie[7], aux[nb_link];
+ t_int i,nb_link_delete=0;
+ t_atom sortie[7], aux[nb_link];
+
+ if (argc != 1)
+ error("deleteMass : Nomass");
- // Delete associated links
- for (i=0; i<nb_link;i++) {
- if (link[i]->mass1->nbr == GetInt(argv[0]) || link[i]->mass2->nbr == GetInt(argv[0])) {
- SetFloat((aux[nb_link_delete]),link[i]->nbr);
- nb_link_delete++;
+ // Delete associated links
+ for (i=0; i<nb_link;i++) {
+ if (link[i]->mass1->nbr == GetInt(argv[0]) || link[i]->mass2->nbr == GetInt(argv[0])) {
+ SetFloat((aux[nb_link_delete]),link[i]->nbr);
+ nb_link_delete++;
+ }
}
- }
- for (i=0; i<nb_link_delete;i++)
- m_delete_link(1,&aux[i]);
+ for (i=0; i<nb_link_delete;i++)
+ m_delete_link(1,&aux[i]);
- // Delete mass
- for (i=0; i<nb_mass;i++)
- if (mass[i]->nbr == GetInt(argv[0])) {
- SetFloat((sortie[0]),mass[i]->nbr);
- SetSymbol((sortie[1]),mass[i]->Id);
- SetFloat((sortie[2]),mass[i]->mobile);
- SetFloat((sortie[3]),1/mass[i]->invM);
- SetFloat((sortie[4]),mass[i]->posX);
- SetFloat((sortie[5]),mass[i]->posY);
- SetFloat((sortie[6]),mass[i]->posZ);
- delete mass[i];
- mass[i] = mass[nb_mass-1]; // copy last mass indeed
- nb_mass--;
- ToOutAnything(1,S_Mass_deleted,7,sortie);
- break;
- }
+ // Delete mass
+ for (i=0; i<nb_mass;i++)
+ if (mass[i]->nbr == GetInt(argv[0])) {
+ SetFloat((sortie[0]),mass[i]->nbr);
+ SetSymbol((sortie[1]),mass[i]->Id);
+ SetFloat((sortie[2]),mass[i]->mobile);
+ SetFloat((sortie[3]),1/mass[i]->invM);
+ SetFloat((sortie[4]),mass[i]->posX);
+ SetFloat((sortie[5]),mass[i]->posY);
+ SetFloat((sortie[6]),mass[i]->posZ);
+ delete mass[i];
+ mass[i] = mass[nb_mass-1]; // copy last mass indeed
+ nb_mass--;
+ ToOutAnything(1,S_Mass_deleted,7,sortie);
+ break;
+ }
}
void m_Xmax(int argc,t_atom *argv)
{
- // set maximum X of all masses
- Xmax = GetFloat(argv[0]);
+ // set X max
+ if (argc != 1)
+ error("Xmax : Value");
+ Xmax = GetFloat(argv[0]);
}
- void m_Ymax(int argc,t_atom *argv)
+ void m_Xmin(int argc,t_atom *argv)
{
- // set maximum Y of all masses
- Ymax = GetFloat(argv[0]);
+ // set X min
+ if (argc != 1)
+ error("Xmin : Value");
+ Xmin = GetFloat(argv[0]);
}
-
- void m_Zmax(int argc,t_atom *argv)
+ void m_Ymax(int argc,t_atom *argv)
{
- // set maximum Z of all masses
- Zmax = GetFloat(argv[0]);
+ // set Y max
+ if (argc != 1)
+ error("Ymax : Value");
+ Ymax = GetFloat(argv[0]);
}
- void m_Xmin(int argc,t_atom *argv)
+ void m_Ymin(int argc,t_atom *argv)
{
- // set minimum X of all masses
- Xmin = GetFloat(argv[0]);
+ // set Y min
+ if (argc != 1)
+ error("Ymin : Value");
+ Ymin = GetFloat(argv[0]);
}
- void m_Ymin(int argc,t_atom *argv)
+ void m_Zmax(int argc,t_atom *argv)
{
- // set minimum Y of all masses
- Ymin = GetFloat(argv[0]);
+ // set maximum Z of all masses
+ if (argc != 1)
+ error("Zmax : Value");
+ Zmax = GetFloat(argv[0]);
}
void m_Zmin(int argc,t_atom *argv)
{
// set minimum Z of all masses
- Zmin = GetFloat(argv[0]);
+ if (argc != 1)
+ error("Zmin : Value");
+ Zmin = GetFloat(argv[0]);
}
// -------------------------------------------------------------- LINKS
// ---------------------------------------------------------------------
void m_link(int argc,t_atom *argv)
// add a link
- // Id, nbr, *mass1, *mass2, K1, D1
+ // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax)
{
t_atom sortie[7], aux[2];
t_int i;
- link[nb_link] = new t_link; // new link
+ 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==GetInt(argv[1])) // pointer on mass 1
+ if (mass[i]->nbr==GetAInt(argv[1])) // pointer to mass1
link[nb_link]->mass1 = mass[i];
- else if(mass[i]->nbr==GetInt(argv[2])) // pointer on mass 2
+ 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]->longz = link[nb_link]->mass1->posZ - link[nb_link]->mass2->posZ; // Lz[0]
- link[nb_link]->longueur = sqrt( pow(link[nb_link]->longx,2) + pow(link[nb_link]->longy,2) + pow(link[nb_link]->longz,2));
+ 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;
+ 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 );
@@ -447,22 +512,24 @@ protected:
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);
+ ToOutAnything(1,S_Link,7,sortie);
}
void m_ilink(int argc,t_atom *argv)
// add interactor link
- // Id, nbr, Id masses1, Id masses2, K1, D1
+ // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax)
{
- t_atom aux[2], arglist[6];
+ t_atom aux[2], arglist[8];
t_int i,j, imass1[nb_mass], nbmass1=0, imass2[nb_mass], nbmass2=0;
t_symbol *Id1, *Id2;
+ if (argc < 6 || argc > 8)
+ error("ilink : Id Idmass1 Idmass2 K D1 D2 (Lmin Lmax)");
+
Id1 = GetSymbol(argv[1]);
Id2 = GetSymbol(argv[2]);
ToOutAnything(1,S_iLink,0,aux);
-
for (i=0;i<nb_mass;i++) {
if (Id1 == mass[i]->Id) {
imass1[nbmass1]=i;
@@ -483,7 +550,16 @@ protected:
SetFloat((arglist[3]),GetFloat(argv[3]));
SetFloat((arglist[4]),GetFloat(argv[4]));
SetFloat((arglist[5]),GetFloat(argv[5]));
- m_link(6,arglist);
+ switch (argc) {
+ case 7 :
+ SetFloat(arglist[6],GetFloat(argv[6]));
+ break;
+ case 8 :
+ SetFloat(arglist[6],GetFloat(argv[6]));
+ SetFloat(arglist[7],GetFloat(argv[7]));
+ break;
+ }
+ m_link(argc,arglist);
}
}
@@ -493,6 +569,9 @@ protected:
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ if (argc != 2)
+ error("setK : IdLink Value");
+
for (i=0; i<nb_link;i++)
{
if (sym == link[i]->Id)
@@ -502,10 +581,13 @@ protected:
void m_setD(int argc,t_atom *argv)
{
- // set viscosity of link(s) named Id
+ // set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ if (argc != 2)
+ error("setD : IdLink Value");
+
for (i=0; i<nb_link;i++)
{
if (sym == link[i]->Id)
@@ -519,6 +601,9 @@ protected:
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ if (argc != 2)
+ error("setD2 : IdLink Value");
+
for (i=0; i<nb_link;i++)
{
if (sym == link[i]->Id)
@@ -529,26 +614,30 @@ protected:
void m_delete_link(int argc,t_atom *argv)
{
// Delete link
- t_int i;
- t_atom sortie[7];
+ t_int i;
+ t_atom sortie[7];
- for (i=0; i<nb_link;i++)
- if (link[i]->nbr == GetInt(argv[0])) {
- SetFloat((sortie[0]),link[i]->nbr);
- SetSymbol((sortie[1]),link[i]->Id);
- SetFloat((sortie[2]),link[i]->mass1->nbr);
- SetFloat((sortie[3]),link[i]->mass2->nbr);
- SetFloat((sortie[4]),link[i]->K1);
- SetFloat((sortie[5]),link[i]->D1);
- SetFloat((sortie[6]),link[i]->D2);
- delete link[i];
- link[i]=link[nb_link-1]; // copy last link
- nb_link--;
- ToOutAnything(1,S_Link_deleted,7,sortie);
- break;
+ if (argc != 1)
+ error("deleteLink : NoLink");
+
+ for (i=0; i<nb_link;i++)
+ if (link[i]->nbr == GetInt(argv[0])) {
+ SetFloat((sortie[0]),link[i]->nbr);
+ SetSymbol((sortie[1]),link[i]->Id);
+ SetFloat((sortie[2]),link[i]->mass1->nbr);
+ SetFloat((sortie[3]),link[i]->mass2->nbr);
+ SetFloat((sortie[4]),link[i]->K1);
+ SetFloat((sortie[5]),link[i]->D1);
+ SetFloat((sortie[6]),link[i]->D2);
+ delete link[i];
+ link[i]=link[nb_link-1]; // copy last link instead
+ nb_link--;
+ ToOutAnything(1,S_Link_deleted,7,sortie);
+ break;
}
}
+
// -------------------------------------------------------------- GET
// -------------------------------------------------------------------
void m_get(int argc,t_atom *argv)