aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN.N. <nimon@users.sourceforge.net>2005-04-28 15:22:14 +0000
committerN.N. <nimon@users.sourceforge.net>2005-04-28 15:22:14 +0000
commitebbeac04a2f1f57cac1bfd87b6da0f58c033e9a8 (patch)
tree625c01bf592bde50e33fa45fb7630300c7179b31
parente68340de2b4519bf90bf339256e25cde16db6c4b (diff)
MSD version 0.05
svn path=/trunk/externals/nusmuk/; revision=2846
-rw-r--r--msd/03_msdwave.pd22
-rw-r--r--msd/help-msd.pd18
-rwxr-xr-xmsd/main.cpp344
-rw-r--r--msd2D/help-msd2D.pd26
-rwxr-xr-xmsd2D/main.cpp438
-rw-r--r--msd3D/02_msd3Dperf.pd22
-rw-r--r--msd3D/help-msd3D.pd26
-rw-r--r--msd3D/imsd3Dball.pd1
-rwxr-xr-xmsd3D/main.cpp517
-rw-r--r--msd3D/msd3Dball.pd1
10 files changed, 768 insertions, 647 deletions
diff --git a/msd/03_msdwave.pd b/msd/03_msdwave.pd
index e69ae1b..4ac3ab6 100644
--- a/msd/03_msdwave.pd
+++ b/msd/03_msdwave.pd
@@ -12,22 +12,22 @@
#N canvas 721 124 605 590 massrender 0;
#X obj 127 22 inlet;
#X obj 48 203 translateXYZ;
-#X obj 64 114 gemhead;
#X obj 48 177 separator;
#X obj 48 153 any;
#X obj 127 136 t b f;
#X obj 127 57 unpack f f f;
#X obj 48 283 cuboid 0.065 0.065 0.07;
-#X connect 0 0 6 0;
-#X connect 1 0 7 0;
-#X connect 2 0 4 1;
-#X connect 3 0 1 0;
+#X obj 64 114 gemhead 45;
+#X connect 0 0 5 0;
+#X connect 1 0 6 0;
+#X connect 2 0 1 0;
+#X connect 3 0 2 0;
#X connect 4 0 3 0;
+#X connect 4 1 1 1;
#X connect 5 0 4 0;
-#X connect 5 1 1 1;
-#X connect 6 0 5 0;
-#X connect 6 1 1 2;
-#X connect 6 2 7 3;
+#X connect 5 1 1 2;
+#X connect 5 2 6 3;
+#X connect 7 0 3 1;
#X restore 265 625 pd massrender;
#X msg 203 83 symbol reset;
#X text 793 205 Select view;
@@ -67,7 +67,7 @@
#X msg 63 718 get massesPos \$1;
#X obj 602 334 rotateXYZ;
#X obj 651 450 vsl 15 128 0 4 0 0 empty empty empty 0 -8 0 8 -262131
--1 -1 0 1;
+-1 -1 1400 1;
#X obj 670 450 vsl 15 128 0 4 0 0 empty empty empty 0 -8 0 8 -262131
-1 -1 0 1;
#X obj 689 450 vsl 15 128 0 4 0 0 empty empty empty 0 -8 0 8 -262131
@@ -104,7 +104,7 @@ z is asked to the 1D model.;
test synchronization between msd objects;
#X obj 33 537 unpack f f f;
#X obj 443 546 unpack f f;
-#X obj 173 598 f;
+#X obj 173 597 f;
#X obj 33 574 t b f;
#X connect 0 0 12 0;
#X connect 2 0 1 0;
diff --git a/msd/help-msd.pd b/msd/help-msd.pd
index 157d95f..22d551f 100644
--- a/msd/help-msd.pd
+++ b/msd/help-msd.pd
@@ -16,7 +16,6 @@
#X obj 61 403 cnv 15 610 210 empty empty DYNAMIC_SETTING 20 12 0 14
-262131 -66577 0;
#X text 350 467 \$2 : New value;
-#X text 348 503 \$1 : Id (symbol);
#X text 348 521 \$2 : New value;
#X msg 87 429 posX \$1 \$2;
#X text 350 431 Set position of mass(es);
@@ -58,18 +57,19 @@ their;
#X text 345 594 \$1 : Creation No of mass;
#X text 334 271 \$4 : initial position;
#X text 350 449 \$1 : Id (symbol) or No;
+#X text 348 503 \$1 : Id (symbol) or No;
#X connect 2 0 0 0;
#X connect 9 0 0 0;
-#X connect 15 0 0 0;
-#X connect 18 0 0 0;
+#X connect 14 0 0 0;
+#X connect 17 0 0 0;
+#X connect 19 0 0 0;
#X connect 20 0 0 0;
-#X connect 21 0 0 0;
-#X connect 24 0 0 0;
+#X connect 23 0 0 0;
+#X connect 27 0 0 0;
#X connect 28 0 0 0;
-#X connect 29 0 0 0;
-#X connect 32 0 0 0;
-#X connect 34 0 0 0;
-#X connect 43 0 0 0;
+#X connect 31 0 0 0;
+#X connect 33 0 0 0;
+#X connect 42 0 0 0;
#X restore 282 323 pd masses;
#N canvas 222 83 808 841 links 0;
#X obj 33 821 msd;
diff --git a/msd/main.cpp b/msd/main.cpp
index f74ba3d..28b3276 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.04 -- 26.04.2005
+ Version 0.05 -- 28.04.2005
*/
// include flext header
@@ -38,7 +38,7 @@
#include <math.h>
// define constants
-#define MSD_VERSION 0.04
+#define MSD_VERSION 0.05
#define nb_max_link 4000
#define nb_max_mass 4000
#define Id_length 20
@@ -112,13 +112,14 @@ protected:
void m_reset()
{
t_int i;
-// t_atom sortie;
+ t_mass **mi;
+ t_link **li;
- for (i=0; i<nb_mass; i++) {
- delete mass[i];
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ delete (*mi);
}
- for (i=0; i<nb_link; i++) {
- delete link[i];
+ for (i=0, li=link; i<nb_link; li++,i++) {
+ delete (*li);
}
ToOutAnything(1,S_Reset,0,NULL);
nb_link = 0;
@@ -134,45 +135,43 @@ protected:
{
t_float F=0,Fx=0,distance,vitesse, X_new;
t_int i;
- struct _mass mass_1, mass_2;
+ t_mass **mi;
+ t_link **li;
-
- for (i=0; i<nb_link; i++) {
+ for (i=0, li=link; i<nb_link; li++,i++) {
// compute link forces
- distance = link[i]->mass1->posX-link[i]->mass2->posX; // L[n] = x1 - x2
+ distance = (*li)->mass1->posX-(*li)->mass2->posX; // L[n] = x1 - x2
if (distance < 0)
distance = -distance; // |L[n]|
- if (distance < link[i]->long_min || distance > link[i]->long_max)
+ if (distance < (*li)->long_min || distance > (*li)->long_max)
Fx = 0;
else { // Lmin < L < Lmax
- F = link[i]->K1 * (distance - link[i]->longueur) ; // F[n] = k1 (L[n] - L[0])
- F += link[i]->D1 * (distance - link[i]->distance_old) ; // F[n] = F[n] + D1 (L[n] - L[n-1])
+ F = (*li)->K1 * (distance - (*li)->longueur) ; // F[n] = k1 (L[n] - L[0])
+ F += (*li)->D1 * (distance - (*li)->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]
+ Fx = F * ((*li)->mass1->posX - (*li)->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]->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]
+ (*li)->mass1->forceX -= Fx; // Fx1[n] = -Fx
+ (*li)->mass1->forceX -= (*li)->D2*(*li)->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
+ (*li)->mass2->forceX += Fx; // Fx2[n] = Fx
+ (*li)->mass2->forceX -= (*li)->D2*(*li)->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1]
+ (*li)->distance_old = distance; // L[n-1] = L[n]
}
-
-
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, 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]
+ if ((*mi)->mobile == 1) {
+ X_new = (*mi)->forceX * (*mi)->invM + 2*(*mi)->posX - (*mi)->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ (*mi)->posX2 = (*mi)->posX; // x[n-2] = x[n-1]
+ (*mi)->posX = max(min(X_new,Xmax),Xmin); // x[n-1] = x[n]
+ (*mi)->speedX = (*mi)->posX - (*mi)->posX2; // vx[n] = x[n] - x[n-1]
}
- for (i=0; i<nb_mass; i++) {
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
// clear forces
- mass[i]->out_forceX = mass[i]->forceX;
- mass[i]->forceX = 0; // Fx[n] = 0
+ (*mi)->out_forceX = (*mi)->forceX;
+ (*mi)->forceX = 0; // Fx[n] = 0
}
}
@@ -213,43 +212,54 @@ protected:
void m_forceX(int argc,t_atom *argv)
{
- // add a force to mass(es) named Id
+ // add a force to mass(es) named Id or No
t_int i;
- const t_symbol *sym = GetSymbol(argv[0]);
+ const t_symbol *sym = GetASymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
error("forceX : Idmass value");
- for (i=0; i<nb_mass;i++)
- {
- if (sym == mass[i]->Id)
- mass[i]->forceX += GetFloat(argv[1]);
- }
+ if (sym ==0)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (GetInt(argv[0]) == (*mi)->nbr) {
+ (*mi)->forceX = GetFloat(argv[1]);
+ break;
+ }
+ }
+ else
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (sym == (*mi)->Id)
+ (*mi)->forceX = GetFloat(argv[1]);
+ }
}
void m_posX(int argc,t_atom *argv)
{
- // displace mass(es) named Id to a certain position
+ // displace mass(es) named Id or No to a certain position
t_int i;
const t_symbol *sym = GetASymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
error("posX : Id/Nomass value");
if (GetFloat(argv[1]) < Xmax && GetFloat(argv[1]) > Xmin)
if (sym ==0)
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (GetInt(argv[0]) == mass[i]->nbr) {
- mass[i]->posX = GetFloat(argv[1]);
+ if (GetInt(argv[0]) == (*mi)->nbr) {
+ (*mi)->posX = GetFloat(argv[1]);
break;
}
}
else
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (sym == mass[i]->Id)
- mass[i]->posX = GetFloat(argv[1]);
+ if (sym == (*mi)->Id)
+ (*mi)->posX = GetFloat(argv[1]);
}
}
@@ -257,15 +267,16 @@ protected:
{
// set mass No to mobile
t_int i,aux;
+ t_mass **mi;
if (argc != 1)
error("setMobile : Idmass");
aux = GetInt(argv[0]);
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (mass[i]->nbr == aux)
- mass[i]->mobile = 1;
+ if ((*mi)->nbr == aux)
+ (*mi)->mobile = 1;
}
}
@@ -274,15 +285,16 @@ protected:
{
// set mass No to fixed
t_int i,aux;
+ t_mass **mi;
if (argc != 1)
error("setFixed : Idmass");
aux = GetInt(argv[0]);
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (mass[i]->nbr == aux)
- mass[i]->mobile = 0;
+ if ((*mi)->nbr == aux)
+ (*mi)->mobile = 0;
}
}
@@ -293,14 +305,16 @@ protected:
t_int i,nb_link_delete=0;
t_atom sortie[5];
NEWARR(t_atom,aux,nb_link);
-
+ t_mass **mi;
+ t_link **li;
+
if (argc != 1)
error("deleteMass : Nomass");
// Delete all associated links
- for (i=0; i<nb_link;i++) {
- if (link[i]->mass1->nbr == GetAInt(argv[0]) || link[i]->mass2->nbr == GetAInt(argv[0])) {
- SetFloat((aux[nb_link_delete]),link[i]->nbr);
+ for (i=0, li=link; i<nb_link; li++,i++) {
+ if ((*li)->mass1->nbr == GetAInt(argv[0]) || (*li)->mass2->nbr == GetAInt(argv[0])) {
+ SetFloat((aux[nb_link_delete]),(*li)->nbr);
nb_link_delete++;
}
}
@@ -309,15 +323,15 @@ protected:
m_delete_link(1,&aux[i]);
// Delete mass
- for (i=0; i<nb_mass;i++)
- if (mass[i]->nbr == GetAInt(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);
- delete mass[i];
- mass[i] = mass[nb_mass-1]; // copy last mass instead
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr == GetAInt(argv[0])) {
+ SetFloat((sortie[0]),(*mi)->nbr);
+ SetSymbol((sortie[1]),(*mi)->Id);
+ SetFloat((sortie[2]),(*mi)->mobile);
+ SetFloat((sortie[3]),1/(*mi)->invM);
+ SetFloat((sortie[4]),(*mi)->posX);
+ delete (*mi);
+ (*mi) = mass[nb_mass-1]; // copy last mass instead
nb_mass--;
ToOutAnything(1,S_Mass_deleted,5,sortie);
break;
@@ -354,18 +368,20 @@ protected:
t_int i;
t_mass *mass1 = NULL;
t_mass *mass2 = NULL;
-
+ t_mass **mi;
+
+
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
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[1])) // pointer to mass1
// we found mass1
- mass1 = mass[i];
- else if (mass[i]->nbr==GetInt(argv[2])) // pointer to mass2
+ mass1 = (*mi);
+ else if ((*mi)->nbr==GetInt(argv[2])) // pointer to mass2
// ... and mass2
- mass2 = mass[i];
+ mass2 = (*mi);
if (mass1 and mass2)
{
@@ -422,6 +438,7 @@ protected:
NEWARR(t_int,imass1,nb_mass);
NEWARR(t_int,imass2,nb_mass);
t_symbol *Id1, *Id2;
+ t_mass **mi;
if (argc < 6 || argc > 8)
error("ilink : Id Idmass1 Idmass2 K D1 D2 (Lmin Lmax)");
@@ -430,12 +447,12 @@ protected:
Id2 = GetSymbol(argv[2]);
ToOutAnything(1,S_iLink,0,aux);
- for (i=0;i<nb_mass;i++) {
- if (Id1 == mass[i]->Id) {
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ if (Id1 == (*mi)->Id) {
imass1[nbmass1]=i;
nbmass1++;
}
- if (Id2 == mass[i]->Id) {
+ if (Id2 == (*mi)->Id) {
imass2[nbmass2]=i;
nbmass2++;
}
@@ -471,14 +488,15 @@ protected:
// set rigidity of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_link **li;
if (argc != 2)
error("setK : IdLink Value");
- for (i=0; i<nb_link;i++)
+ for (i=0, li=link; i<nb_link; li++,i++)
{
- if (sym == link[i]->Id)
- link[i]->K1 = GetFloat(argv[1]);
+ if (sym == (*li)->Id)
+ (*li)->K1 = GetFloat(argv[1]);
}
}
@@ -487,14 +505,15 @@ protected:
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_link **li;
if (argc != 2)
error("setD : IdLink Value");
- for (i=0; i<nb_link;i++)
+ for (i=0, li=link; i<nb_link; li++,i++)
{
- if (sym == link[i]->Id)
- link[i]->D1 = GetFloat(argv[1]);
+ if (sym == (*li)->Id)
+ (*li)->D1 = GetFloat(argv[1]);
}
}
@@ -503,14 +522,15 @@ protected:
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_link **li;
if (argc != 2)
error("setD2 : IdLink Value");
- for (i=0; i<nb_link;i++)
+ for (i=0, li=link; i<nb_link; li++,i++)
{
- if (sym == link[i]->Id)
- link[i]->D2 = GetFloat(argv[1]);
+ if (sym == (*li)->Id)
+ (*li)->D2 = GetFloat(argv[1]);
}
}
@@ -519,21 +539,22 @@ protected:
// Delete link
t_int i;
t_atom sortie[7];
+ t_link **li;
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
+ for (i=0, li=link; i<nb_link; li++,i++)
+ if ((*li)->nbr == GetInt(argv[0])) {
+ SetFloat((sortie[0]),(*li)->nbr);
+ SetSymbol((sortie[1]),(*li)->Id);
+ SetFloat((sortie[2]),(*li)->mass1->nbr);
+ SetFloat((sortie[3]),(*li)->mass2->nbr);
+ SetFloat((sortie[4]),(*li)->K1);
+ SetFloat((sortie[5]),(*li)->D1);
+ SetFloat((sortie[6]),(*li)->D2);
+ delete (*li);
+ (*li)=link[nb_link-1]; // copy last link instead
nb_link--;
ToOutAnything(1,S_Link_deleted,7,sortie);
break;
@@ -550,37 +571,40 @@ protected:
t_int i,j;
t_symbol *auxarg,*auxarg2, *auxtype;
t_atom sortie[3];
+ t_mass **mi;
+ t_link **li;
+
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++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->posX);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->posX);
ToOutAnything(0,S_massesPos,2,sortie);
}
else if (auxtype == S_massesForces) // get all masses forces
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->out_forceX);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->out_forceX);
ToOutAnything(0,S_massesForces,2,sortie);
}
else if (auxtype == S_linksPos) // get all links positions
- for (i=0; i<nb_link; i++)
+ for (i=0, li=link; i<nb_link; li++,i++)
{
- SetFloat(sortie[0],link[i]->nbr);
- SetFloat(sortie[1],link[i]->mass1->posX);
- SetFloat(sortie[2],link[i]->mass2->posX);
+ SetFloat(sortie[0],(*li)->nbr);
+ SetFloat(sortie[1],(*li)->mass1->posX);
+ SetFloat(sortie[2],(*li)->mass2->posX);
ToOutAnything(0,S_linksPos,3,sortie);
}
else // get all masses speeds
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->speedX);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->speedX);
ToOutAnything(0,S_massesSpeeds,2,sortie);
}
}
@@ -589,11 +613,11 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[j]))
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->posX);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->posX);
ToOutAnything(0,S_massesPosNo,2,sortie);
}
}
@@ -602,12 +626,12 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (auxarg2==mass[i]->Id)
+ if (auxarg2==(*mi)->Id)
{
- SetSymbol(sortie[0],mass[i]->Id);
- SetFloat(sortie[1],mass[i]->posX);
+ SetSymbol(sortie[0],(*mi)->Id);
+ SetFloat(sortie[1],(*mi)->posX);
ToOutAnything(0,S_massesPosId,2,sortie);
}
}
@@ -619,11 +643,11 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[j]))
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->out_forceX);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->out_forceX);
ToOutAnything(0,S_massesForcesNo,2,sortie);
}
}
@@ -632,12 +656,12 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (auxarg2==mass[i]->Id)
+ if (auxarg2==(*mi)->Id)
{
- SetSymbol(sortie[0],mass[i]->Id);
- SetFloat(sortie[1],mass[i]->out_forceX);
+ SetSymbol(sortie[0],(*mi)->Id);
+ SetFloat(sortie[1],(*mi)->out_forceX);
ToOutAnything(0,S_massesForcesId,2,sortie);
}
}
@@ -649,12 +673,12 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_link;i++)
- if (link[i]->nbr==GetInt(argv[j]))
+ for (i=0, li=link; i<nb_link; li++,i++)
+ if ((*li)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],link[i]->nbr);
- SetFloat(sortie[1],link[i]->mass1->posX);
- SetFloat(sortie[2],link[i]->mass2->posX);
+ SetFloat(sortie[0],(*li)->nbr);
+ SetFloat(sortie[1],(*li)->mass1->posX);
+ SetFloat(sortie[2],(*li)->mass2->posX);
ToOutAnything(0,S_linksPosNo,3,sortie);
}
}
@@ -663,13 +687,13 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_link;i++)
+ for (i=0, li=link; i<nb_link; li++,i++)
{
- if (auxarg2==link[i]->Id)
+ if (auxarg2==(*li)->Id)
{
- SetSymbol(sortie[0],link[i]->Id);
- SetFloat(sortie[1],link[i]->mass1->posX);
- SetFloat(sortie[2],link[i]->mass2->posX);
+ SetSymbol(sortie[0],(*li)->Id);
+ SetFloat(sortie[1],(*li)->mass1->posX);
+ SetFloat(sortie[2],(*li)->mass2->posX);
ToOutAnything(0,S_linksPosId,3,sortie);
}
}
@@ -681,11 +705,11 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[j]))
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->speedX);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->speedX);
ToOutAnything(0,S_massesSpeedsNo,2,sortie);
}
}
@@ -694,12 +718,12 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (auxarg2==mass[i]->Id)
+ if (auxarg2==(*mi)->Id)
{
- SetSymbol(sortie[0],mass[i]->Id);
- SetFloat(sortie[1],mass[i]->speedX);
+ SetSymbol(sortie[0],(*mi)->Id);
+ SetFloat(sortie[1],(*mi)->speedX);
ToOutAnything(0,S_massesSpeedsId,2,sortie);
}
}
@@ -715,9 +739,10 @@ protected:
{
NEWARR(t_atom,sortie,nb_mass);
t_int i;
+ t_mass **mi;
- for (i=0; i<nb_mass; i++) {
- SetFloat((sortie[i]),mass[i]->posX);
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ SetFloat((sortie[i]),(*mi)->posX);
}
ToOutAnything(0, S_massesPosL, nb_mass, sortie);
DELARR(sortie);
@@ -728,9 +753,10 @@ protected:
{
NEWARR(t_atom,sortie,nb_mass);
t_int i;
+ t_mass **mi;
- for (i=0; i<nb_mass; i++) {
- SetFloat((sortie[i]),mass[i]->out_forceX);
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ SetFloat((sortie[i]),(*mi)->out_forceX);
}
ToOutAnything(0, S_massesForcesL, nb_mass, sortie);
DELARR(sortie);
@@ -741,24 +767,26 @@ protected:
{
t_atom sortie[7];
t_int i;
+ t_mass **mi;
+ t_link **li;
- for (i=0; i<nb_mass; i++) {
- 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);
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ SetFloat((sortie[0]),(*mi)->nbr);
+ SetSymbol((sortie[1]),(*mi)->Id);
+ SetFloat((sortie[2]),(*mi)->mobile);
+ SetFloat((sortie[3]),1/(*mi)->invM);
+ SetFloat((sortie[4]),(*mi)->posX);
ToOutAnything(1, S_Mass, 5, sortie);
}
- for (i=0; i<nb_link; i++) {
- 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);
+ for (i=0, li=link; i<nb_link; li++,i++) {
+ SetFloat((sortie[0]),(*li)->nbr);
+ SetSymbol((sortie[1]),(*li)->Id);
+ SetFloat((sortie[2]),(*li)->mass1->nbr);
+ SetFloat((sortie[3]),(*li)->mass2->nbr);
+ SetFloat((sortie[4]),(*li)->K1);
+ SetFloat((sortie[5]),(*li)->D1);
+ SetFloat((sortie[6]),(*li)->D2);
ToOutAnything(1, S_Link, 7, sortie);
}
diff --git a/msd2D/help-msd2D.pd b/msd2D/help-msd2D.pd
index 40623a6..67071b9 100644
--- a/msd2D/help-msd2D.pd
+++ b/msd2D/help-msd2D.pd
@@ -15,7 +15,6 @@
#X obj 61 403 cnv 15 610 210 empty empty DYNAMIC_SETTING 20 12 0 14
-262131 -66577 0;
#X text 350 467 \$2 : New value;
-#X text 348 503 \$1 : Id (symbol);
#X text 348 521 \$2 : New value;
#X msg 87 429 posX \$1 \$2;
#X text 350 431 Set position of mass(es);
@@ -60,18 +59,19 @@ their;
#X msg 84 538 Xmin \$1 \, Xmax \$1 \, Ymin \$1 \, Ymax \$1;
#X text 334 271 \$4 \, \$5 : initial position;
#X text 350 449 \$1 : Id (symbol) or No;
-#X connect 1 0 45 0;
-#X connect 8 0 45 0;
-#X connect 14 0 45 0;
-#X connect 17 0 45 0;
-#X connect 19 0 45 0;
-#X connect 20 0 45 0;
-#X connect 23 0 45 0;
-#X connect 27 0 45 0;
-#X connect 30 0 45 0;
-#X connect 39 0 45 0;
-#X connect 42 0 45 0;
-#X connect 47 0 45 0;
+#X text 348 503 \$1 : Id (symbol) or No;
+#X connect 1 0 44 0;
+#X connect 8 0 44 0;
+#X connect 13 0 44 0;
+#X connect 16 0 44 0;
+#X connect 18 0 44 0;
+#X connect 19 0 44 0;
+#X connect 22 0 44 0;
+#X connect 26 0 44 0;
+#X connect 29 0 44 0;
+#X connect 38 0 44 0;
+#X connect 41 0 44 0;
+#X connect 46 0 44 0;
#X restore 221 312 pd masses;
#X text 75 312 HELP on masses --->;
#X text 74 343 HELP on links --->;
diff --git a/msd2D/main.cpp b/msd2D/main.cpp
index ccefdc6..436703b 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.04 -- 26.04.2005
+ Version 0.05 -- 28.04.2005
*/
// include flext header
@@ -38,7 +38,7 @@
#include <math.h>
// define constants
-#define MSD2D_VERSION 0.04
+#define MSD2D_VERSION 0.05
#define nb_max_link 4000
#define nb_max_mass 4000
#define Id_length 20
@@ -115,13 +115,14 @@ protected:
void m_reset()
{
t_int i;
-// t_atom sortie;
+ t_mass **mi;
+ t_link **li;
- for (i=0; i<nb_mass; i++) {
- delete mass[i];
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ delete (*mi);
}
- for (i=0; i<nb_link; i++) {
- delete link[i];
+ for (i=0, li=link; i<nb_link; li++, i++) {
+ delete (*li);
}
ToOutAnything(1,S_Reset,0,NULL);
nb_link = 0;
@@ -137,54 +138,55 @@ protected:
{
t_float F=0,Fx=0,Fy=0,distance,vitesse, X_new, Y_new;
t_int i;
- struct _mass mass_1, mass_2;
+ t_mass **mi;
+ t_link **li;
- for (i=0; i<nb_link; i++) {
+ for (i=0, li=link; i<nb_link; li++, 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)²)
- if (distance < link[i]->long_min || distance > link[i]->long_max) {
+ distance = sqrt(pow((*li)->mass1->posX-(*li)->mass2->posX,2) +
+ pow((*li)->mass1->posY-(*li)->mass2->posY,2)); // L[n] = sqrt( (x1-x2)² +(y1-y2)²)
+ if (distance < (*li)->long_min || distance > (*li)->long_max) {
Fx = 0;
Fy = 0;
}
else {
- F = link[i]->K1 * (distance - link[i]->longueur) ; // F[n] = k1 (L[n] - L[0])
- F += link[i]->D1 * (distance - link[i]->distance_old) ; // F[n] = F[n] + D1 (L[n] - L[n-1])
+ F = (*li)->K1 * (distance - (*li)->longueur) ; // F[n] = k1 (L[n] - L[0])
+ F += (*li)->D1 * (distance - (*li)->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]
- Fy = F * (link[i]->mass1->posY - link[i]->mass2->posY)/distance; // Fy = F * Ly[n]/L[n]
+ Fx = F * ((*li)->mass1->posX - (*li)->mass2->posX)/distance; // Fx = F * Lx[n]/L[n]
+ Fy = F * ((*li)->mass1->posY - (*li)->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]->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]->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]
+ (*li)->mass1->forceX -= Fx; // Fx1[n] = -Fx
+ (*li)->mass1->forceX -= (*li)->D2*(*li)->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
+ (*li)->mass2->forceX += Fx; // Fx2[n] = Fx
+ (*li)->mass2->forceX -= (*li)->D2*(*li)->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1]
+ (*li)->mass1->forceY -= Fy; // Fy1[n] = -Fy
+ (*li)->mass1->forceY -= (*li)->D2*(*li)->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
+ (*li)->mass2->forceY += Fy; // Fy2[n] = Fy
+ (*li)->mass2->forceY -= (*li)->D2*(*li)->mass2->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
+ (*li)->distance_old = distance; // L[n-1] = L[n]
}
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, 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]
- Y_new = mass[i]->forceY * mass[i]->invM + 2*mass[i]->posY - mass[i]->posY2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
- mass[i]->posY2 = mass[i]->posY; // x[n-2] = x[n-1]
- mass[i]->posY = max(min(Y_new,Ymax),Ymin); // x[n-1] = x[n]
- mass[i]->speedY = mass[i]->posY - mass[i]->posY2; // vx[n] = x[n] - x[n-1]
+ if ((*mi)->mobile == 1) {
+ X_new = (*mi)->forceX * (*mi)->invM + 2*(*mi)->posX - (*mi)->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ (*mi)->posX2 = (*mi)->posX; // x[n-2] = x[n-1]
+ (*mi)->posX = max(min(X_new,Xmax),Xmin); // x[n-1] = x[n]
+ (*mi)->speedX = (*mi)->posX - (*mi)->posX2; // vx[n] = x[n] - x[n-1]
+ Y_new = (*mi)->forceY * (*mi)->invM + 2*(*mi)->posY - (*mi)->posY2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ (*mi)->posY2 = (*mi)->posY; // x[n-2] = x[n-1]
+ (*mi)->posY = max(min(Y_new,Ymax),Ymin); // x[n-1] = x[n]
+ (*mi)->speedY = (*mi)->posY - (*mi)->posY2; // vx[n] = x[n] - x[n-1]
}
- for (i=0; i<nb_mass; i++) {
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
// clear forces
- mass[i]->out_forceX = mass[i]->forceX;
- mass[i]->forceX = 0; // Fx[n] = 0
- mass[i]->out_forceY = mass[i]->forceY;
- mass[i]->forceY = 0; // Fy[n] = 0
+ (*mi)->out_forceX = (*mi)->forceX;
+ (*mi)->forceX = 0; // Fx[n] = 0
+ (*mi)->out_forceY = (*mi)->forceY;
+ (*mi)->forceY = 0; // Fy[n] = 0
}
}
@@ -231,34 +233,54 @@ protected:
void m_forceX(int argc,t_atom *argv)
{
- // add a force to mass(es) named Id
+ // add a force to mass(es) named Id or No
t_int i;
- const t_symbol *sym = GetSymbol(argv[0]);
+ const t_symbol *sym = GetASymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
error("forceX : Idmass value");
- for (i=0; i<nb_mass;i++)
- {
- if (sym == mass[i]->Id)
- mass[i]->forceX += GetFloat(argv[1]);
- }
+ if (sym ==0)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (GetInt(argv[0]) == (*mi)->nbr) {
+ (*mi)->forceX = GetFloat(argv[1]);
+ break;
+ }
+ }
+ else
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (sym == (*mi)->Id)
+ (*mi)->forceX = GetFloat(argv[1]);
+ }
}
void m_forceY(int argc,t_atom *argv)
{
- // add a force to mass(es) named Id
+ // add a force to mass(es) named Id or No
t_int i;
- const t_symbol *sym = GetSymbol(argv[0]);
+ const t_symbol *sym = GetASymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
- error("forceY : Idmass value");
+ error("forceX : Idmass value");
- for (i=0; i<nb_mass;i++)
- {
- if (sym == mass[i]->Id)
- mass[i]->forceY += GetFloat(argv[1]);
- }
+ if (sym ==0)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (GetInt(argv[0]) == (*mi)->nbr) {
+ (*mi)->forceY = GetFloat(argv[1]);
+ break;
+ }
+ }
+ else
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (sym == (*mi)->Id)
+ (*mi)->forceY = GetFloat(argv[1]);
+ }
}
void m_posX(int argc,t_atom *argv)
@@ -266,24 +288,25 @@ protected:
// displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetASymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
error("posX : Id/Nomass value");
if (GetFloat(argv[1]) < Xmax && GetFloat(argv[1]) > Xmin)
if (sym ==0)
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (GetInt(argv[0]) == mass[i]->nbr) {
- mass[i]->posX = GetFloat(argv[1]);
+ if (GetInt(argv[0]) == (*mi)->nbr) {
+ (*mi)->posX = GetFloat(argv[1]);
break;
}
}
else
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (sym == mass[i]->Id)
- mass[i]->posX = GetFloat(argv[1]);
+ if (sym == (*mi)->Id)
+ (*mi)->posX = GetFloat(argv[1]);
}
}
@@ -292,24 +315,25 @@ protected:
// displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetASymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
error("posY : Id/Nomass value");
if (GetFloat(argv[1]) < Ymax && GetFloat(argv[1]) > Ymin)
if (sym ==0)
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (GetInt(argv[0]) == mass[i]->nbr) {
- mass[i]->posY = GetFloat(argv[1]);
+ if (GetInt(argv[0]) == (*mi)->nbr) {
+ (*mi)->posY = GetFloat(argv[1]);
break;
}
}
else
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (sym == mass[i]->Id)
- mass[i]->posY = GetFloat(argv[1]);
+ if (sym == (*mi)->Id)
+ (*mi)->posY = GetFloat(argv[1]);
}
}
@@ -317,15 +341,16 @@ protected:
{
// set mass No to mobile
t_int i,aux;
+ t_mass **mi;
if (argc != 1)
error("setMobile : Idmass");
aux = GetInt(argv[0]);
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (mass[i]->nbr == aux)
- mass[i]->mobile = 1;
+ if ((*mi)->nbr == aux)
+ (*mi)->mobile = 1;
}
}
@@ -334,15 +359,16 @@ protected:
{
// set mass No to fixed
t_int i,aux;
+ t_mass **mi;
if (argc != 1)
error("setFixed : Idmass");
aux = GetAInt(argv[0]);
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (mass[i]->nbr == aux)
- mass[i]->mobile = 0;
+ if ((*mi)->nbr == aux)
+ (*mi)->mobile = 0;
}
}
@@ -353,14 +379,16 @@ protected:
t_int i,nb_link_delete=0;
t_atom sortie[6];
NEWARR(t_atom,aux,nb_link);
+ t_mass **mi;
+ t_link **li;
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);
+ for (i=0, li=link; i<nb_link; li++, i++) {
+ if ((*li)->mass1->nbr == GetInt(argv[0]) || (*li)->mass2->nbr == GetInt(argv[0])) {
+ SetFloat((aux[nb_link_delete]),(*li)->nbr);
nb_link_delete++;
}
}
@@ -369,16 +397,16 @@ protected:
m_delete_link(1,&aux[i]);
// delete mass
- for (i=0; i<nb_mass;i++)
- if (mass[i]->nbr == GetAInt(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);
- delete mass[i];
- mass[i] = mass[nb_mass-1];
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr == GetAInt(argv[0])) {
+ SetFloat((sortie[0]),(*mi)->nbr);
+ SetSymbol((sortie[1]),(*mi)->Id);
+ SetFloat((sortie[2]),(*mi)->mobile);
+ SetFloat((sortie[3]),1/(*mi)->invM);
+ SetFloat((sortie[4]),(*mi)->posX);
+ SetFloat((sortie[5]),(*mi)->posY);
+ delete (*mi);
+ (*mi) = mass[nb_mass-1];
nb_mass--;
ToOutAnything(1,S_Mass_deleted,6,sortie);
break;
@@ -429,18 +457,19 @@ protected:
t_int i;
t_mass *mass1 = NULL;
t_mass *mass2 = NULL;
-
+ t_mass **mi;
+
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
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[1])) // pointer to mass1
// we found mass1
- mass1 = mass[i];
- else if (mass[i]->nbr==GetInt(argv[2])) // pointer to mass2
+ mass1 = (*mi);
+ else if ((*mi)->nbr==GetInt(argv[2])) // pointer to mass2
// ... and mass2
- mass2 = mass[i];
+ mass2 = (*mi);
if (mass1 and mass2)
{
@@ -495,6 +524,7 @@ protected:
NEWARR(t_int,imass1,nb_mass);
NEWARR(t_int,imass2,nb_mass);
t_symbol *Id1, *Id2;
+ t_mass **mi;
if (argc < 6 || argc > 8)
error("ilink : Id Idmass1 Idmass2 K D1 D2 (Lmin Lmax)");
@@ -503,12 +533,12 @@ protected:
Id2 = GetSymbol(argv[2]);
ToOutAnything(1,S_iLink,0,aux);
- for (i=0;i<nb_mass;i++) {
- if (Id1 == mass[i]->Id) {
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ if (Id1 == (*mi)->Id) {
imass1[nbmass1]=i;
nbmass1++;
}
- if (Id2 == mass[i]->Id) {
+ if (Id2 == (*mi)->Id) {
imass2[nbmass2]=i;
nbmass2++;
}
@@ -543,14 +573,15 @@ protected:
// set rigidity of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_link **li;
if (argc != 2)
error("setK : IdLink Value");
- for (i=0; i<nb_link;i++)
+ for (i=0, li=link; i<nb_link; li++, i++)
{
- if (sym == link[i]->Id)
- link[i]->K1 = GetFloat(argv[1]);
+ if (sym == (*li)->Id)
+ (*li)->K1 = GetFloat(argv[1]);
}
}
@@ -559,14 +590,15 @@ protected:
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_link **li;
if (argc != 2)
error("setD : IdLink Value");
- for (i=0; i<nb_link;i++)
+ for (i=0, li=link; i<nb_link; li++, i++)
{
- if (sym == link[i]->Id)
- link[i]->D1 = GetFloat(argv[1]);
+ if (sym == (*li)->Id)
+ (*li)->D1 = GetFloat(argv[1]);
}
}
@@ -575,14 +607,15 @@ protected:
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_link **li;
if (argc != 2)
error("setD2 : IdLink Value");
- for (i=0; i<nb_link;i++)
+ for (i=0, li=link; i<nb_link; li++, i++)
{
- if (sym == link[i]->Id)
- link[i]->D2 = GetFloat(argv[1]);
+ if (sym == (*li)->Id)
+ (*li)->D2 = GetFloat(argv[1]);
}
}
@@ -591,21 +624,22 @@ protected:
// Delete link
t_int i;
t_atom sortie[7];
+ t_link **li;
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
+ for (i=0, li=link; i<nb_link; li++, i++)
+ if ((*li)->nbr == GetInt(argv[0])) {
+ SetFloat((sortie[0]),(*li)->nbr);
+ SetSymbol((sortie[1]),(*li)->Id);
+ SetFloat((sortie[2]),(*li)->mass1->nbr);
+ SetFloat((sortie[3]),(*li)->mass2->nbr);
+ SetFloat((sortie[4]),(*li)->K1);
+ SetFloat((sortie[5]),(*li)->D1);
+ SetFloat((sortie[6]),(*li)->D2);
+ delete (*li);
+ (*li)=link[nb_link-1]; // copy last link instead
nb_link--;
ToOutAnything(1,S_Link_deleted,7,sortie);
break;
@@ -623,41 +657,43 @@ protected:
t_atom sortie[5];
auxtype = GetSymbol(argv[0]);
auxarg = GetASymbol(argv[1]); //auxarg : & symbol, 0 else
+ t_mass **mi;
+ t_link **li;
if (argc == 1)
{
if (auxtype == S_massesPos) // get all masses positions
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->posX);
- SetFloat(sortie[2],mass[i]->posY);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->posX);
+ SetFloat(sortie[2],(*mi)->posY);
ToOutAnything(0,S_massesPos,3,sortie);
}
else if (auxtype == S_massesForces) // get all masses forces
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->out_forceX);
- SetFloat(sortie[2],mass[i]->out_forceY);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->out_forceX);
+ SetFloat(sortie[2],(*mi)->out_forceY);
ToOutAnything(0,S_massesForces,3,sortie);
}
else if (auxtype == S_linksPos) // get all links positions
- for (i=0; i<nb_link; i++)
+ for (i=0, li=link; i<nb_link; li++, i++)
{
- 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);
+ SetFloat(sortie[0],(*li)->nbr);
+ SetFloat(sortie[1],(*li)->mass1->posX);
+ SetFloat(sortie[2],(*li)->mass1->posY);
+ SetFloat(sortie[3],(*li)->mass2->posX);
+ SetFloat(sortie[4],(*li)->mass2->posY);
ToOutAnything(0,S_linksPos,5,sortie);
}
else // get all masses speeds
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->speedX);
- SetFloat(sortie[2],mass[i]->speedY);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->speedX);
+ SetFloat(sortie[2],(*mi)->speedY);
ToOutAnything(0,S_massesSpeeds,3,sortie);
}
}
@@ -666,12 +702,12 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[j]))
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->posX);
- SetFloat(sortie[2],mass[i]->posY);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->posX);
+ SetFloat(sortie[2],(*mi)->posY);
ToOutAnything(0,S_massesPosNo,3,sortie);
}
}
@@ -680,13 +716,13 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (auxarg2==mass[i]->Id)
+ if (auxarg2==(*mi)->Id)
{
- SetSymbol(sortie[0],mass[i]->Id);
- SetFloat(sortie[1],mass[i]->posX);
- SetFloat(sortie[2],mass[i]->posY);
+ SetSymbol(sortie[0],(*mi)->Id);
+ SetFloat(sortie[1],(*mi)->posX);
+ SetFloat(sortie[2],(*mi)->posY);
ToOutAnything(0,S_massesPosId,3,sortie);
}
}
@@ -698,12 +734,12 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[j]))
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->out_forceX);
- SetFloat(sortie[2],mass[i]->out_forceY);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->out_forceX);
+ SetFloat(sortie[2],(*mi)->out_forceY);
ToOutAnything(0,S_massesForcesNo,3,sortie);
}
}
@@ -712,13 +748,13 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (auxarg2==mass[i]->Id)
+ if (auxarg2==(*mi)->Id)
{
- SetSymbol(sortie[0],mass[i]->Id);
- SetFloat(sortie[1],mass[i]->out_forceX);
- SetFloat(sortie[2],mass[i]->out_forceY);
+ SetSymbol(sortie[0],(*mi)->Id);
+ SetFloat(sortie[1],(*mi)->out_forceX);
+ SetFloat(sortie[2],(*mi)->out_forceY);
ToOutAnything(0,S_massesForcesId,3,sortie);
}
}
@@ -730,14 +766,14 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_link;i++)
- if (link[i]->nbr==GetInt(argv[j]))
+ for (i=0, li=link; i<nb_link; li++, i++)
+ if ((*li)->nbr==GetInt(argv[j]))
{
- 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);
+ SetFloat(sortie[0],(*li)->nbr);
+ SetFloat(sortie[1],(*li)->mass1->posX);
+ SetFloat(sortie[2],(*li)->mass1->posY);
+ SetFloat(sortie[3],(*li)->mass2->posX);
+ SetFloat(sortie[4],(*li)->mass2->posY);
ToOutAnything(0,S_linksPosNo,5,sortie);
}
}
@@ -746,15 +782,15 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_link;i++)
+ for (i=0, li=link; i<nb_link; li++, i++)
{
- if (auxarg2==link[i]->Id)
+ if (auxarg2==(*li)->Id)
{
- 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);
+ SetSymbol(sortie[0],(*li)->Id);
+ SetFloat(sortie[1],(*li)->mass1->posX);
+ SetFloat(sortie[2],(*li)->mass1->posY);
+ SetFloat(sortie[3],(*li)->mass2->posX);
+ SetFloat(sortie[4],(*li)->mass2->posY);
ToOutAnything(0,S_linksPosId,5,sortie);
}
}
@@ -766,12 +802,12 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[j]))
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->speedX);
- SetFloat(sortie[2],mass[i]->speedY);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->speedX);
+ SetFloat(sortie[2],(*mi)->speedY);
ToOutAnything(0,S_massesSpeedsNo,3,sortie);
}
}
@@ -780,13 +816,13 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
{
- if (auxarg2==mass[i]->Id)
+ if (auxarg2==(*mi)->Id)
{
- SetSymbol(sortie[0],mass[i]->Id);
- SetFloat(sortie[1],mass[i]->speedX);
- SetFloat(sortie[2],mass[i]->speedY);
+ SetSymbol(sortie[0],(*mi)->Id);
+ SetFloat(sortie[1],(*mi)->speedX);
+ SetFloat(sortie[2],(*mi)->speedY);
ToOutAnything(0,S_massesSpeedsId,3,sortie);
}
}
@@ -802,10 +838,11 @@ protected:
{
NEWARR(t_atom,sortie,2*nb_mass);
t_int i;
+ t_mass **mi;
- for (i=0; i<nb_mass; i++) {
- SetFloat((sortie[2*i]),mass[i]->posX);
- SetFloat((sortie[2*i+1]),mass[i]->posY);
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ SetFloat((sortie[2*i]),(*mi)->posX);
+ SetFloat((sortie[2*i+1]),(*mi)->posY);
}
ToOutAnything(0, S_massesPosL, 2*nb_mass, sortie);
DELARR(sortie);
@@ -816,10 +853,11 @@ protected:
{
NEWARR(t_atom,sortie,2*nb_mass);
t_int i;
+ t_mass **mi;
- for (i=0; i<nb_mass; i++) {
- SetFloat((sortie[2*i]),mass[i]->out_forceX);
- SetFloat((sortie[2*i+1]),mass[i]->out_forceY);
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ SetFloat((sortie[2*i]),(*mi)->out_forceX);
+ SetFloat((sortie[2*i+1]),(*mi)->out_forceY);
}
ToOutAnything(0, S_massesForcesL, 2*nb_mass, sortie);
DELARR(sortie);
@@ -830,25 +868,27 @@ protected:
{
t_atom sortie[7];
t_int i;
-
- for (i=0; i<nb_mass; i++) {
- 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);
+ t_mass **mi;
+ t_link **li;
+
+ for (i=0, mi=mass; i<nb_mass; mi++, i++) {
+ SetFloat((sortie[0]),(*mi)->nbr);
+ SetSymbol((sortie[1]),(*mi)->Id);
+ SetFloat((sortie[2]),(*mi)->mobile);
+ SetFloat((sortie[3]),1/(*mi)->invM);
+ SetFloat((sortie[4]),(*mi)->posX);
+ SetFloat((sortie[5]),(*mi)->posY);
ToOutAnything(1, S_Mass, 6, sortie);
}
- for (i=0; i<nb_link; i++) {
- 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);
+ for (i=0, li=link; i<nb_link; li++, i++) {
+ SetFloat((sortie[0]),(*li)->nbr);
+ SetSymbol((sortie[1]),(*li)->Id);
+ SetFloat((sortie[2]),(*li)->mass1->nbr);
+ SetFloat((sortie[3]),(*li)->mass2->nbr);
+ SetFloat((sortie[4]),(*li)->K1);
+ SetFloat((sortie[5]),(*li)->D1);
+ SetFloat((sortie[6]),(*li)->D2);
ToOutAnything(1, S_Link, 7, sortie);
}
diff --git a/msd3D/02_msd3Dperf.pd b/msd3D/02_msd3Dperf.pd
index b52b0cd..65dc785 100644
--- a/msd3D/02_msd3Dperf.pd
+++ b/msd3D/02_msd3Dperf.pd
@@ -78,8 +78,6 @@
#X obj 52 678 route massesPos;
#X msg 52 425 bang \, get massesPos;
#X text 265 487 <-- Move masses;
-#X msg 143 479 forceX mob 100;
-#X msg 143 503 forceX mob -100;
#X floatatom 495 615 5 0 0 0 - - -;
#X floatatom 536 618 5 0 0 0 - - -;
#X floatatom 589 619 5 0 0 0 - - -;
@@ -89,6 +87,8 @@
#X msg 162 553 forceY mob -100;
#X msg 176 577 forceZ mob 100;
#X msg 175 601 forceZ mob -100;
+#X msg 143 479 forceX mob 100;
+#X msg 144 503 forceX mob -100;
#X connect 0 0 31 0;
#X connect 1 0 5 0;
#X connect 2 0 0 0;
@@ -104,7 +104,7 @@
#X connect 5 4 17 0;
#X connect 5 4 34 0;
#X connect 6 0 30 0;
-#X connect 7 0 51 0;
+#X connect 7 0 49 0;
#X connect 9 0 0 0;
#X connect 10 0 30 0;
#X connect 10 0 42 0;
@@ -145,14 +145,14 @@
#X connect 42 0 38 0;
#X connect 43 0 12 0;
#X connect 44 0 31 0;
-#X connect 46 0 31 0;
-#X connect 47 0 31 0;
-#X connect 48 0 51 1;
-#X connect 49 0 51 2;
-#X connect 50 0 51 3;
-#X connect 51 0 8 0;
-#X connect 52 0 39 1;
-#X connect 52 0 40 1;
+#X connect 46 0 49 1;
+#X connect 47 0 49 2;
+#X connect 48 0 49 3;
+#X connect 49 0 8 0;
+#X connect 50 0 39 1;
+#X connect 50 0 40 1;
+#X connect 51 0 31 0;
+#X connect 52 0 31 0;
#X connect 53 0 31 0;
#X connect 54 0 31 0;
#X connect 55 0 31 0;
diff --git a/msd3D/help-msd3D.pd b/msd3D/help-msd3D.pd
index 53382b5..547aad7 100644
--- a/msd3D/help-msd3D.pd
+++ b/msd3D/help-msd3D.pd
@@ -15,7 +15,6 @@
#X obj 61 403 cnv 15 610 210 empty empty DYNAMIC_SETTING 20 12 0 14
-262131 -66577 0;
#X text 350 467 \$2 : New value;
-#X text 348 503 \$1 : Id (symbol);
#X text 348 521 \$2 : New value;
#X msg 87 429 posX \$1 \$2;
#X text 350 431 Set position of mass(es);
@@ -63,18 +62,19 @@ their;
#X msg 83 548 Zmin \$1 \, Zmax \$1;
#X obj 33 821 msd3D;
#X text 350 449 \$1 : Id (symbol) or No;
-#X connect 1 0 51 0;
-#X connect 8 0 51 0;
-#X connect 14 0 51 0;
-#X connect 17 0 51 0;
-#X connect 19 0 51 0;
-#X connect 20 0 51 0;
-#X connect 23 0 51 0;
-#X connect 27 0 51 0;
-#X connect 30 0 51 0;
-#X connect 39 0 51 0;
-#X connect 45 0 51 0;
-#X connect 46 0 51 0;
+#X text 348 503 \$1 : Id (symbol) or No;
+#X connect 1 0 50 0;
+#X connect 8 0 50 0;
+#X connect 13 0 50 0;
+#X connect 16 0 50 0;
+#X connect 18 0 50 0;
+#X connect 19 0 50 0;
+#X connect 22 0 50 0;
+#X connect 26 0 50 0;
+#X connect 29 0 50 0;
+#X connect 38 0 50 0;
+#X connect 44 0 50 0;
+#X connect 45 0 50 0;
#X restore 158 305 pd masses;
#X text 12 305 HELP on masses --->;
#X text 11 336 HELP on links --->;
diff --git a/msd3D/imsd3Dball.pd b/msd3D/imsd3Dball.pd
index 324af35..90dca47 100644
--- a/msd3D/imsd3Dball.pd
+++ b/msd3D/imsd3Dball.pd
@@ -117,6 +117,7 @@
#X obj 116 38 t b b b b;
#X obj 442 294 t b;
#X text 310 286 Create window;
+#X text 416 489 NOT UPDATED FOR MSD VERSION 0.04;
#X connect 0 0 25 0;
#X connect 3 0 2 0;
#X connect 4 0 5 0;
diff --git a/msd3D/main.cpp b/msd3D/main.cpp
index 7b0d2f4..fff45bc 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.04 -- 26.04.2005
+ Version 0.05 -- 28.04.2005
*/
// include flext header
@@ -38,7 +38,7 @@
#include <math.h>
// define constants
-#define MSD3D_VERSION 0.04
+#define MSD3D_VERSION 0.05
#define nb_max_link 4000
#define nb_max_mass 4000
#define Id_length 20
@@ -120,13 +120,14 @@ protected:
void m_reset()
{
t_int i;
-// t_atom sortie[0];
+ t_mass **mi;
+ t_link **li;
- for (i=0; i<nb_mass; i++) {
- delete mass[i];
+ for (i=0, mi=mass; i<nb_mass;mi++, i++) {
+ delete (*mi);
}
- for (i=0; i<nb_link; i++) {
- delete link[i];
+ for (i=0, li=link; i<nb_link;li++, i++) {
+ delete (*li);
}
ToOutAnything(1,S_Reset,0,NULL);
nb_link = 0;
@@ -141,66 +142,67 @@ protected:
{
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;
+ t_mass **mi;
+ t_link **li;
- for (i=0; i<nb_link; i++) {
+ for (i=0, li=link; i<nb_link;li++, 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]
- if (distance < link[i]->long_min || distance > link[i]->long_max) {
+ distance = sqrt(pow((*li)->mass1->posX-(*li)->mass2->posX,2) + pow((*li)->mass1->posY
+ -(*li)->mass2->posY,2) + pow((*li)->mass1->posZ-(*li)->mass2->posZ,2)); // L[n]
+ if (distance < (*li)->long_min || distance > (*li)->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])
+ F = (*li)->K1 * (distance - (*li)->longueur) ; // F = K1(L[n] - L[0])
+ F += (*li)->D1 * (distance - (*li)->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]
+ Fx = F * ((*li)->mass1->posX - (*li)->mass2->posX)/distance; // Fx[n] = F * Lx[n]/L[n]
+ Fy = F * ((*li)->mass1->posY - (*li)->mass2->posY)/distance; // Fy[n] = F * Ly[n]/L[n]
+ Fz = F * ((*li)->mass1->posZ - (*li)->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]->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]->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]->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]
+ (*li)->mass1->forceX -= Fx; // Fx1[n] = -Fx
+ (*li)->mass1->forceX -= (*li)->D2*(*li)->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1]
+ (*li)->mass2->forceX += Fx; // Fx2[n] = Fx
+ (*li)->mass2->forceX -= (*li)->D2*(*li)->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1]
+ (*li)->mass1->forceY -= Fy; // Fy1[n] = -Fy
+ (*li)->mass1->forceY -= (*li)->D2*(*li)->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1]
+ (*li)->mass2->forceY += Fy; // Fy2[n] = Fy
+ (*li)->mass2->forceY -= (*li)->D2*(*li)->mass2->speedY; // Fy2[n] = Fy2[n] - D2 * vy2[n-1]
+ (*li)->mass1->forceZ -= Fz; // Fz1[n] = -Fz
+ (*li)->mass1->forceZ -= (*li)->D2*(*li)->mass1->speedZ; // Fz1[n] = Fz1[n] - D2 * vz1[n-1]
+ (*li)->mass2->forceZ += Fz; // Fz2[n] = Fz
+ (*li)->mass2->forceZ -= (*li)->D2*(*li)->mass2->speedZ; // Fz2[n] = Fz2[n] - D2 * vz2[n-1]
+ (*li)->distance_old = distance; // L[n-1] = L[n]
}
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, 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]
- Y_new = mass[i]->forceY * mass[i]->invM + 2*mass[i]->posY - mass[i]->posY2; // y[n] =Fy[n]/M+2y[n]-y[n-1]
- mass[i]->posY2 = mass[i]->posY; // y[n-2] = y[n-1]
- mass[i]->posY = max(min(Y_new,Ymax),Ymin); // y[n-1] = y[n]
- mass[i]->speedY = mass[i]->posY - mass[i]->posY2; // vy[n] = y[n] - y[n-1]
- Z_new = mass[i]->forceZ * mass[i]->invM + 2*mass[i]->posZ - mass[i]->posZ2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
- mass[i]->posZ2 = mass[i]->posZ; // z[n-2] = z[n-1]
- mass[i]->posZ = max(min(Z_new,Zmax),Zmin); // z[n-1] = z[n]
- mass[i]->speedZ = mass[i]->posZ - mass[i]->posZ2; // vz[n] = z[n] - z[n-1]
+ if ((*mi)->mobile == 1) {
+ X_new = (*mi)->forceX * (*mi)->invM + 2*(*mi)->posX - (*mi)->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ (*mi)->posX2 = (*mi)->posX; // x[n-2] = x[n-1]
+ (*mi)->posX = max(min(X_new,Xmax),Xmin); // x[n-1] = x[n]
+ (*mi)->speedX = (*mi)->posX - (*mi)->posX2; // vx[n] = x[n] - x[n-1]
+ Y_new = (*mi)->forceY * (*mi)->invM + 2*(*mi)->posY - (*mi)->posY2; // y[n] =Fy[n]/M+2y[n]-y[n-1]
+ (*mi)->posY2 = (*mi)->posY; // y[n-2] = y[n-1]
+ (*mi)->posY = max(min(Y_new,Ymax),Ymin); // y[n-1] = y[n]
+ (*mi)->speedY = (*mi)->posY - (*mi)->posY2; // vy[n] = y[n] - y[n-1]
+ Z_new = (*mi)->forceZ * (*mi)->invM + 2*(*mi)->posZ - (*mi)->posZ2; // x[n] =Fx[n]/M+2x[n]-x[n-1]
+ (*mi)->posZ2 = (*mi)->posZ; // z[n-2] = z[n-1]
+ (*mi)->posZ = max(min(Z_new,Zmax),Zmin); // z[n-1] = z[n]
+ (*mi)->speedZ = (*mi)->posZ - (*mi)->posZ2; // vz[n] = z[n] - z[n-1]
}
- for (i=0; i<nb_mass; i++) {
+ for (i=0, mi=mass; i<nb_mass;mi++, i++) {
// clear forces
- mass[i]->out_forceX = mass[i]->forceX;
- mass[i]->forceX = 0;
- mass[i]->out_forceY = mass[i]->forceY;
- mass[i]->forceY = 0;
- mass[i]->out_forceZ = mass[i]->forceZ;
- mass[i]->forceZ = 0;
+ (*mi)->out_forceX = (*mi)->forceX;
+ (*mi)->forceX = 0;
+ (*mi)->out_forceY = (*mi)->forceY;
+ (*mi)->forceY = 0;
+ (*mi)->out_forceZ = (*mi)->forceZ;
+ (*mi)->forceZ = 0;
}
}
@@ -251,50 +253,80 @@ protected:
void m_forceX(int argc,t_atom *argv)
{
- // add a force to mass(es) named Id
+ // add a force to mass(es) named Id or No
t_int i;
- const t_symbol *sym = GetSymbol(argv[0]);
+ const t_symbol *sym = GetASymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
error("forceX : Idmass value");
- for (i=0; i<nb_mass;i++)
- {
- if (sym == mass[i]->Id)
- mass[i]->forceX += GetFloat(argv[1]);
- }
+ if (sym ==0)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (GetInt(argv[0]) == (*mi)->nbr) {
+ (*mi)->forceX = GetFloat(argv[1]);
+ break;
+ }
+ }
+ else
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (sym == (*mi)->Id)
+ (*mi)->forceX = GetFloat(argv[1]);
+ }
}
void m_forceY(int argc,t_atom *argv)
{
- // add a force to mass(es) named Id
+ // add a force to mass(es) named Id or No
t_int i;
- const t_symbol *sym = GetSymbol(argv[0]);
+ const t_symbol *sym = GetASymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
- error("forceY : Idmass value");
+ error("forceX : Idmass value");
- for (i=0; i<nb_mass;i++)
- {
- if (sym == mass[i]->Id)
- mass[i]->forceY += GetFloat(argv[1]);
- }
+ if (sym ==0)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (GetInt(argv[0]) == (*mi)->nbr) {
+ (*mi)->forceY = GetFloat(argv[1]);
+ break;
+ }
+ }
+ else
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (sym == (*mi)->Id)
+ (*mi)->forceY = GetFloat(argv[1]);
+ }
}
void m_forceZ(int argc,t_atom *argv)
{
- // add a force to mass(es) named Id
+ // add a force to mass(es) named Id or No
t_int i;
- const t_symbol *sym = GetSymbol(argv[0]);
+ const t_symbol *sym = GetASymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
- error("forceZ : Idmass value");
+ error("forceX : Idmass value");
- for (i=0; i<nb_mass;i++)
- {
- if (sym == mass[i]->Id)
- mass[i]->forceZ += GetFloat(argv[1]);
- }
+ if (sym ==0)
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (GetInt(argv[0]) == (*mi)->nbr) {
+ (*mi)->forceZ = GetFloat(argv[1]);
+ break;
+ }
+ }
+ else
+ for (i=0, mi=mass; i<nb_mass; mi++, i++)
+ {
+ if (sym == (*mi)->Id)
+ (*mi)->forceZ = GetFloat(argv[1]);
+ }
}
void m_posX(int argc,t_atom *argv)
@@ -302,15 +334,16 @@ protected:
// displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
error("posX : Idmass value");
if (GetFloat(argv[1]) < Xmax && GetFloat(argv[1]) > Xmin)
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- if (sym == mass[i]->Id)
- mass[i]->posX = GetAFloat(argv[1]);
+ if (sym == (*mi)->Id)
+ (*mi)->posX = GetAFloat(argv[1]);
}
}
@@ -319,15 +352,16 @@ protected:
// displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
error("posY : Idmass value");
if (GetFloat(argv[1]) < Ymax && GetFloat(argv[1]) > Ymin)
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- if (sym == mass[i]->Id)
- mass[i]->posY = GetFloat(argv[1]);
+ if (sym == (*mi)->Id)
+ (*mi)->posY = GetFloat(argv[1]);
}
}
@@ -337,15 +371,16 @@ protected:
// displace mass(es) named Id to a certain position
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_mass **mi;
if (argc != 2)
error("posZ : Idmass value");
if (GetFloat(argv[1]) < Zmax && GetFloat(argv[1]) > Zmin)
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- if (sym == mass[i]->Id)
- mass[i]->posZ = GetFloat(argv[1]);
+ if (sym == (*mi)->Id)
+ (*mi)->posZ = GetFloat(argv[1]);
}
}
@@ -354,15 +389,16 @@ protected:
{
// set mass No to mobile
t_int i,aux;
+ t_mass **mi;
if (argc != 1)
error("setMobile : Idmass");
aux = GetInt(argv[0]);
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- if (mass[i]->nbr == aux)
- mass[i]->mobile = 1;
+ if ((*mi)->nbr == aux)
+ (*mi)->mobile = 1;
}
}
@@ -371,15 +407,16 @@ protected:
{
// set mass No to fixed
t_int i,aux;
+ t_mass **mi;
if (argc != 1)
error("setFixed : Idmass");
aux = GetAInt(argv[0]);
- for (i=0; i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- if (mass[i]->nbr == aux)
- mass[i]->mobile = 0;
+ if ((*mi)->nbr == aux)
+ (*mi)->mobile = 0;
}
}
@@ -390,14 +427,16 @@ protected:
t_int i,nb_link_delete=0;
t_atom sortie[7];
NEWARR(t_atom,aux,nb_link);
+ t_mass **mi;
+ t_link **li;
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);
+ for (i=0, li=link; i<nb_link;li++, i++) {
+ if ((*li)->mass1->nbr == GetInt(argv[0]) || (*li)->mass2->nbr == GetInt(argv[0])) {
+ SetFloat((aux[nb_link_delete]),(*li)->nbr);
nb_link_delete++;
}
}
@@ -406,17 +445,17 @@ protected:
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
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
+ if ((*mi)->nbr == GetInt(argv[0])) {
+ SetFloat((sortie[0]),(*mi)->nbr);
+ SetSymbol((sortie[1]),(*mi)->Id);
+ SetFloat((sortie[2]),(*mi)->mobile);
+ SetFloat((sortie[3]),1/(*mi)->invM);
+ SetFloat((sortie[4]),(*mi)->posX);
+ SetFloat((sortie[5]),(*mi)->posY);
+ SetFloat((sortie[6]),(*mi)->posZ);
+ delete (*mi);
+ (*mi) = mass[nb_mass-1]; // copy last mass indeed
nb_mass--;
ToOutAnything(1,S_Mass_deleted,7,sortie);
break;
@@ -482,18 +521,19 @@ protected:
t_int i;
t_mass *mass1 = NULL;
t_mass *mass2 = NULL;
-
+ t_mass **mi;
+
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
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[1])) // pointer to mass1
// we found mass1
- mass1 = mass[i];
- else if (mass[i]->nbr==GetInt(argv[2])) // pointer to mass2
+ mass1 = (*mi);
+ else if ((*mi)->nbr==GetInt(argv[2])) // pointer to mass2
// ... and mass2
- mass2 = mass[i];
+ mass2 = (*mi);
if (mass1 and mass2)
{
@@ -549,6 +589,7 @@ protected:
NEWARR(t_int,imass1,nb_mass);
NEWARR(t_int,imass2,nb_mass);
t_symbol *Id1, *Id2;
+ t_mass **mi;
if (argc < 6 || argc > 8)
error("ilink : Id Idmass1 Idmass2 K D1 D2 (Lmin Lmax)");
@@ -557,12 +598,12 @@ protected:
Id2 = GetSymbol(argv[2]);
ToOutAnything(1,S_iLink,0,aux);
- for (i=0;i<nb_mass;i++) {
- if (Id1 == mass[i]->Id) {
+ for (i=0, mi=mass; i<nb_mass;mi++, i++) {
+ if (Id1 == (*mi)->Id) {
imass1[nbmass1]=i;
nbmass1++;
}
- if (Id2 == mass[i]->Id) {
+ if (Id2 == (*mi)->Id) {
imass2[nbmass2]=i;
nbmass2++;
}
@@ -597,14 +638,15 @@ protected:
// set rigidity of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_link **li;
if (argc != 2)
error("setK : IdLink Value");
- for (i=0; i<nb_link;i++)
+ for (i=0, li=link; i<nb_link;li++, i++)
{
- if (sym == link[i]->Id)
- link[i]->K1 = GetFloat(argv[1]);
+ if (sym == (*li)->Id)
+ (*li)->K1 = GetFloat(argv[1]);
}
}
@@ -613,14 +655,15 @@ protected:
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_link **li;
if (argc != 2)
error("setD : IdLink Value");
- for (i=0; i<nb_link;i++)
+ for (i=0, li=link; i<nb_link;li++, i++)
{
- if (sym == link[i]->Id)
- link[i]->D1 = GetFloat(argv[1]);
+ if (sym == (*li)->Id)
+ (*li)->D1 = GetFloat(argv[1]);
}
}
@@ -629,14 +672,15 @@ protected:
// set damping of link(s) named Id
t_int i;
const t_symbol *sym = GetSymbol(argv[0]);
+ t_link **li;
if (argc != 2)
error("setD2 : IdLink Value");
- for (i=0; i<nb_link;i++)
+ for (i=0, li=link; i<nb_link;li++, i++)
{
- if (sym == link[i]->Id)
- link[i]->D2 = GetFloat(argv[1]);
+ if (sym == (*li)->Id)
+ (*li)->D2 = GetFloat(argv[1]);
}
}
@@ -645,21 +689,22 @@ protected:
// Delete link
t_int i;
t_atom sortie[7];
+ t_link **li;
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
+ for (i=0, li=link; i<nb_link;li++, i++)
+ if ((*li)->nbr == GetInt(argv[0])) {
+ SetFloat((sortie[0]),(*li)->nbr);
+ SetSymbol((sortie[1]),(*li)->Id);
+ SetFloat((sortie[2]),(*li)->mass1->nbr);
+ SetFloat((sortie[3]),(*li)->mass2->nbr);
+ SetFloat((sortie[4]),(*li)->K1);
+ SetFloat((sortie[5]),(*li)->D1);
+ SetFloat((sortie[6]),(*li)->D2);
+ delete (*li);
+ (*li)=link[nb_link-1]; // copy last link instead
nb_link--;
ToOutAnything(1,S_Link_deleted,7,sortie);
break;
@@ -677,46 +722,48 @@ protected:
t_atom sortie[7];
auxtype = GetSymbol(argv[0]);
auxarg = GetASymbol(argv[1]); //auxarg : & symbol, 0 else
+ t_mass **mi;
+ t_link **li;
if (argc == 1)
{
if (auxtype == S_massesPos)// get all masses positions
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->posX);
- SetFloat(sortie[2],mass[i]->posY);
- SetFloat(sortie[3],mass[i]->posZ);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->posX);
+ SetFloat(sortie[2],(*mi)->posY);
+ SetFloat(sortie[3],(*mi)->posZ);
ToOutAnything(0,S_massesPos,4,sortie);
}
else if (auxtype == S_massesForces)// get all masses forces
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->out_forceX);
- SetFloat(sortie[2],mass[i]->out_forceY);
- SetFloat(sortie[3],mass[i]->out_forceZ);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->out_forceX);
+ SetFloat(sortie[2],(*mi)->out_forceY);
+ SetFloat(sortie[3],(*mi)->out_forceZ);
ToOutAnything(0,S_massesForces,4,sortie);
}
else if (auxtype == S_linksPos)// get all links positions
- for (i=0; i<nb_link; i++)
+ for (i=0, li=link; i<nb_link;li++, i++)
{
- 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]->mass1->posZ);
- SetFloat(sortie[4],link[i]->mass2->posX);
- SetFloat(sortie[5],link[i]->mass2->posY);
- SetFloat(sortie[6],link[i]->mass2->posZ);
+ SetFloat(sortie[0],(*li)->nbr);
+ SetFloat(sortie[1],(*li)->mass1->posX);
+ SetFloat(sortie[2],(*li)->mass1->posY);
+ SetFloat(sortie[3],(*li)->mass1->posZ);
+ SetFloat(sortie[4],(*li)->mass2->posX);
+ SetFloat(sortie[5],(*li)->mass2->posY);
+ SetFloat(sortie[6],(*li)->mass2->posZ);
ToOutAnything(0,S_linksPos,7,sortie);
}
else // get all masses speeds
- for (i=0; i<nb_mass; i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->speedX);
- SetFloat(sortie[2],mass[i]->speedY);
- SetFloat(sortie[3],mass[i]->speedZ);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->speedX);
+ SetFloat(sortie[2],(*mi)->speedY);
+ SetFloat(sortie[3],(*mi)->speedZ);
ToOutAnything(0,S_massesSpeeds,4,sortie);
}
}
@@ -725,13 +772,13 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[j]))
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->posX);
- SetFloat(sortie[2],mass[i]->posY);
- SetFloat(sortie[3],mass[i]->posZ);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->posX);
+ SetFloat(sortie[2],(*mi)->posY);
+ SetFloat(sortie[3],(*mi)->posZ);
ToOutAnything(0,S_massesPosNo,4,sortie);
}
}
@@ -740,14 +787,14 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- if (auxarg2==mass[i]->Id)
+ if (auxarg2==(*mi)->Id)
{
- SetSymbol(sortie[0],mass[i]->Id);
- SetFloat(sortie[1],mass[i]->posX);
- SetFloat(sortie[2],mass[i]->posY);
- SetFloat(sortie[3],mass[i]->posZ);
+ SetSymbol(sortie[0],(*mi)->Id);
+ SetFloat(sortie[1],(*mi)->posX);
+ SetFloat(sortie[2],(*mi)->posY);
+ SetFloat(sortie[3],(*mi)->posZ);
ToOutAnything(0,S_massesPosId,4,sortie);
}
}
@@ -759,13 +806,13 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[j]))
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->out_forceX);
- SetFloat(sortie[2],mass[i]->out_forceY);
- SetFloat(sortie[3],mass[i]->out_forceZ);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->out_forceX);
+ SetFloat(sortie[2],(*mi)->out_forceY);
+ SetFloat(sortie[3],(*mi)->out_forceZ);
ToOutAnything(0,S_massesForcesNo,4,sortie);
}
}
@@ -774,14 +821,14 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- if (auxarg2==mass[i]->Id)
+ if (auxarg2==(*mi)->Id)
{
- SetSymbol(sortie[0],mass[i]->Id);
- SetFloat(sortie[1],mass[i]->out_forceX);
- SetFloat(sortie[2],mass[i]->out_forceY);
- SetFloat(sortie[3],mass[i]->out_forceZ);
+ SetSymbol(sortie[0],(*mi)->Id);
+ SetFloat(sortie[1],(*mi)->out_forceX);
+ SetFloat(sortie[2],(*mi)->out_forceY);
+ SetFloat(sortie[3],(*mi)->out_forceZ);
ToOutAnything(0,S_massesForcesId,4,sortie);
}
}
@@ -793,16 +840,16 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_link;i++)
- if (link[i]->nbr==GetInt(argv[j]))
+ for (i=0, li=link; i<nb_link;li++, i++)
+ if ((*li)->nbr==GetInt(argv[j]))
{
- 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]->mass1->posZ);
- SetFloat(sortie[4],link[i]->mass2->posX);
- SetFloat(sortie[5],link[i]->mass2->posY);
- SetFloat(sortie[6],link[i]->mass2->posZ);
+ SetFloat(sortie[0],(*li)->nbr);
+ SetFloat(sortie[1],(*li)->mass1->posX);
+ SetFloat(sortie[2],(*li)->mass1->posY);
+ SetFloat(sortie[3],(*li)->mass1->posZ);
+ SetFloat(sortie[4],(*li)->mass2->posX);
+ SetFloat(sortie[5],(*li)->mass2->posY);
+ SetFloat(sortie[6],(*li)->mass2->posZ);
ToOutAnything(0,S_linksPosNo,7,sortie);
}
}
@@ -811,17 +858,17 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_link;i++)
+ for (i=0, li=link; i<nb_link;li++, i++)
{
- if (auxarg2==link[i]->Id)
+ if (auxarg2==(*li)->Id)
{
- 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]->mass1->posZ);
- SetFloat(sortie[4],link[i]->mass2->posX);
- SetFloat(sortie[5],link[i]->mass2->posY);
- SetFloat(sortie[6],link[i]->mass2->posZ);
+ SetSymbol(sortie[0],(*li)->Id);
+ SetFloat(sortie[1],(*li)->mass1->posX);
+ SetFloat(sortie[2],(*li)->mass1->posY);
+ SetFloat(sortie[3],(*li)->mass1->posZ);
+ SetFloat(sortie[4],(*li)->mass2->posX);
+ SetFloat(sortie[5],(*li)->mass2->posY);
+ SetFloat(sortie[6],(*li)->mass2->posZ);
ToOutAnything(0,S_linksPosId,7,sortie);
}
}
@@ -833,13 +880,13 @@ protected:
if (auxarg == 0) // No
{
for (j = 1; j<argc; j++)
- for (i=0;i<nb_mass;i++)
- if (mass[i]->nbr==GetInt(argv[j]))
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
+ if ((*mi)->nbr==GetInt(argv[j]))
{
- SetFloat(sortie[0],mass[i]->nbr);
- SetFloat(sortie[1],mass[i]->speedX);
- SetFloat(sortie[2],mass[i]->speedY);
- SetFloat(sortie[3],mass[i]->speedZ);
+ SetFloat(sortie[0],(*mi)->nbr);
+ SetFloat(sortie[1],(*mi)->speedX);
+ SetFloat(sortie[2],(*mi)->speedY);
+ SetFloat(sortie[3],(*mi)->speedZ);
ToOutAnything(0,S_massesSpeedsNo,4,sortie);
}
}
@@ -848,14 +895,14 @@ protected:
for (j = 1; j<argc; j++)
{
auxarg2 = GetSymbol(argv[j]);
- for (i=0;i<nb_mass;i++)
+ for (i=0, mi=mass; i<nb_mass;mi++, i++)
{
- if (auxarg2==mass[i]->Id)
+ if (auxarg2==(*mi)->Id)
{
- SetSymbol(sortie[0],mass[i]->Id);
- SetFloat(sortie[1],mass[i]->speedX);
- SetFloat(sortie[2],mass[i]->speedY);
- SetFloat(sortie[3],mass[i]->speedZ);
+ SetSymbol(sortie[0],(*mi)->Id);
+ SetFloat(sortie[1],(*mi)->speedX);
+ SetFloat(sortie[2],(*mi)->speedY);
+ SetFloat(sortie[3],(*mi)->speedZ);
ToOutAnything(0,S_massesSpeedsId,4,sortie);
}
}
@@ -871,11 +918,12 @@ protected:
{
NEWARR(t_atom,sortie,3*nb_mass);
t_int i;
+ t_mass **mi;
- for (i=0; i<nb_mass; i++) {
- SetFloat((sortie[3*i]),mass[i]->posX);
- SetFloat((sortie[3*i+1]),mass[i]->posY);
- SetFloat((sortie[3*i+2]),mass[i]->posZ);
+ for (i=0, mi=mass; i<nb_mass;mi++, i++) {
+ SetFloat((sortie[3*i]),(*mi)->posX);
+ SetFloat((sortie[3*i+1]),(*mi)->posY);
+ SetFloat((sortie[3*i+2]),(*mi)->posZ);
}
ToOutAnything(0, S_massesPosL, 3*nb_mass, sortie);
DELARR(sortie);
@@ -886,11 +934,12 @@ protected:
{
NEWARR(t_atom,sortie,3*nb_mass);
t_int i;
+ t_mass **mi;
- for (i=0; i<nb_mass; i++) {
- SetFloat((sortie[3*i]),mass[i]->out_forceX);
- SetFloat((sortie[3*i+1]),mass[i]->out_forceY);
- SetFloat((sortie[3*i+2]),mass[i]->out_forceZ);
+ for (i=0, mi=mass; i<nb_mass;mi++, i++) {
+ SetFloat((sortie[3*i]),(*mi)->out_forceX);
+ SetFloat((sortie[3*i+1]),(*mi)->out_forceY);
+ SetFloat((sortie[3*i+2]),(*mi)->out_forceZ);
}
ToOutAnything(0, S_massesForcesL, 3*nb_mass, sortie);
DELARR(sortie);
@@ -901,26 +950,28 @@ protected:
{
t_atom sortie[7];
t_int i;
+ t_mass **mi;
+ t_link **li;
- for (i=0; i<nb_mass; i++) {
- 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);
+ for (i=0, mi=mass; i<nb_mass;mi++, i++) {
+ SetFloat((sortie[0]),(*mi)->nbr);
+ SetSymbol((sortie[1]),(*mi)->Id);
+ SetFloat((sortie[2]),(*mi)->mobile);
+ SetFloat((sortie[3]),1/(*mi)->invM);
+ SetFloat((sortie[4]),(*mi)->posX);
+ SetFloat((sortie[5]),(*mi)->posY);
+ SetFloat((sortie[6]),(*mi)->posZ);
ToOutAnything(1, S_Mass, 7, sortie);
}
- for (i=0; i<nb_link; i++) {
- 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);
+ for (i=0, li=link; i<nb_link;li++, i++) {
+ SetFloat((sortie[0]),(*li)->nbr);
+ SetSymbol((sortie[1]),(*li)->Id);
+ SetFloat((sortie[2]),(*li)->mass1->nbr);
+ SetFloat((sortie[3]),(*li)->mass2->nbr);
+ SetFloat((sortie[4]),(*li)->K1);
+ SetFloat((sortie[5]),(*li)->D1);
+ SetFloat((sortie[6]),(*li)->D2);
ToOutAnything(1, S_Link, 7, sortie);
}
diff --git a/msd3D/msd3Dball.pd b/msd3D/msd3Dball.pd
index 1ffcb08..3a1c863 100644
--- a/msd3D/msd3Dball.pd
+++ b/msd3D/msd3Dball.pd
@@ -168,6 +168,7 @@ mass fix 0 100 70 30 20 \, mass fix 0 100 70 70 20;
#X msg 429 544 view 0 3 0 0 0 0 0 0 1;
#X msg 429 523 view 0 0 1 0 0 0 0 1 0;
#X msg 429 500 view 3 0 0.5 0 0 0 0 0 1;
+#X text 287 627 NOT UPDATED FOR MSD VERSION 0.04;
#X connect 0 0 26 0;
#X connect 3 0 2 0;
#X connect 4 0 5 0;