diff options
-rw-r--r-- | pmpd-help.pd | 15 | ||||
-rw-r--r-- | pmpd.c | 45 | ||||
-rw-r--r-- | pmpd2d-help.pd | 7 | ||||
-rw-r--r-- | pmpd2d.c | 49 | ||||
-rw-r--r-- | pmpd3d-help.pd | 7 | ||||
-rw-r--r-- | pmpd3d.c | 49 |
6 files changed, 129 insertions, 43 deletions
diff --git a/pmpd-help.pd b/pmpd-help.pd index d0357a3..8dc88d6 100644 --- a/pmpd-help.pd +++ b/pmpd-help.pd @@ -1,4 +1,4 @@ -#N canvas 37 22 575 730 10; +#N canvas 427 32 575 730 10; #X obj 4 369 cnv 15 550 15 empty empty empty 20 12 0 14 -158509 -66577 0; #X obj 5 689 cnv 15 550 40 empty empty empty 20 12 0 14 -158509 -66577 @@ -65,9 +65,9 @@ souple 3 2 1 0.5; #X obj 17 344 s \$0-out; #X obj 17 295 r \$0-in; #X obj 261 184 vsl 15 127 0 127 0 0 empty empty Drag-----> -70 60 1 -10 -262144 -1 -1 0 1; +10 -262144 -1 -1 3000 1; #X obj 292 184 vsl 15 127 0 127 0 0 empty empty empty 0 -8 0 8 -262144 --1 -1 0 1; +-1 -1 3004 1; #X obj 261 345 s \$0-in; #X msg 261 322 posX fix \$1; #N canvas 565 515 355 193 compute 0; @@ -86,9 +86,9 @@ souple 3 2 1 0.5; -1 -1; #X obj 261 131 route massesPosL; #X obj 311 184 vsl 15 127 0 127 0 0 empty empty empty 0 -8 0 8 -262144 --1 -1 0 1; +-1 -1 3008 1; #X obj 330 184 vsl 15 127 0 127 0 0 empty empty empty 0 -8 0 8 -262144 --1 -1 0 1; +-1 -1 3010 1; #X obj 261 152 unpack f f f f; #X text 101 388 Bang - A bang at the left inlet compute the new model state based on previous instant.; @@ -197,7 +197,7 @@ on outlet No 1; #X msg 616 171 linksLengthXT \$1 (\$2); #X msg 616 278 linksPosSpeedXT \$1 (\$2); #X restore 12 519 pd links_attributes ___; -#N canvas 61 22 1230 682 attributes__________ 1; +#N canvas 50 22 1230 682 attributes__________ 0; #X obj 11 95 cnv 15 100 35 empty empty empty 20 12 0 14 -233017 -66577 0; #X obj 5 75 cnv 15 590 15 empty empty empty 20 12 0 14 -158509 -66577 @@ -298,10 +298,11 @@ name \, \$2 (optional): Masses Id); 0; #X obj 601 552 cnv 15 590 15 empty empty empty 20 12 0 14 -158509 -66577 0; -#X msg 612 600 closestMass \$1; #X text 767 600 output the closest mass; #X text 766 614 \$1 : position; #X text 604 552 others :; +#X msg 612 600 closestMass \$1 (\$2); +#X text 766 629 \$2 : none or Id; #X restore 12 499 pd attributes__________; #N canvas 141 69 1139 731 dynamic 0; #X obj 5 3 cnv 15 550 15 empty empty empty 20 12 0 14 -233017 -66577 @@ -1765,25 +1765,50 @@ void pmpd_grabMass(t_pmpd *x, t_float posX, t_float grab) }
}
-void pmpd_closestMass(t_pmpd *x, t_float posX)
+void pmpd_closestMass(t_pmpd *x, t_symbol *s, int argc, t_atom *argv)
{
t_float dist, tmp;
t_int i;
t_atom std_out[2];
+ t_float posX;
+ posX = atom_getfloatarg(0, argc, argv);
- if ((x->nb_mass > 0))
- {
- dist = x->mass[0].posX - posX;
- for (i=1; i<x->nb_mass; i++)
+ if ( (argc == 2) && (argv[1].a_type == A_SYMBOL) )
+ {
+ //t_symbol *mass_name = atom_getsymbolarg(2, argc, argv);
+ if ((x->nb_mass > 0))
{
- tmp = x->mass[i].posX - posX;
- if (tmp < dist)
+ dist = 1000000000;//sqr(x->mass[0].posX - posX) + sqr(x->mass[0].posY - posY);
+ for (i=0; i<x->nb_mass; i++)
{
- dist = tmp;
- x->grab_nb= i;
+ if (atom_getsymbolarg(1,argc,argv) == x->mass[i].Id)
+ {
+ tmp = x->mass[i].posX - posX;
+ if (tmp < dist)
+ {
+ dist = tmp;
+ x->grab_nb= i;
+ }
+ }
+ }
+ }
+ }
+ else {
+ if ((x->nb_mass > 0))
+ {
+ dist = x->mass[0].posX - posX;
+ for (i=1; i<x->nb_mass; i++)
+ {
+ tmp = x->mass[i].posX - posX;
+ if (tmp < dist)
+ {
+ dist = tmp;
+ x->grab_nb= i;
+ }
}
}
}
+
SETFLOAT(&(std_out[0]),x->grab_nb);
SETFLOAT(&(std_out[1]), x->mass[x->grab_nb].posX);
outlet_anything(x->main_outlet, gensym("closestMass"),2,std_out);
@@ -1893,6 +1918,6 @@ void pmpd_setup(void) */
class_addmethod(pmpd_class, (t_method)pmpd_grabMass, gensym("grabMass"), A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd_class, (t_method)pmpd_closestMass, gensym("closestMass"), A_DEFFLOAT, 0);
+ class_addmethod(pmpd_class, (t_method)pmpd_closestMass, gensym("closestMass"), A_GIMME, 0);
}
diff --git a/pmpd2d-help.pd b/pmpd2d-help.pd index 5723965..fb5ad7a 100644 --- a/pmpd2d-help.pd +++ b/pmpd2d-help.pd @@ -1,4 +1,4 @@ -#N canvas 288 22 571 767 10; +#N canvas 622 37 571 767 10; #X obj 4 369 cnv 15 550 15 empty empty empty 20 12 0 14 -158509 -66577 0; #X obj 5 685 cnv 15 550 30 empty empty empty 20 12 0 14 -158509 -66577 @@ -735,9 +735,10 @@ a table; 0; #X text 780 845 output the closest mass; #X text 617 797 others :; -#X msg 625 845 closestMass \$1 \$2; #X text 779 859 \$1 : x -position; #X text 779 874 \$2 : y -position; +#X msg 625 845 closestMass \$1 \$2 (\$3); +#X text 779 890 \$3 : none or Id; #X restore 12 499 pd attributes__________; #N canvas 100 72 1078 872 dynamic 0; #X obj 5 3 cnv 15 550 15 empty empty empty 20 12 0 14 -233017 -66577 @@ -846,6 +847,7 @@ used this argument as the value applayed to all masses (or link); #X text 184 749 \$1 : Id (symbol) or No; #X restore 12 478 pd dynamic settings ___; #X text 112 638 54_pmpd2dtest.pd; +#X obj 307 324 print; #X connect 21 0 39 0; #X connect 24 0 23 0; #X connect 25 0 50 0; @@ -857,3 +859,4 @@ used this argument as the value applayed to all masses (or link); #X connect 45 0 42 0; #X connect 50 0 44 0; #X connect 50 1 44 1; +#X connect 50 2 59 0; @@ -3668,25 +3668,52 @@ void pmpd2d_grabMass(t_pmpd2d *x, t_float posX, t_float posY, t_float grab) }
}
-void pmpd2d_closestMass(t_pmpd2d *x, t_float posX, t_float posY)
+void pmpd2d_closestMass(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)// t_float posX, t_float posY)
{
t_float dist, tmp;
t_int i;
t_atom std_out[3];
-
- if ((x->nb_mass > 0))
- {
- dist = sqr(x->mass[0].posX - posX) + sqr(x->mass[0].posY - posY);
- for (i=1; i<x->nb_mass; i++)
+
+ t_float posX, posY;
+ posX = atom_getfloatarg(0, argc, argv);
+ posY = atom_getfloatarg(1, argc, argv);
+ if ( (argc == 3) && (argv[2].a_type == A_SYMBOL) )
+ {
+ //t_symbol *mass_name = atom_getsymbolarg(2, argc, argv);
+ if ((x->nb_mass > 0))
{
- tmp = sqr(x->mass[i].posX - posX) + sqr(x->mass[i].posY - posY);
- if (tmp < dist)
+ dist = 1000000000;//sqr(x->mass[0].posX - posX) + sqr(x->mass[0].posY - posY);
+ for (i=0; i<x->nb_mass; i++)
{
- dist = tmp;
- x->grab_nb= i;
+ if (atom_getsymbolarg(2,argc,argv) == x->mass[i].Id)
+ {
+ tmp = sqr(x->mass[i].posX - posX) + sqr(x->mass[i].posY - posY);
+ if (tmp < dist)
+ {
+ dist = tmp;
+ x->grab_nb= i;
+ }
+ }
}
}
}
+ else {
+ if ((x->nb_mass > 0))
+ {
+ dist = sqr(x->mass[0].posX - posX) + sqr(x->mass[0].posY - posY);
+ for (i=1; i<x->nb_mass; i++)
+ {
+ tmp = sqr(x->mass[i].posX - posX) + sqr(x->mass[i].posY - posY);
+ if (tmp < dist)
+ {
+ dist = tmp;
+ x->grab_nb= i;
+ }
+ }
+ }
+ }
+
+
SETFLOAT(&(std_out[0]),x->grab_nb);
SETFLOAT(&(std_out[1]), x->mass[x->grab_nb].posX);
SETFLOAT(&(std_out[2]), x->mass[x->grab_nb].posY);
@@ -3838,7 +3865,7 @@ void pmpd2d_setup(void) */
class_addmethod(pmpd2d_class, (t_method)pmpd2d_grabMass, gensym("grabMass"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd2d_class, (t_method)pmpd2d_closestMass, gensym("closestMass"), A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(pmpd2d_class, (t_method)pmpd2d_closestMass, gensym("closestMass"), A_GIMME, 0);
}
diff --git a/pmpd3d-help.pd b/pmpd3d-help.pd index bd69f04..68db63d 100644 --- a/pmpd3d-help.pd +++ b/pmpd3d-help.pd @@ -1,4 +1,4 @@ -#N canvas 52 39 624 761 10; +#N canvas 515 28 624 761 10; #X obj 4 369 cnv 15 550 15 empty empty empty 20 12 0 14 -158509 -66577 0; #X obj 5 695 cnv 15 550 30 empty empty empty 20 12 0 14 -158509 -66577 @@ -496,8 +496,9 @@ and forces of masses \, or directly send value to a table.; #X text 618 807 others :; #X text 780 869 \$1 : x -position; #X text 780 884 \$2 : y -position; -#X msg 626 855 closestMass \$1 \$2 \$3; #X text 780 899 \$3 : z -position; +#X text 780 911 \$4 : none or Id; +#X msg 626 855 closestMass \$1 \$2 \$3 (\$4); #X restore 12 499 pd masses_attributes __; #N canvas 44 22 1236 814 links_attributes 0; #X obj 5 3 cnv 15 590 15 empty empty empty 20 12 0 14 -233017 -66577 @@ -847,6 +848,7 @@ their Id.; ; #X connect 3 0 4 0; #X restore 14 702 pd More_Info; +#X obj 325 322 print; #X connect 35 0 45 0; #X connect 38 0 37 0; #X connect 39 0 51 0; @@ -858,3 +860,4 @@ their Id.; #X connect 47 0 36 0; #X connect 51 0 43 0; #X connect 51 1 43 1; +#X connect 51 2 59 0; @@ -4395,25 +4395,52 @@ void pmpd3d_grabMass(t_pmpd3d *x, t_float posX, t_float posY, t_float posZ, t_fl }
}
-void pmpd3d_closestMass(t_pmpd3d *x, t_float posX, t_float posY, t_float posZ)
+void pmpd3d_closestMass(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
{
t_float dist, tmp;
t_int i;
t_atom std_out[4];
-
- if ((x->nb_mass > 0))
- {
- dist = sqr(x->mass[0].posX - posX) + sqr(x->mass[0].posY - posY) + sqr(x->mass[0].posZ - posZ);
- for (i=1; i<x->nb_mass; i++)
+
+ t_float posX, posY, posZ;
+ posX = atom_getfloatarg(0, argc, argv);
+ posY = atom_getfloatarg(1, argc, argv);
+ posZ = atom_getfloatarg(2, argc, argv);
+ if ( (argc == 4) && (argv[3].a_type == A_SYMBOL) )
+ {
+ //t_symbol *mass_name = atom_getsymbolarg(2, argc, argv);
+ if ((x->nb_mass > 0))
{
- tmp = sqr(x->mass[i].posX - posX) + sqr(x->mass[i].posY - posY) + sqr(x->mass[i].posZ - posZ);
- if (tmp < dist)
+ dist = 1000000000;//sqr(x->mass[0].posX - posX) + sqr(x->mass[0].posY - posY);
+ for (i=0; i<x->nb_mass; i++)
{
- dist = tmp;
- x->grab_nb= i;
+ if (atom_getsymbolarg(3,argc,argv) == x->mass[i].Id)
+ {
+ tmp = sqr(x->mass[i].posX - posX) + sqr(x->mass[i].posY - posY) + sqr(x->mass[i].posZ - posZ);
+ if (tmp < dist)
+ {
+ dist = tmp;
+ x->grab_nb= i;
+ }
+ }
}
}
}
+ else {
+ if ((x->nb_mass > 0))
+ {
+ dist = sqr(x->mass[0].posX - posX) + sqr(x->mass[0].posY - posY) + sqr(x->mass[0].posZ - posZ);
+ for (i=1; i<x->nb_mass; i++)
+ {
+ tmp = sqr(x->mass[i].posX - posX) + sqr(x->mass[i].posY - posY) + sqr(x->mass[i].posZ - posZ);
+ if (tmp < dist)
+ {
+ dist = tmp;
+ x->grab_nb= i;
+ }
+ }
+ }
+ }
+
SETFLOAT(&(std_out[0]),x->grab_nb);
SETFLOAT(&(std_out[1]), x->mass[x->grab_nb].posX);
SETFLOAT(&(std_out[2]), x->mass[x->grab_nb].posY);
@@ -4589,7 +4616,7 @@ void pmpd3d_setup(void) */
class_addmethod(pmpd3d_class, (t_method)pmpd3d_grabMass, gensym("grabMass"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
- class_addmethod(pmpd3d_class, (t_method)pmpd3d_closestMass, gensym("closestMass"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(pmpd3d_class, (t_method)pmpd3d_closestMass, gensym("closestMass"), A_GIMME, 0);
}
|