aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2014-08-24 17:57:34 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2014-08-24 17:57:34 +0000
commitb7b84d0b2330ae3d4b65ed18d8931eb0fe5b9da9 (patch)
treede927d7c60e0731e2e43583a5d636d0af7d51725
parent086c2639def9c1f002d17ce22e1e7a88d9aa0b6b (diff)
new get for link
svn path=/trunk/externals/pmpd/; revision=17337
-rw-r--r--pmpd2d_get.c63
1 files changed, 61 insertions, 2 deletions
diff --git a/pmpd2d_get.c b/pmpd2d_get.c
index 513566c..eeb99dc 100644
--- a/pmpd2d_get.c
+++ b/pmpd2d_get.c
@@ -545,10 +545,69 @@ void pmpd2d_linkPos(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
{
SETSYMBOL(&(toout[0]), x->link[i].Id);
SETFLOAT(&(toout[1]), i);
- SETFLOAT(&(toout[2]), (x->link[i].mass1->posX+x->link[i].mass2->posX)/2);
- SETFLOAT(&(toout[3]), (x->link[i].mass1->posY+x->link[i].mass2->posY)/2);
+ SETFLOAT(&(toout[2]), (x->link[i].mass1->posX-x->link[i].mass2->posX));
+ SETFLOAT(&(toout[3]), (x->link[i].mass1->posY+x->link[i].mass2->posY));
outlet_anything(x->main_outlet, gensym("linkPos"), 4, toout);
}
}
}
+void pmpd2d_linkLength(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i;
+ t_atom toout[5];
+ t_float tmp1, tmp2;
+
+ if ((argc>0)&&(argv[0].a_type == A_FLOAT))
+ {
+ i = atom_getfloatarg(0, argc, argv);
+ if ( (i>=0) && (i<x->nb_link) )
+ {
+ tmp1=x->link[i].mass1->posX-x->link[i].mass2->posX;
+ tmp2=x->link[i].mass1->posY-x->link[i].mass2->posY;
+
+ SETSYMBOL(&(toout[0]), x->link[i].Id);
+ SETFLOAT(&(toout[1]), i);
+ SETFLOAT(&(toout[2]), tmp1);
+ SETFLOAT(&(toout[3]), tmp2);
+ SETFLOAT(&(toout[4]), sqrt(tmp1*tmp1 + tmp2*tmp2));
+ outlet_anything(x->main_outlet, gensym("linkLength"), 5, toout);
+ }
+ }
+ else
+ if ((argc>0)&&(argv[0].a_type == A_SYMBOL))
+ {
+ SETSYMBOL(&(toout[0]), atom_getsymbolarg(0,argc,argv));
+ for (i=0; i< x->nb_link; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
+ {
+ tmp1=x->link[i].mass1->posX-x->link[i].mass2->posX;
+ tmp2=x->link[i].mass1->posY-x->link[i].mass2->posY;
+
+ SETFLOAT(&(toout[1]), i);
+ SETFLOAT(&(toout[2]), tmp1);
+ SETFLOAT(&(toout[3]), tmp2);
+ SETFLOAT(&(toout[4]), sqrt(tmp1*tmp1 + tmp2*tmp2));
+ outlet_anything(x->main_outlet, gensym("linkLength"), 5, toout);
+ }
+ }
+ }
+ else
+ if (argc == 0)
+ {
+ for (i=0; i< x->nb_link; i++)
+ {
+ tmp1=x->link[i].mass1->posX-x->link[i].mass2->posX;
+ tmp2=x->link[i].mass1->posY-x->link[i].mass2->posY;
+
+ SETSYMBOL(&(toout[0]), x->link[i].Id);
+ SETFLOAT(&(toout[1]), i);
+ SETFLOAT(&(toout[2]), tmp1);
+ SETFLOAT(&(toout[3]), tmp2);
+ SETFLOAT(&(toout[4]), sqrt(tmp1*tmp1 + tmp2*tmp2));
+ outlet_anything(x->main_outlet, gensym("linkLength"), 5, toout);
+ }
+ }
+}
+