diff options
author | Cyrille Henry <nusmuk@users.sourceforge.net> | 2013-04-09 16:51:04 +0000 |
---|---|---|
committer | Cyrille Henry <nusmuk@users.sourceforge.net> | 2013-04-09 16:51:04 +0000 |
commit | 81aaebcdc9432022b03af5895132f0d1d47c5171 (patch) | |
tree | b37cf10a85327161a963f7dee2d73ac3b578d91e | |
parent | 7d4780c91c33c3aa7e1663762783350935dc8d04 (diff) |
bugfix, add more test on function argument number and various stuf
svn path=/trunk/externals/pmpd/; revision=17079
-rw-r--r-- | pmpd2d.c | 1 | ||||
-rw-r--r-- | pmpd2d_core.c | 91 | ||||
-rw-r--r-- | pmpd2d_set.c | 95 | ||||
-rw-r--r-- | pmpd2d_various.c | 30 | ||||
-rw-r--r-- | pmpd3d.c | 3 | ||||
-rw-r--r-- | pmpd3d_core.c | 4 | ||||
-rw-r--r-- | pmpd3d_set.c | 48 | ||||
-rw-r--r-- | pmpd3d_various.c | 40 |
8 files changed, 169 insertions, 143 deletions
@@ -4,6 +4,7 @@ pmpd = physical modeling for pure data
Written by Cyrille Henry (ch@chnry.net)
+ with help from Nicolas Mongermont
Get sources on pd svn on sourceforge.
diff --git a/pmpd2d_core.c b/pmpd2d_core.c index 5f58d3e..5efaf19 100644 --- a/pmpd2d_core.c +++ b/pmpd2d_core.c @@ -79,12 +79,30 @@ void pmpd2d_bang(t_pmpd2d *x) // compute new masses position if (x->mass[i].mobile > 0) // only if mobile { + // amplify force that opose to movement + if (x->mass[i].overdamp != 0) + { + tmp = x->mass[i].speedX * x->mass[i].forceX + x->mass[i].speedY * x->mass[i].forceY; + tmp = min(0,tmp); // overdamped only if force opose movment + tmp *= -x->mass[i].overdamp; + tmp += 1; + x->mass[i].forceX *= tmp; + x->mass[i].forceY *= tmp; + } + + // compute new velocity thanks to forces. (Forces = M * acceleration) x->mass[i].speedX += x->mass[i].forceX * x->mass[i].invM; x->mass[i].speedY += x->mass[i].forceY * x->mass[i].invM; + + // no need to reset force to 0, because we compute a new force latter thanks to velocity damping // x->mass[i].forceX = 0; - // x->mass[i].forceY = 0; + // x->mass[i].forceY = 0; + + // compute new speed thanks to new velocity x->mass[i].posX += x->mass[i].speedX ; x->mass[i].posY += x->mass[i].speedY ; + + // space limitation if ( (x->mass[i].posX < x->minX) || (x->mass[i].posX > x->maxX) || (x->mass[i].posY < x->minY) || (x->mass[i].posY > x->maxY) ) { tmpX = min(x->maxX,max(x->minX,x->mass[i].posX)); @@ -93,9 +111,13 @@ void pmpd2d_bang(t_pmpd2d *x) x->mass[i].speedY -= x->mass[i].posY - tmpY; x->mass[i].posX = tmpX; x->mass[i].posY = tmpY; - } + } + + // velocity damping of every masse (set a new force) x->mass[i].forceX = -x->mass[i].D2 * x->mass[i].speedX; x->mass[i].forceY = -x->mass[i].D2 * x->mass[i].speedY; + + // offset on velocity damping (to impose a specific velocity) speed = sqrt(x->mass[i].speedX * x->mass[i].speedX + x->mass[i].speedY * x->mass[i].speedY); if (speed != 0) { x->mass[i].forceX += x->mass[i].D2offset * (x->mass[i].speedX/speed); @@ -104,41 +126,45 @@ void pmpd2d_bang(t_pmpd2d *x) } for (i=0; i<x->nb_link; i++) - // compute link forces - { - Lx = x->link[i].mass1->posX - x->link[i].mass2->posX; - Ly = x->link[i].mass1->posY - x->link[i].mass2->posY; - L = sqrt( sqr(Lx) + sqr(Ly) ); - - if ( (L >= x->link[i].Lmin) && (L < x->link[i].Lmax) && (L != 0)) + { // compute link forces + if (x->link[i].active == 1) { - if (x->link[i].lType == 2) - { // K et D viennent d'une table - F = x->link[i].D * tabread2(x, (L - x->link[i].distance) / x->link[i].D_L, x->link[i].arrayD); - F += x->link[i].K * tabread2(x, L / x->link[i].K_L, x->link[i].arrayK); - } - else - { - F = x->link[i].D * (L - x->link[i].distance) ; - F += x->link[i].K * pow_ch( L - x->link[i].L, x->link[i].Pow); - } + Lx = x->link[i].mass1->posX - x->link[i].mass2->posX; + Ly = x->link[i].mass1->posY - x->link[i].mass2->posY; + L = sqrt( sqr(Lx) + sqr(Ly) ); + + if ( (L >= x->link[i].Lmin) && (L < x->link[i].Lmax) && (L != 0)) + { + if (x->link[i].lType == 2) + { // K et D viennent d'une table + F = x->link[i].D * tabread2(x, (L - x->link[i].distance) / x->link[i].D_L, x->link[i].arrayD); + F += x->link[i].K * tabread2(x, L / x->link[i].K_L, x->link[i].arrayK); + } + else + { + F = x->link[i].D * (L - x->link[i].distance) ; + F += x->link[i].K * pow_ch( L - x->link[i].L, x->link[i].Pow); + } - Fx = F * Lx/L; - Fy = F * Ly/L; + Fx = F * Lx/L; + Fy = F * Ly/L; - if (x->link[i].lType == 1) - { // on projette selon 1 axe - // F = Fx*x->link[i].VX + Fy*x->link[i].VY; // produit scalaire de la force sur le vecteur qui la porte - Fx = Fx*x->link[i].VX; // V est unitaire, dc on projete sans pb - Fy = Fy*x->link[i].VY; - } + if (x->link[i].lType == 1) + { // on projette selon 1 axe + // F = Fx*x->link[i].VX + Fy*x->link[i].VY; // produit scalaire de la force sur le vecteur qui la porte + Fx = Fx*x->link[i].VX; // V est unitaire, dc on projete sans pb + Fy = Fy*x->link[i].VY; + } - x->link[i].mass1->forceX -= Fx; - x->link[i].mass1->forceY -= Fy; - x->link[i].mass2->forceX += Fx; - x->link[i].mass2->forceY += Fy; + x->link[i].mass1->forceX -= Fx; + x->link[i].mass1->forceY -= Fy; + x->link[i].mass2->forceX += Fx; + x->link[i].mass2->forceY += Fy; + x->link[i].forceX = Fx; // save for latter use + x->link[i].forceY = Fy; + } + x->link[i].distance=L; } - x->link[i].distance=L; } } @@ -170,6 +196,7 @@ void pmpd2d_create_link(t_pmpd2d *x, t_symbol *Id, int mass1, int mass2, t_float { x->link[x->nb_link].lType = type; x->link[x->nb_link].Id = Id; + x->link[x->nb_link].active = 1; x->link[x->nb_link].mass1 = &x->mass[mass1]; x->link[x->nb_link].mass2 = &x->mass[mass2]; x->link[x->nb_link].K = K; diff --git a/pmpd2d_set.c b/pmpd2d_set.c index 74aa009..58df834 100644 --- a/pmpd2d_set.c +++ b/pmpd2d_set.c @@ -2,13 +2,13 @@ void pmpd2d_setK(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].K = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_link; i++) { @@ -24,13 +24,13 @@ void pmpd2d_setD(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].D = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_link; i++) { @@ -46,13 +46,13 @@ void pmpd2d_setDEnv(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].D2 = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -62,7 +62,7 @@ void pmpd2d_setDEnv(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) } } } - if ( ( argv[0].a_type == A_FLOAT ) && ( argc == 1 ) ) + else if ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) && ( argc == 1 ) ) { for (i=0; i< x->nb_mass; i++) { @@ -75,13 +75,13 @@ void pmpd2d_setDEnvOffset(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].D2offset = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -91,7 +91,7 @@ void pmpd2d_setDEnvOffset(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) } } } - if ( ( argv[0].a_type == A_FLOAT ) && ( argc == 1 ) ) + else if ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -104,13 +104,13 @@ void pmpd2d_setL(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { // set a link to a specific length tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].L = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { // set a class of link to a specific length for (i=0; i< x->nb_link; i++) { @@ -120,13 +120,13 @@ void pmpd2d_setL(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) } } } - if ( ( argv[0].a_type == A_FLOAT ) && ( argc == 1 ) ) + else if ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) && ( argc == 1 ) ) { // set a link to it's current length tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].L = x->link[tmp].distance; } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argc == 1 ) ) + else if ( (argc == 1) && ( argv[0].a_type == A_SYMBOL ) && ( argc == 1 ) ) { // set a class of link to there current length for (i=0; i< x->nb_link; i++) { @@ -181,13 +181,13 @@ void pmpd2d_setLKTab(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) int tmp, i; t_float K_l = atom_getfloatarg(1, argc, argv); if (K_l <= 0) K_l = 1; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].K_L = K_l; } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if (argc == 2) && ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_link; i++) { @@ -204,13 +204,13 @@ void pmpd2d_setLDTab(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) int tmp, i; t_float D_l = atom_getfloatarg(1, argc, argv); if (D_l <= 0) D_l = 1; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].D_L = D_l; } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_link; i++) { @@ -226,13 +226,13 @@ void pmpd2d_setLinkId(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_SYMBOL ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_SYMBOL ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].Id = atom_getsymbolarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) { for (i=0; i< x->nb_link; i++) { @@ -248,13 +248,13 @@ void pmpd2d_setMassId(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_SYMBOL ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_SYMBOL ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].Id = atom_getsymbolarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) { for (i=0; i< x->nb_mass; i++) { @@ -270,13 +270,13 @@ void pmpd2d_setFixed(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( argv[0].a_type == A_FLOAT ) + if ( (argc == 1) && (argv[0].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].mobile = 0; } - if ( argv[0].a_type == A_SYMBOL ) + else if ( (argc == 1) && (argv[0].a_type == A_SYMBOL ) ) { for (i=0; i< x->nb_mass; i++) { @@ -292,13 +292,13 @@ void pmpd2d_setMobile(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( argv[0].a_type == A_FLOAT ) + if ( (argc == 1) && (argv[0].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].mobile = 1; } - if ( argv[0].a_type == A_SYMBOL ) + else if ( (argc == 2) && (argv[0].a_type == A_SYMBOL ) ) { for (i=0; i< x->nb_mass; i++) { @@ -314,14 +314,14 @@ void pmpd2d_setSpeed(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + if ( (argc == 3) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].speedX = atom_getfloatarg(1, argc, argv); x->mass[tmp].speedY = atom_getfloatarg(2, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + else if ( (argc == 3) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -338,13 +338,13 @@ void pmpd2d_setSpeedX(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].speedX = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -360,13 +360,13 @@ void pmpd2d_setSpeedY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].speedY = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -382,14 +382,14 @@ void pmpd2d_setForce(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + if ( (argc == 3) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceX = atom_getfloatarg(1, argc, argv); x->mass[tmp].forceY = atom_getfloatarg(2, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + else if ( (argc == 3) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -406,13 +406,13 @@ void pmpd2d_setForceX(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceX = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -428,13 +428,13 @@ void pmpd2d_setForceY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceY = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -509,7 +509,7 @@ void pmpd2d_pos(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) // displace a mass to a certain position int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + if ( (argc == 3) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); @@ -521,7 +521,7 @@ void pmpd2d_pos(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].forceY = 0; } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + else if ( (argc == 3) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -544,16 +544,15 @@ void pmpd2d_posX(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) // displace a mass to a certain position int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].posX = atom_getfloatarg(1, argc, argv); - x->mass[tmp].speedX = 0; + x->mass[tmp].speedX = 0; x->mass[tmp].forceX = 0; - } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -562,7 +561,6 @@ void pmpd2d_posX(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) x->mass[i].posX = atom_getfloatarg(1, argc, argv); x->mass[i].speedX = 0; x->mass[i].forceX = 0; - } } } @@ -573,7 +571,7 @@ void pmpd2d_posY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) // displace a mass to a certain position int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); @@ -582,7 +580,7 @@ void pmpd2d_posY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].forceY = 0; } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -596,7 +594,6 @@ void pmpd2d_posY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) } } - void pmpd2d_overdamp(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { // set the overdamped factor to a mass @@ -608,7 +605,7 @@ void pmpd2d_overdamp(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].overdamp = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { diff --git a/pmpd2d_various.c b/pmpd2d_various.c index 26d01d1..5fe15f7 100644 --- a/pmpd2d_various.c +++ b/pmpd2d_various.c @@ -40,14 +40,14 @@ void pmpd2d_force(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) // add a force to a specific mass int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + if ( (argc == 3) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceX += atom_getfloatarg(1, argc, argv); x->mass[tmp].forceY += atom_getfloatarg(2, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + else if ( (argc == 3) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -65,13 +65,13 @@ void pmpd2d_forceX(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) // add a force to a specific mass int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceX += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -88,13 +88,13 @@ void pmpd2d_forceY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) // add a force to a specific mass int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceY += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -142,14 +142,14 @@ void pmpd2d_addPos(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + if ( (argc == 3) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].posX += atom_getfloatarg(1, argc, argv); x->mass[tmp].posY += atom_getfloatarg(2, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) + else if ( (argc == 3) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -166,13 +166,13 @@ void pmpd2d_addPosX(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].posX += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -188,13 +188,13 @@ void pmpd2d_addPosY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) { int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].posY += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -228,7 +228,7 @@ void pmpd2d_grabMass(t_pmpd2d *x, t_float posX, t_float posY, t_float grab) } } } - if (x->grab == 1) + else if (x->grab == 1) { x->mass[x->grab_nb].posX = posX; x->mass[x->grab_nb].posY = posY; @@ -390,7 +390,7 @@ void pmpd2d_forcesXT(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) t_word *vec; t_symbol *array; - if ( argv[0].a_type == A_SYMBOL ) + if ( ( argc > 0 ) && (argv[0].a_type == A_SYMBOL )) { array = atom_getsymbolarg(0,argc,argv); if (!(a = (t_garray *)pd_findbyclass(array, garray_class))) @@ -436,7 +436,7 @@ void pmpd2d_forcesYT(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) t_word *vec; t_symbol *array; - if ( argv[0].a_type == A_SYMBOL ) + if ( ( argc > 0 ) && (argv[0].a_type == A_SYMBOL )) { array = atom_getsymbolarg(0,argc,argv); if (!(a = (t_garray *)pd_findbyclass(array, garray_class))) @@ -4,7 +4,8 @@ pmpd = physical modeling for pure data
Written by Cyrille Henry (ch@chnry.net)
-
+ with help from Nicolas Mongermont
+
Get sources on pd svn on sourceforge.
This program is free software; you can redistribute it and/or
diff --git a/pmpd3d_core.c b/pmpd3d_core.c index 1ad06fd..2da8ba8 100644 --- a/pmpd3d_core.c +++ b/pmpd3d_core.c @@ -123,6 +123,7 @@ void pmpd3d_bang(t_pmpd3d *x) x->mass[i].posY = tmpY; x->mass[i].posZ = tmpZ; } + // velocity damping of every masse (set a new force) x->mass[i].forceX = -x->mass[i].D2 * x->mass[i].speedX; x->mass[i].forceY = -x->mass[i].D2 * x->mass[i].speedY; @@ -138,8 +139,7 @@ void pmpd3d_bang(t_pmpd3d *x) } for (i=0; i<x->nb_link; i++) - // compute link forces - { + { // compute link forces if (x->link[i].active == 1) { Lx = x->link[i].mass1->posX - x->link[i].mass2->posX; diff --git a/pmpd3d_set.c b/pmpd3d_set.c index fe0fd9a..cdc2e5e 100644 --- a/pmpd3d_set.c +++ b/pmpd3d_set.c @@ -8,7 +8,7 @@ void pmpd3d_setK(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].K = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_link; i++) { @@ -30,7 +30,7 @@ void pmpd3d_setD(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].D = atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_link; i++) { @@ -52,7 +52,7 @@ void pmpd3d_setDEnv(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].D2 = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -62,7 +62,7 @@ void pmpd3d_setDEnv(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) } } } - if ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) ) + else if ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -81,7 +81,7 @@ void pmpd3d_setDEnvOffset(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].D2offset = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -91,7 +91,7 @@ void pmpd3d_setDEnvOffset(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) } } } - if ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) ) + else if ( (argc == 1) && ( argv[0].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -210,7 +210,7 @@ void pmpd3d_setLDTab(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].D_L = D_l; } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_link; i++) { @@ -232,7 +232,7 @@ void pmpd3d_setLinkId(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_link-1, tmp)); x->link[tmp].Id = atom_getsymbolarg(1, argc, argv); } - if ( ((argc == 2) && argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) + else if ( ((argc == 2) && argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) { for (i=0; i< x->nb_link; i++) { @@ -254,7 +254,7 @@ void pmpd3d_setMassId(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].Id = atom_getsymbolarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) ) { for (i=0; i< x->nb_mass; i++) { @@ -276,7 +276,7 @@ void pmpd3d_setFixed(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].mobile = 0; } - if ( (argc == 2) && (argv[0].a_type == A_SYMBOL ) ) + else if ( (argc == 2) && (argv[0].a_type == A_SYMBOL ) ) { for (i=0; i< x->nb_mass; i++) { @@ -298,7 +298,7 @@ void pmpd3d_setMobile(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].mobile = 1; } - if ( (argc == 1) && ( argv[0].a_type == A_SYMBOL ) ) + else if ( (argc == 1) && ( argv[0].a_type == A_SYMBOL ) ) { for (i=0; i< x->nb_mass; i++) { @@ -322,7 +322,7 @@ void pmpd3d_setSpeed(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].speedY = atom_getfloatarg(2, argc, argv); x->mass[tmp].speedZ = atom_getfloatarg(3, argc, argv); } - if ( (argc == 4) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) + else if ( (argc == 4) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -346,7 +346,7 @@ void pmpd3d_setSpeedX(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].speedX = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -368,7 +368,7 @@ void pmpd3d_setSpeedY(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].speedY = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -390,7 +390,7 @@ void pmpd3d_setSpeedZ(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].speedZ = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -414,7 +414,7 @@ void pmpd3d_setForce(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].forceY = atom_getfloatarg(2, argc, argv); x->mass[tmp].forceZ = atom_getfloatarg(3, argc, argv); } - if ( (argc == 4) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) + else if ( (argc == 4) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -438,7 +438,7 @@ void pmpd3d_setForceX(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceX = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -460,7 +460,7 @@ void pmpd3d_setForceY(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceY = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -482,7 +482,7 @@ void pmpd3d_setForceZ(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceZ = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -571,7 +571,7 @@ void pmpd3d_pos(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].speedZ = 0; x->mass[tmp].forceZ = 0; } - if ( (argc == 4) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) + else if ( (argc == 4) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -605,7 +605,7 @@ void pmpd3d_posX(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].forceX = 0; } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -634,7 +634,7 @@ void pmpd3d_posY(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].forceY = 0; } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -662,7 +662,7 @@ void pmpd3d_posZ(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].forceZ = 0; } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -687,7 +687,7 @@ void pmpd3d_overdamp(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].overdamp = atom_getfloatarg(1, argc, argv); } - if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { diff --git a/pmpd3d_various.c b/pmpd3d_various.c index 1004601..f31009d 100644 --- a/pmpd3d_various.c +++ b/pmpd3d_various.c @@ -42,7 +42,7 @@ void pmpd3d_force(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) // add a force to a specific mass t_int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) + if ( (argc == 4) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); @@ -50,7 +50,7 @@ void pmpd3d_force(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].forceY += atom_getfloatarg(2, argc, argv); x->mass[tmp].forceZ += atom_getfloatarg(3, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) + else if ( (argc == 4) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -69,13 +69,13 @@ void pmpd3d_forceX(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) // add a force to a specific mass t_int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceX += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -92,13 +92,13 @@ void pmpd3d_forceY(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) // add a force to a specific mass t_int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceY += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -115,13 +115,13 @@ void pmpd3d_forceZ(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) // add a force to a specific mass t_int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].forceZ += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -181,7 +181,7 @@ void pmpd3d_addPos(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) { t_int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) + if ( (argc == 4) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); @@ -189,7 +189,7 @@ void pmpd3d_addPos(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) x->mass[tmp].posY += atom_getfloatarg(2, argc, argv); x->mass[tmp].posZ += atom_getfloatarg(3, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) + else if ( (argc == 4) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -207,13 +207,13 @@ void pmpd3d_addPosX(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) { t_int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].posX += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -229,13 +229,13 @@ void pmpd3d_addPosY(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) { t_int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].posY += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -251,13 +251,13 @@ void pmpd3d_addPosZ(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) { t_int tmp, i; - if ( ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); tmp = max(0, min( x->nb_mass-1, tmp)); x->mass[tmp].posZ += atom_getfloatarg(1, argc, argv); } - if ( ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) + else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) ) { for (i=0; i< x->nb_mass; i++) { @@ -291,7 +291,7 @@ void pmpd3d_grabMass(t_pmpd3d *x, t_float posX, t_float posY, t_float posZ, t_fl } } } - if (x->grab == 1) + else if (x->grab == 1) { x->mass[x->grab_nb].posX = posX; x->mass[x->grab_nb].posY = posY; @@ -458,7 +458,7 @@ void pmpd3d_forcesXT(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) t_word *vec; t_symbol *array; - if ( argv[0].a_type == A_SYMBOL ) + if ( ( argc > 0 ) && (argv[0].a_type == A_SYMBOL )) { array = atom_getsymbolarg(0,argc,argv); if (!(a = (t_garray *)pd_findbyclass(array, garray_class))) @@ -504,7 +504,7 @@ void pmpd3d_forcesYT(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) t_word *vec; t_symbol *array; - if ( argv[0].a_type == A_SYMBOL ) + if ( ( argc > 0 ) && (argv[0].a_type == A_SYMBOL )) { array = atom_getsymbolarg(0,argc,argv); if (!(a = (t_garray *)pd_findbyclass(array, garray_class))) @@ -550,7 +550,7 @@ void pmpd3d_forcesZT(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) t_word *vec; t_symbol *array; - if ( argv[0].a_type == A_SYMBOL ) + if ( ( argc > 0 ) && (argv[0].a_type == A_SYMBOL )) { array = atom_getsymbolarg(0,argc,argv); if (!(a = (t_garray *)pd_findbyclass(array, garray_class))) |