aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2013-05-01 14:39:38 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2013-05-01 14:39:38 +0000
commit5c175e3c65e69451969173d8c01e9dda4604c8b9 (patch)
tree3e3a6fda7d25d417e488363110d7bebd98bdac9f
parent3d1b29ec4d566d1af1892f23b1d930dea74ea753 (diff)
add messages to change link connection
svn path=/trunk/externals/pmpd/; revision=17103
-rw-r--r--pmpd2d.c4
-rw-r--r--pmpd2d_set.c121
-rw-r--r--pmpd3d.c6
-rw-r--r--pmpd3d_set.c6
4 files changed, 127 insertions, 10 deletions
diff --git a/pmpd2d.c b/pmpd2d.c
index 224e3b9..a2b0e32 100644
--- a/pmpd2d.c
+++ b/pmpd2d.c
@@ -95,7 +95,9 @@ void pmpd2d_setup(void)
class_addmethod(pmpd2d_class, (t_method)pmpd2d_posX, gensym("setPosX"), A_GIMME, 0);
class_addmethod(pmpd2d_class, (t_method)pmpd2d_posY, gensym("setPosY"), A_GIMME, 0);
class_addmethod(pmpd2d_class, (t_method)pmpd2d_overdamp, gensym("setOverdamp"), A_GIMME, 0);
-
+ class_addmethod(pmpd3d_class, (t_method)pmpd2d_setEnd1, gensym("setEnd1"), A_GIMME, 0);
+ class_addmethod(pmpd3d_class, (t_method)pmpd2d_setEnd2, gensym("setEnd2"), A_GIMME, 0);
+ class_addmethod(pmpd3d_class, (t_method)pmpd2d_setEnd, gensym("setEnd"), A_GIMME, 0);
/*
pmpd2d_get
--
diff --git a/pmpd2d_set.c b/pmpd2d_set.c
index 02d4683..aa13697 100644
--- a/pmpd2d_set.c
+++ b/pmpd2d_set.c
@@ -446,6 +446,16 @@ void pmpd2d_setForceY(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
}
}
+void pmpd2d_setActivei(t_pmpd3d *x, int i)
+{
+ float Lx, Ly, L;
+ 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) );
+ x->link[i].distance = L;
+ x->link[i].active = 1;
+}
+
void pmpd2d_setActive(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i;
@@ -454,7 +464,7 @@ void pmpd2d_setActive(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
{
tmp = atom_getfloatarg(0, argc, argv);
tmp = max(0, min( x->nb_link-1, tmp));
- x->link[tmp].active = 1;
+ pmpd2d_setActivei(x,tmp);
}
else if ( (argc == 1) && ( argv[0].a_type == A_SYMBOL ) )
{
@@ -462,7 +472,7 @@ void pmpd2d_setActive(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
{
if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id )
{
- x->link[i].active = 1;
+ pmpd2d_setActivei(x,tmp);
}
}
}
@@ -470,7 +480,7 @@ void pmpd2d_setActive(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
{
for (i=0; i< x->nb_link; i++)
{
- x->link[i].active = 1;
+ pmpd2d_setActivei(x,tmp);
}
}
}
@@ -616,3 +626,108 @@ void pmpd2d_overdamp(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
}
}
}
+
+void pmpd2d_setConnection1i(t_pmpd2d *x, int i, int j)
+{
+ float Lx, Ly, L;
+
+ x->link[i].mass1=&x->mass[max(0, min( x->nb_mass-1, j))];
+ 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) );
+ x->link[i].distance = L;
+}
+
+void pmpd2d_setEnd1(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ 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));
+ pmpd2d_setConnection1i(x,tmp,atom_getfloatarg(1, argc, argv));
+
+ }
+ else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id )
+ {
+ pmpd2d_setConnection1i(x,i,atom_getfloatarg(1, argc, argv));
+ }
+ }
+ }
+}
+
+void pmpd2d_setConnection2i(t_pmpd2d *x, int i, int j)
+{
+ float Lx, Ly, L;
+
+ x->link[i].mass2=&x->mass[max(0, min( x->nb_mass-1, j))];
+ 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) );
+ x->link[i].distance = L;
+}
+
+void pmpd2d_setEnd2(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ 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));
+ pmpd2d_setConnection2i(x,tmp,atom_getfloatarg(1, argc, argv));
+
+ }
+ else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) )
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id )
+ {
+ pmpd2d_setConnection2i(x,i,atom_getfloatarg(1, argc, argv));
+ }
+ }
+ }
+}
+
+void pmpd2d_setConnectioni(t_pmpd2d *x, int i, int j, int k)
+{
+ float Lx, Ly, L;
+
+ x->link[i].mass1=&x->mass[max(0, min( x->nb_mass-1, j))];
+ x->link[i].mass2=&x->mass[max(0, min( x->nb_mass-1, k))];
+
+ 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) );
+ x->link[i].distance = L;
+}
+
+void pmpd2d_setEnd(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int tmp, i;
+
+ 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_link-1, tmp));
+ pmpd2d_setConnectioni(x,tmp,atom_getfloatarg(1, argc, argv),atom_getfloatarg(2, argc, argv));
+
+ }
+ 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_link; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id )
+ {
+ pmpd2d_setConnectioni(x,i,atom_getfloatarg(1, argc, argv),atom_getfloatarg(2, argc, argv));
+ }
+ }
+ }
+}
+
diff --git a/pmpd3d.c b/pmpd3d.c
index a8c3c10..2fbe0c6 100644
--- a/pmpd3d.c
+++ b/pmpd3d.c
@@ -100,9 +100,9 @@ void pmpd3d_setup(void)
class_addmethod(pmpd3d_class, (t_method)pmpd3d_posY, gensym("setPosY"), A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_posZ, gensym("setPosZ"), A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_overdamp, gensym("setOverdamp"), A_GIMME, 0);
- class_addmethod(pmpd3d_class, (t_method)pmpd3d_setConnection1, gensym("setConnection1"), A_GIMME, 0);
- class_addmethod(pmpd3d_class, (t_method)pmpd3d_setConnection2, gensym("setConnection2"), A_GIMME, 0);
- class_addmethod(pmpd3d_class, (t_method)pmpd3d_setConnection, gensym("setConnection"), A_GIMME, 0);
+ class_addmethod(pmpd3d_class, (t_method)pmpd3d_setEnd1, gensym("setEnd1"), A_GIMME, 0);
+ class_addmethod(pmpd3d_class, (t_method)pmpd3d_setEnd2, gensym("setEnd2"), A_GIMME, 0);
+ class_addmethod(pmpd3d_class, (t_method)pmpd3d_setEnd, gensym("setEnd"), A_GIMME, 0);
/*
pmpd3d_get
diff --git a/pmpd3d_set.c b/pmpd3d_set.c
index 6327380..19b8540 100644
--- a/pmpd3d_set.c
+++ b/pmpd3d_set.c
@@ -722,7 +722,7 @@ void pmpd3d_setConnection1i(t_pmpd3d *x, int i, int j)
x->link[i].distance = L;
}
-void pmpd3d_setConnection1(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
+void pmpd3d_setEnd1(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i;
@@ -757,7 +757,7 @@ void pmpd3d_setConnection2i(t_pmpd3d *x, int i, int j)
x->link[i].distance = L;
}
-void pmpd3d_setConnection2(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
+void pmpd3d_setEnd2(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i;
@@ -794,7 +794,7 @@ void pmpd3d_setConnectioni(t_pmpd3d *x, int i, int j, int k)
x->link[i].distance = L;
}
-void pmpd3d_setConnection(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
+void pmpd3d_setEnd(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i;