aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Grill <xovo@users.sourceforge.net>2005-04-26 11:39:49 +0000
committerThomas Grill <xovo@users.sourceforge.net>2005-04-26 11:39:49 +0000
commit3d7f8e6f9f4c708c6130ea0a63c2eb139f34327a (patch)
tree3feaf8b197c932b421dffce6cc5d24a8c41695df
parent8ea100baa14f1f3f663b7a72a79f67aff2609a09 (diff)
some small changes for Windows compilation
svn path=/trunk/externals/nusmuk/; revision=2825
-rwxr-xr-xmsd/main.cpp147
-rwxr-xr-xmsd2D/main.cpp167
-rwxr-xr-xmsd3D/main.cpp190
3 files changed, 278 insertions, 226 deletions
diff --git a/msd/main.cpp b/msd/main.cpp
index 2e4e5c2..69dfbd5 100755
--- a/msd/main.cpp
+++ b/msd/main.cpp
@@ -39,8 +39,8 @@
// define constants
#define MSD_VERSION 0.03
-#define nb_max_link 4000
-#define nb_max_mass 4000
+#define nb_max_link 4000
+#define nb_max_mass 4000
#define Id_length 20
// check for appropriate flext version
@@ -48,33 +48,40 @@
#error You need at least flext version 0.4.1
#endif
-#define max(a,b) ( ((a) > (b)) ? (a) : (b) )
+#define max(a,b) ( ((a) > (b)) ? (a) : (b) )
#define min(a,b) ( ((a) < (b)) ? (a) : (b) )
-typedef struct _mass {
+#ifdef _MSC_VER
+#define NEWARR(type,var,size) type *var = new type[size]
+#define DELARR(var) delete[] var
+#else
+#define NEWARR(type,var,size) type var[size]
+#define DELARR(var) ((void)0)
+#endif
+
+typedef struct _mass {
t_symbol *Id;
t_int nbr;
- t_int mobile;
- t_float invM;
- t_float speedX;
+ t_int mobile;
+ t_float invM;
+ t_float speedX;
t_float posX;
- t_float posX2;
+ t_float posX2;
t_float forceX;
t_float out_forceX;
-} t_mass;
-
-typedef struct _link {
+} t_mass;
+
+typedef struct _link {
t_symbol *Id;
- t_int nbr;
- t_mass *mass1;
- t_mass *mass2;
+ t_int nbr;
+ t_mass *mass1;
+ t_mass *mass2;
t_float K1, D1, D2;
t_float longx, longueur, long_min, long_max;
t_float distance_old;
} t_link;
-
class msd:
public flext_base
{
@@ -105,7 +112,7 @@ protected:
void m_reset()
{
t_int i;
- t_atom sortie[0];
+// t_atom sortie;
for (i=0; i<nb_mass; i++) {
delete mass[i];
@@ -113,8 +120,8 @@ protected:
for (i=0; i<nb_link; i++) {
delete link[i];
}
- ToOutAnything(1,S_Reset,0,sortie);
- nb_link = 0;
+ ToOutAnything(1,S_Reset,0,NULL);
+ nb_link = 0;
nb_mass = 0;
id_mass = 0;
id_link = 0;
@@ -125,11 +132,11 @@ protected:
void m_bang()
{
- t_float F=0,Fx=0,distance,vitesse, X_new;
+ t_float F=0,Fx=0,distance,vitesse, X_new;
t_int i;
- struct _mass mass_1, mass_2;
+ struct _mass mass_1, mass_2;
- for (i=0; i<nb_link; i++) {
+ for (i=0; i<nb_link; i++) {
// compute link forces
distance = link[i]->mass1->posX-link[i]->mass2->posX; // L[n] = x1 - x2
if (distance < 0)
@@ -141,37 +148,37 @@ protected:
F += link[i]->D1 * (distance - link[i]->distance_old) ; // F[n] = F[n] + D1 (L[n] - L[n-1])
if (distance != 0)
Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance; // Fx = F * Lx[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]
+ link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
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) {
+
+ for (i=0; i<nb_mass; i++)
+ // compute new masses position only if mobile = 1
+ if (mass[i]->mobile == 1) {
X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1]
mass[i]->posX = max(min(X_new,Xmax),Xmin); // x[n-1] = x[n]
mass[i]->speedX = mass[i]->posX - mass[i]->posX2; // vx[n] = x[n] - x[n-1]
}
- for (i=0; i<nb_mass; i++) {
+ for (i=0; i<nb_mass; i++) {
// clear forces
- mass[i]->out_forceX = mass[i]->forceX;
+ mass[i]->out_forceX = mass[i]->forceX;
mass[i]->forceX = 0; // Fx[n] = 0
- }
+ }
}
// -------------------------------------------------------------- MASSES
// ----------------------------------------------------------------------
- void m_mass(int argc,t_atom *argv)
- // add a mass
- // Id, nbr, mobile, invM, speedX, posX, forceX
+ void m_mass(int argc,t_atom *argv)
+ // add a mass
+ // Id, nbr, mobile, invM, speedX, posX, forceX
{
t_atom sortie[5], aux[2];
t_float M;
@@ -179,20 +186,20 @@ protected:
if (argc != 4)
error("mass : Id mobile mass X");
- mass[nb_mass] = new t_mass; // new mass
+ mass[nb_mass] = new t_mass; // new mass
mass[nb_mass]->Id = GetSymbol(argv[0]); // ID
mass[nb_mass]->mobile = GetInt(argv[1]); // mobile
if (GetFloat(argv[2])==0)
M=1;
else M = GetFloat(argv[2]);
mass[nb_mass]->invM = 1/(M); // 1/M
- mass[nb_mass]->speedX = 0; // vx[n]
+ mass[nb_mass]->speedX = 0; // vx[n]
mass[nb_mass]->posX = GetFloat(argv[3]); // x[n]
- mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1]
+ 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++ ;
- id_mass++;
+ id_mass++;
nb_mass = min ( nb_max_mass -1, nb_mass );
SetFloat((sortie[0]),id_mass-1);
SetSymbol((sortie[1]),GetSymbol(argv[0]));
@@ -202,8 +209,8 @@ protected:
ToOutAnything(1,S_Mass,5,sortie);
}
- void m_forceX(int argc,t_atom *argv)
- {
+ void m_forceX(int argc,t_atom *argv)
+ {
// add a force to mass(es) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -219,8 +226,8 @@ protected:
}
void m_posX(int argc,t_atom *argv)
- {
- // displace mass(es) named Id to a certain position
+ {
+ // displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetASymbol(argv[0]);
@@ -245,8 +252,8 @@ protected:
}
void m_set_mobile(int argc,t_atom *argv)
- {
- // set mass No to mobile
+ {
+ // set mass No to mobile
t_int i,aux;
if (argc != 1)
@@ -262,8 +269,8 @@ protected:
}
void m_set_fixe(int argc,t_atom *argv)
- {
- // set mass No to fixed
+ {
+ // set mass No to fixed
t_int i,aux;
if (argc != 1)
@@ -282,7 +289,8 @@ protected:
{
// Delete mass
t_int i,nb_link_delete=0;
- t_atom sortie[5], aux[nb_link];
+ t_atom sortie[5];
+ NEWARR(t_atom,aux,nb_link);
if (argc != 1)
error("deleteMass : Nomass");
@@ -312,11 +320,13 @@ protected:
ToOutAnything(1,S_Mass_deleted,5,sortie);
break;
}
+
+ DELARR(aux);
}
void m_Xmax(int argc,t_atom *argv)
- {
+ {
// set X max
if (argc != 1)
error("Xmax : Value");
@@ -324,7 +334,7 @@ protected:
}
void m_Xmin(int argc,t_atom *argv)
- {
+ {
// set X min
if (argc != 1)
error("Xmin : Value");
@@ -335,9 +345,9 @@ protected:
// ---------------------------------------------------------------------
void m_link(int argc,t_atom *argv)
- // add a link
- // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax)
- {
+ // add a link
+ // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax)
+ {
t_atom sortie[7], aux[2];
t_int i;
@@ -350,7 +360,7 @@ protected:
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]->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]
@@ -375,7 +385,7 @@ protected:
break;
}
nb_link++;
- id_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);
@@ -384,15 +394,17 @@ 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, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax)
- {
+ // add interactor link
+ // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax)
+ {
t_atom aux[2], arglist[8];
- t_int i,j, imass1[nb_mass], nbmass1=0, imass2[nb_mass], nbmass2=0;
+ t_int i,j,nbmass1=0,nbmass2=0;
+ NEWARR(t_int,imass1,nb_mass);
+ NEWARR(t_int,imass2,nb_mass);
t_symbol *Id1, *Id2;
if (argc < 6 || argc > 8)
@@ -433,10 +445,13 @@ protected:
}
m_link(argc,arglist);
}
+
+ DELARR(imass1);
+ DELARR(imass2);
}
void m_setK(int argc,t_atom *argv)
- {
+ {
// set rigidity of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -452,7 +467,7 @@ protected:
}
void m_setD(int argc,t_atom *argv)
- {
+ {
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -468,7 +483,7 @@ protected:
}
void m_setD2(int argc,t_atom *argv)
- {
+ {
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -656,7 +671,7 @@ protected:
{
if (auxarg2==mass[i]->Id)
{
- SETFLOAT(&sortie[0],mass[i]->speedX);
+ SetFloat(sortie[0],mass[i]->speedX);
ToOutAnything(0,S_massesSpeedsId,1,sortie);
}
}
@@ -670,25 +685,27 @@ protected:
void m_mass_dumpl()
// List of masses positions on first outlet
{
- t_atom sortie[nb_mass];
+ NEWARR(t_atom,sortie,nb_mass);
t_int i;
for (i=0; i<nb_mass; i++) {
SetFloat((sortie[i]),mass[i]->posX);
}
ToOutAnything(0, S_massesPosL, nb_mass, sortie);
+ DELARR(sortie);
}
void m_force_dumpl()
// List of masses forces on first outlet
{
- t_atom sortie[nb_mass];
+ NEWARR(t_atom,sortie,nb_mass);
t_int i;
for (i=0; i<nb_mass; i++) {
SetFloat((sortie[i]),mass[i]->out_forceX);
}
ToOutAnything(0, S_massesForcesL, nb_mass, sortie);
+ DELARR(sortie);
}
void m_info_dumpl()
@@ -723,7 +740,7 @@ protected:
// -------------------------------------------------------------- PROTECTED VARIABLES
// -----------------------------------------------------------------------------------
- t_link * link[nb_max_link]; // Pointer table on links
+ t_link * link[nb_max_link]; // Pointer table on links
t_mass * mass[nb_max_mass]; // Pointer table on masses
t_float Xmin, Xmax; // Limit values
int nb_link, nb_mass, id_mass, id_link;
diff --git a/msd2D/main.cpp b/msd2D/main.cpp
index 37a7510..4ab0dff 100755
--- a/msd2D/main.cpp
+++ b/msd2D/main.cpp
@@ -39,8 +39,8 @@
// define constants
#define MSD2D_VERSION 0.03
-#define nb_max_link 4000
-#define nb_max_mass 4000
+#define nb_max_link 4000
+#define nb_max_mass 4000
#define Id_length 20
// check for appropriate flext version
@@ -48,31 +48,40 @@
#error You need at least flext version 0.4.1
#endif
-#define max(a,b) ( ((a) > (b)) ? (a) : (b) )
+#define max(a,b) ( ((a) > (b)) ? (a) : (b) )
#define min(a,b) ( ((a) < (b)) ? (a) : (b) )
-typedef struct _mass {
+#ifdef _MSC_VER
+#define NEWARR(type,var,size) type *var = new type[size]
+#define DELARR(var) delete[] var
+#else
+#define NEWARR(type,var,size) type var[size]
+#define DELARR(var) ((void)0)
+#endif
+
+
+typedef struct _mass {
t_symbol *Id;
t_int nbr;
- t_int mobile;
- t_float invM;
- t_float speedX;
+ t_int mobile;
+ t_float invM;
+ t_float speedX;
t_float posX;
- t_float posX2;
+ t_float posX2;
t_float forceX;
t_float out_forceX;
- t_float speedY;
+ t_float speedY;
t_float posY;
- t_float posY2;
+ t_float posY2;
t_float forceY;
t_float out_forceY;
-} t_mass;
-
-typedef struct _link {
+} t_mass;
+
+typedef struct _link {
t_symbol *Id;
- t_int nbr;
- t_mass *mass1;
- t_mass *mass2;
+ t_int nbr;
+ t_mass *mass1;
+ t_mass *mass2;
t_float K1, D1, D2;
t_float longx, longy, longueur, long_min, long_max;
t_float distance_old;
@@ -106,7 +115,7 @@ protected:
void m_reset()
{
t_int i;
- t_atom sortie[0];
+// t_atom sortie;
for (i=0; i<nb_mass; i++) {
delete mass[i];
@@ -114,8 +123,8 @@ protected:
for (i=0; i<nb_link; i++) {
delete link[i];
}
- ToOutAnything(1,S_Reset,0,sortie);
- nb_link = 0;
+ ToOutAnything(1,S_Reset,0,NULL);
+ nb_link = 0;
nb_mass = 0;
id_mass = 0;
id_link = 0;
@@ -126,11 +135,11 @@ protected:
void m_bang()
{
- t_float F=0,Fx=0,Fy=0,distance,vitesse, X_new, Y_new;
+ t_float F=0,Fx=0,Fy=0,distance,vitesse, X_new, Y_new;
t_int i;
- struct _mass mass_1, mass_2;
+ struct _mass mass_1, mass_2;
- for (i=0; i<nb_link; i++) {
+ for (i=0; i<nb_link; i++) {
// 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)); // L[n] = sqrt( (x1-x2)² +(y1-y2)²)
@@ -145,21 +154,21 @@ protected:
Fx = F * (link[i]->mass1->posX - link[i]->mass2->posX)/distance; // Fx = F * Lx[n]/L[n]
Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance; // Fy = F * Ly[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]
+ link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
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]->mass1->forceY -= Fy; // Fy1[n] = -Fy
- link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
+ link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
link[i]->mass2->forceY += Fy; // Fy2[n] = Fy
link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[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) {
+
+ for (i=0; i<nb_mass; i++)
+ // compute new masses position only if mobile = 1
+ if (mass[i]->mobile == 1) {
X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1]
mass[i]->posX = max(min(X_new,Xmax),Xmin); // x[n-1] = x[n]
@@ -170,21 +179,21 @@ protected:
mass[i]->speedY = mass[i]->posY - mass[i]->posY2; // vx[n] = x[n] - x[n-1]
}
- for (i=0; i<nb_mass; i++) {
+ for (i=0; i<nb_mass; i++) {
// clear forces
- mass[i]->out_forceX = mass[i]->forceX;
+ mass[i]->out_forceX = mass[i]->forceX;
mass[i]->forceX = 0; // Fx[n] = 0
- mass[i]->out_forceY = mass[i]->forceY;
+ mass[i]->out_forceY = mass[i]->forceY;
mass[i]->forceY = 0; // Fy[n] = 0
- }
+ }
}
// -------------------------------------------------------------- MASSES
// ----------------------------------------------------------------------
- void m_mass(int argc,t_atom *argv)
- // add a mass
- // Id, nbr, mobile, invM, speedX Y, posX Y, forceX Y
+ void m_mass(int argc,t_atom *argv)
+ // add a mass
+ // Id, nbr, mobile, invM, speedX Y, posX Y, forceX Y
{
t_atom sortie[6], aux[2];
t_float M;
@@ -192,24 +201,24 @@ protected:
if (argc != 5)
error("mass : Id mobile mass X Y");
- mass[nb_mass] = new t_mass; // new mass
+ mass[nb_mass] = new t_mass; // new mass
mass[nb_mass]->Id = GetSymbol(argv[0]); // ID
mass[nb_mass]->mobile = GetInt(argv[1]); // mobile
if (GetFloat(argv[2])==0)
M=1;
else M = GetFloat(argv[2]);
mass[nb_mass]->invM = 1/(M); // invM
- mass[nb_mass]->speedX = 0; // vx[n]
+ mass[nb_mass]->speedX = 0; // vx[n]
mass[nb_mass]->posX = GetFloat(argv[3]); // x[n]
- mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1]
+ mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1]
mass[nb_mass]->forceX = 0; // Fx[n]
- mass[nb_mass]->speedY = 0; // vy[n]
+ mass[nb_mass]->speedY = 0; // vy[n]
mass[nb_mass]->posY = GetFloat(argv[4]); // y[n]
- mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1]
+ mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1]
mass[nb_mass]->forceY = 0; // Fy[n]
mass[nb_mass]->nbr = id_mass; // id number
nb_mass++ ;
- id_mass++;
+ id_mass++;
nb_mass = min ( nb_max_mass -1, nb_mass );
SetFloat((sortie[0]),id_mass-1);
SetSymbol((sortie[1]),GetSymbol(argv[0]));
@@ -220,8 +229,8 @@ protected:
ToOutAnything(1,S_Mass,6,sortie);
}
- void m_forceX(int argc,t_atom *argv)
- {
+ void m_forceX(int argc,t_atom *argv)
+ {
// add a force to mass(es) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -236,8 +245,8 @@ protected:
}
}
- void m_forceY(int argc,t_atom *argv)
- {
+ void m_forceY(int argc,t_atom *argv)
+ {
// add a force to mass(es) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -253,8 +262,8 @@ protected:
}
void m_posX(int argc,t_atom *argv)
- {
- // displace mass(es) named Id to a certain position
+ {
+ // displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -270,8 +279,8 @@ protected:
}
void m_posY(int argc,t_atom *argv)
- {
- // displace mass(es) named Id to a certain position
+ {
+ // displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -288,8 +297,8 @@ protected:
}
void m_set_mobile(int argc,t_atom *argv)
- {
- // set mass No to mobile
+ {
+ // set mass No to mobile
t_int i,aux;
if (argc != 1)
@@ -305,8 +314,8 @@ protected:
}
void m_set_fixe(int argc,t_atom *argv)
- {
- // set mass No to fixed
+ {
+ // set mass No to fixed
t_int i,aux;
if (argc != 1)
@@ -325,7 +334,8 @@ protected:
{
// Delete mass
t_int i,nb_link_delete=0;
- t_atom sortie[6], aux[nb_link];
+ t_atom sortie[6];
+ NEWARR(t_atom,aux,nb_link);
if (argc != 1)
error("deleteMass : Nomass");
@@ -356,11 +366,12 @@ protected:
ToOutAnything(1,S_Mass_deleted,6,sortie);
break;
}
+ DELARR(aux);
}
void m_Xmax(int argc,t_atom *argv)
- {
+ {
// set X max
if (argc != 1)
error("Xmax : Value");
@@ -368,14 +379,14 @@ protected:
}
void m_Xmin(int argc,t_atom *argv)
- {
+ {
// set X min
if (argc != 1)
error("Xmin : Value");
Xmin = GetFloat(argv[0]);
}
void m_Ymax(int argc,t_atom *argv)
- {
+ {
// set Y max
if (argc != 1)
error("Ymax : Value");
@@ -383,7 +394,7 @@ protected:
}
void m_Ymin(int argc,t_atom *argv)
- {
+ {
// set Y min
if (argc != 1)
error("Ymin : Value");
@@ -394,9 +405,9 @@ protected:
// ---------------------------------------------------------------------
void m_link(int argc,t_atom *argv)
- // add a link
- // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax)
- {
+ // add a link
+ // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax)
+ {
t_atom sortie[7], aux[2];
t_int i;
@@ -409,7 +420,7 @@ protected:
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]->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]
@@ -432,7 +443,7 @@ protected:
break;
}
nb_link++;
- id_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);
@@ -441,15 +452,17 @@ 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, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax)
- {
+ // add interactor link
+ // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax)
+ {
t_atom aux[2], arglist[8];
- t_int i,j, imass1[nb_mass], nbmass1=0, imass2[nb_mass], nbmass2=0;
+ t_int i,j, nbmass1=0, nbmass2=0;
+ NEWARR(t_int,imass1,nb_mass);
+ NEWARR(t_int,imass2,nb_mass);
t_symbol *Id1, *Id2;
if (argc < 6 || argc > 8)
@@ -490,10 +503,12 @@ protected:
}
m_link(argc,arglist);
}
+ DELARR(imass1);
+ DELARR(imass2);
}
void m_setK(int argc,t_atom *argv)
- {
+ {
// set rigidity of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -509,7 +524,7 @@ protected:
}
void m_setD(int argc,t_atom *argv)
- {
+ {
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -525,7 +540,7 @@ protected:
}
void m_setD2(int argc,t_atom *argv)
- {
+ {
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -742,7 +757,7 @@ protected:
void m_mass_dumpl()
// List of masses positions on first outlet
{
- t_atom sortie[2*nb_mass];
+ NEWARR(t_atom,sortie,2*nb_mass);
t_int i;
for (i=0; i<nb_mass; i++) {
@@ -750,12 +765,13 @@ protected:
SetFloat((sortie[2*i+1]),mass[i]->posY);
}
ToOutAnything(0, S_massesPosL, 2*nb_mass, sortie);
+ DELARR(sortie);
}
void m_force_dumpl()
// List of masses forces on first outlet
{
- t_atom sortie[2*nb_mass];
+ NEWARR(t_atom,sortie,2*nb_mass);
t_int i;
for (i=0; i<nb_mass; i++) {
@@ -763,6 +779,7 @@ protected:
SetFloat((sortie[2*i+1]),mass[i]->out_forceY);
}
ToOutAnything(0, S_massesForcesL, 2*nb_mass, sortie);
+ DELARR(sortie);
}
void m_info_dumpl()
@@ -797,7 +814,7 @@ protected:
// -------------------------------------------------------------- GLOBAL VARIABLES
// --------------------------------------------------------------------------------
- t_link * link[nb_max_link];
+ t_link * link[nb_max_link];
t_mass * mass[nb_max_mass];
t_float Xmin, Xmax, Ymin, Ymax;
int nb_link, nb_mass, id_mass, id_link;
diff --git a/msd3D/main.cpp b/msd3D/main.cpp
index 2deb80a..c235776 100755
--- a/msd3D/main.cpp
+++ b/msd3D/main.cpp
@@ -39,8 +39,8 @@
// define constants
#define MSD3D_VERSION 0.03
-#define nb_max_link 4000
-#define nb_max_mass 4000
+#define nb_max_link 4000
+#define nb_max_mass 4000
#define Id_length 20
// check for appropriate flext version
@@ -48,36 +48,46 @@
#error You need at least flext version 0.4.1
#endif
-#define max(a,b) ( ((a) > (b)) ? (a) : (b) )
+#define max(a,b) ( ((a) > (b)) ? (a) : (b) )
#define min(a,b) ( ((a) < (b)) ? (a) : (b) )
-typedef struct _mass {
+#ifdef _MSC_VER
+#define NEWARR(type,var,size) type *var = new type[size]
+#define DELARR(var) delete[] var
+#else
+#define NEWARR(type,var,size) type var[size]
+#define DELARR(var) ((void)0)
+#endif
+
+
+
+typedef struct _mass {
t_symbol *Id;
t_int nbr;
- t_int mobile;
- t_float invM;
- t_float speedX;
+ t_int mobile;
+ t_float invM;
+ t_float speedX;
t_float posX;
- t_float posX2;
+ t_float posX2;
t_float forceX;
t_float out_forceX;
- t_float speedY;
+ t_float speedY;
t_float posY;
- t_float posY2;
+ t_float posY2;
t_float forceY;
t_float out_forceY;
t_float speedZ;
t_float posZ;
- t_float posZ2;
+ t_float posZ2;
t_float forceZ;
t_float out_forceZ;
-} t_mass;
-
-typedef struct _link {
+} t_mass;
+
+typedef struct _link {
t_symbol *Id;
- t_int nbr;
- t_mass *mass1;
- t_mass *mass2;
+ t_int nbr;
+ t_mass *mass1;
+ t_mass *mass2;
t_float K1, D1, D2;
t_float longx, longy, longz, longueur, long_min, long_max;
t_float distance_old;
@@ -110,7 +120,7 @@ protected:
void m_reset()
{
t_int i;
- t_atom sortie[0];
+// t_atom sortie[0];
for (i=0; i<nb_mass; i++) {
delete mass[i];
@@ -118,8 +128,8 @@ protected:
for (i=0; i<nb_link; i++) {
delete link[i];
}
- ToOutAnything(1,S_Reset,0,sortie);
- nb_link = 0;
+ ToOutAnything(1,S_Reset,0,NULL);
+ nb_link = 0;
nb_mass = 0;
id_mass = 0;
id_link = 0;
@@ -129,11 +139,11 @@ protected:
// -----------------------------------------------------------------------
void m_bang()
{
- t_float F=0,Fx=0,Fy=0, Fz=0,distance,vitesse, X_new, Y_new, Z_new;
+ t_float F=0,Fx=0,Fy=0, Fz=0,distance,vitesse, X_new, Y_new, Z_new;
t_int i;
- struct _mass mass_1, mass_2;
+ struct _mass mass_1, mass_2;
- for (i=0; i<nb_link; i++) {
+ for (i=0; i<nb_link; i++) {
// 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]
@@ -150,25 +160,25 @@ protected:
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]
+ link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
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]->mass1->forceY -= Fy; // Fy1[n] = -Fy
- link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
+ link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
link[i]->mass2->forceY += Fy; // Fy2[n] = Fy
link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY; // Fy2[n] = Fy2[n] - D2 * vy2[n-1]
link[i]->mass1->forceZ -= Fz; // Fz1[n] = -Fz
- link[i]->mass1->forceZ -= link[i]->D2*link[i]->mass1->speedZ; // Fz1[n] = Fz1[n] - D2 * vz1[n-1]
+ link[i]->mass1->forceZ -= link[i]->D2*link[i]->mass1->speedZ; // Fz1[n] = Fz1[n] - D2 * vz1[n-1]
link[i]->mass2->forceZ += Fz; // Fz2[n] = Fz
link[i]->mass2->forceZ -= link[i]->D2*link[i]->mass2->speedZ; // Fz2[n] = Fz2[n] - D2 * vz2[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) {
+
+ for (i=0; i<nb_mass; i++)
+ // compute new masses position only if mobile = 1
+ if (mass[i]->mobile == 1) {
X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1]
mass[i]->posX = max(min(X_new,Xmax),Xmin); // x[n-1] = x[n]
@@ -183,22 +193,22 @@ protected:
mass[i]->speedZ = mass[i]->posZ - mass[i]->posZ2; // vz[n] = z[n] - z[n-1]
}
- for (i=0; i<nb_mass; i++) {
+ for (i=0; i<nb_mass; i++) {
// clear forces
- mass[i]->out_forceX = mass[i]->forceX;
+ mass[i]->out_forceX = mass[i]->forceX;
mass[i]->forceX = 0;
- mass[i]->out_forceY = mass[i]->forceY;
+ mass[i]->out_forceY = mass[i]->forceY;
mass[i]->forceY = 0;
- mass[i]->out_forceZ = mass[i]->forceZ;
+ mass[i]->out_forceZ = mass[i]->forceZ;
mass[i]->forceZ = 0;
- }
+ }
}
// -------------------------------------------------------------- MASSES
// ----------------------------------------------------------------------
- void m_mass(int argc,t_atom *argv)
- // add a mass
- // Id, nbr, mobile, invM, speedX, posX, forceX
+ void m_mass(int argc,t_atom *argv)
+ // add a mass
+ // Id, nbr, mobile, invM, speedX, posX, forceX
{
t_atom sortie[7], aux[2];
t_float M;
@@ -206,28 +216,28 @@ protected:
if (argc != 6)
error("mass : Id mobile mass X Y Z");
- mass[nb_mass] = new t_mass; // new mass
+ mass[nb_mass] = new t_mass; // new mass
mass[nb_mass]->Id = GetSymbol(argv[0]); // Id
mass[nb_mass]->mobile = GetInt(argv[1]); // mobile
if (GetFloat(argv[2])==0)
M=1;
else M = GetFloat(argv[2]);
mass[nb_mass]->invM = 1/(M); // 1/M
- mass[nb_mass]->speedX = 0; // vx[n]
+ mass[nb_mass]->speedX = 0; // vx[n]
mass[nb_mass]->posX = GetFloat(argv[3]); // x[n]
- mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1]
+ mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1]
mass[nb_mass]->forceX = 0; // Fx[n]
- mass[nb_mass]->speedY = 0; // vy[n]
+ mass[nb_mass]->speedY = 0; // vy[n]
mass[nb_mass]->posY = GetFloat(argv[4]); // y[n]
- mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1]
+ mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1]
mass[nb_mass]->forceY = 0; // Fz[n]
- mass[nb_mass]->speedZ = 0; // vz[n]
+ mass[nb_mass]->speedZ = 0; // vz[n]
mass[nb_mass]->posZ = GetFloat(argv[5]); // z[n]
- mass[nb_mass]->posZ2 = GetFloat(argv[5]); // z[n-1]
+ mass[nb_mass]->posZ2 = GetFloat(argv[5]); // z[n-1]
mass[nb_mass]->forceZ = 0; // Fz[n]
mass[nb_mass]->nbr = id_mass; // id number
nb_mass++ ;
- id_mass++;
+ id_mass++;
nb_mass = min ( nb_max_mass -1, nb_mass );
SetFloat((sortie[0]),id_mass-1);
SetSymbol((sortie[1]),GetSymbol(argv[0]));
@@ -239,8 +249,8 @@ protected:
ToOutAnything(1,S_Mass ,7,sortie);
}
- void m_forceX(int argc,t_atom *argv)
- {
+ void m_forceX(int argc,t_atom *argv)
+ {
// add a force to mass(es) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -255,8 +265,8 @@ protected:
}
}
- void m_forceY(int argc,t_atom *argv)
- {
+ void m_forceY(int argc,t_atom *argv)
+ {
// add a force to mass(es) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -271,8 +281,8 @@ protected:
}
}
- void m_forceZ(int argc,t_atom *argv)
- {
+ void m_forceZ(int argc,t_atom *argv)
+ {
// add a force to mass(es) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -288,8 +298,8 @@ protected:
}
void m_posX(int argc,t_atom *argv)
- {
- // displace mass(es) named Id to a certain position
+ {
+ // displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -305,8 +315,8 @@ protected:
}
void m_posY(int argc,t_atom *argv)
- {
- // displace mass(es) named Id to a certain position
+ {
+ // displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -323,8 +333,8 @@ protected:
}
void m_posZ(int argc,t_atom *argv)
- {
- // displace mass(es) named Id to a certain position
+ {
+ // displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -341,8 +351,8 @@ protected:
}
void m_set_mobile(int argc,t_atom *argv)
- {
- // set mass No to mobile
+ {
+ // set mass No to mobile
t_int i,aux;
if (argc != 1)
@@ -358,8 +368,8 @@ protected:
}
void m_set_fixe(int argc,t_atom *argv)
- {
- // set mass No to fixed
+ {
+ // set mass No to fixed
t_int i,aux;
if (argc != 1)
@@ -378,7 +388,8 @@ protected:
{
// Delete mass
t_int i,nb_link_delete=0;
- t_atom sortie[7], aux[nb_link];
+ t_atom sortie[7];
+ NEWARR(t_atom,aux,nb_link);
if (argc != 1)
error("deleteMass : Nomass");
@@ -410,11 +421,12 @@ protected:
ToOutAnything(1,S_Mass_deleted,7,sortie);
break;
}
+ DELARR(aux);
}
void m_Xmax(int argc,t_atom *argv)
- {
+ {
// set X max
if (argc != 1)
error("Xmax : Value");
@@ -422,14 +434,14 @@ protected:
}
void m_Xmin(int argc,t_atom *argv)
- {
+ {
// set X min
if (argc != 1)
error("Xmin : Value");
Xmin = GetFloat(argv[0]);
}
void m_Ymax(int argc,t_atom *argv)
- {
+ {
// set Y max
if (argc != 1)
error("Ymax : Value");
@@ -437,7 +449,7 @@ protected:
}
void m_Ymin(int argc,t_atom *argv)
- {
+ {
// set Y min
if (argc != 1)
error("Ymin : Value");
@@ -445,7 +457,7 @@ protected:
}
void m_Zmax(int argc,t_atom *argv)
- {
+ {
// set maximum Z of all masses
if (argc != 1)
error("Zmax : Value");
@@ -453,7 +465,7 @@ protected:
}
void m_Zmin(int argc,t_atom *argv)
- {
+ {
// set minimum Z of all masses
if (argc != 1)
error("Zmin : Value");
@@ -463,9 +475,9 @@ protected:
// -------------------------------------------------------------- LINKS
// ---------------------------------------------------------------------
void m_link(int argc,t_atom *argv)
- // add a link
- // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax)
- {
+ // add a link
+ // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax)
+ {
t_atom sortie[7], aux[2];
t_int i;
@@ -478,7 +490,7 @@ protected:
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]->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]
@@ -502,7 +514,7 @@ protected:
break;
}
nb_link++;
- id_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);
@@ -511,15 +523,17 @@ 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, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax)
- {
+ // add interactor link
+ // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax)
+ {
t_atom aux[2], arglist[8];
- t_int i,j, imass1[nb_mass], nbmass1=0, imass2[nb_mass], nbmass2=0;
+ t_int i,j, nbmass1=0, nbmass2=0;
+ NEWARR(t_int,imass1,nb_mass);
+ NEWARR(t_int,imass2,nb_mass);
t_symbol *Id1, *Id2;
if (argc < 6 || argc > 8)
@@ -560,10 +574,12 @@ protected:
}
m_link(argc,arglist);
}
+ DELARR(imass1);
+ DELARR(imass2);
}
void m_setK(int argc,t_atom *argv)
- {
+ {
// set rigidity of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -579,7 +595,7 @@ protected:
}
void m_setD(int argc,t_atom *argv)
- {
+ {
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -595,7 +611,7 @@ protected:
}
void m_setD2(int argc,t_atom *argv)
- {
+ {
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
@@ -827,7 +843,7 @@ protected:
void m_mass_dumpl()
// List of masses positions on first outlet
{
- t_atom sortie[3*nb_mass];
+ NEWARR(t_atom,sortie,3*nb_mass);
t_int i;
for (i=0; i<nb_mass; i++) {
@@ -836,12 +852,13 @@ protected:
SetFloat((sortie[3*i+2]),mass[i]->posZ);
}
ToOutAnything(0, S_massesPosL, 3*nb_mass, sortie);
+ DELARR(sortie);
}
void m_force_dumpl()
// List of masses positions on first outlet
{
- t_atom sortie[3*nb_mass];
+ NEWARR(t_atom,sortie,3*nb_mass);
t_int i;
for (i=0; i<nb_mass; i++) {
@@ -850,6 +867,7 @@ protected:
SetFloat((sortie[3*i+2]),mass[i]->out_forceZ);
}
ToOutAnything(0, S_massesForcesL, 3*nb_mass, sortie);
+ DELARR(sortie);
}
void m_info_dumpl()
@@ -884,7 +902,7 @@ protected:
// -------------------------------------------------------------- GLOBAL VARIABLES
// --------------------------------------------------------------------------------
- t_link * link[nb_max_link];
+ t_link * link[nb_max_link];
t_mass * mass[nb_max_mass];
t_float Xmin, Xmax, Ymin, Ymax, Zmin, Zmax;
int nb_link, nb_mass, id_mass, id_link;