aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pmpd2d.h4
-rw-r--r--pmpd2d_core.c3
-rw-r--r--pmpd2d_set.c42
3 files changed, 36 insertions, 13 deletions
diff --git a/pmpd2d.h b/pmpd2d.h
index 1cd3da8..cd84986 100644
--- a/pmpd2d.h
+++ b/pmpd2d.h
@@ -31,11 +31,11 @@ typedef struct _link {
t_int active;
t_float K;
t_float D;
- t_float L; // teta
+ t_float L; // teta actuel
t_float Pow;
t_float Lmin; // tetamin pour un hinge
t_float Lmax; // tetamax
- t_float distance; // angle de la charniere ds le cas d'un hinge
+ t_float distance; // angle force nul de la charniere ds le cas d'un hinge
t_float VX; // vecteur portant la liaison, si c'est le cas
t_float VY;
t_symbol *arrayK;
diff --git a/pmpd2d_core.c b/pmpd2d_core.c
index eeebafc..1066db4 100644
--- a/pmpd2d_core.c
+++ b/pmpd2d_core.c
@@ -84,11 +84,12 @@ t_float distance(t_pmpd2d *x, t_int mass1, t_int mass2)
}
t_float mod2Pi(t_float angle)
-{
+{ // return an angle between -pi and pi
t_float tmp;
tmp = fmodf(angle-3.1415926, 6.2831852);
return(tmp > 0 ? tmp-3.1415926 : tmp+3.1415926); // TODO : mettre un vrai PI
}
+
void pmpd2d_reset(t_pmpd2d *x)
{
x->nb_link = 0;
diff --git a/pmpd2d_set.c b/pmpd2d_set.c
index f6807cd..8d2d0fa 100644
--- a/pmpd2d_set.c
+++ b/pmpd2d_set.c
@@ -413,7 +413,7 @@ void pmpd2d_setL(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
x->link[tmp].L = atom_getfloatarg(1, argc, argv);
}
else if ( (argc == 3) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) )
- {
+ { // set a range of link to a specific value
tmp = atom_getfloatarg(0, argc, argv);
tmp = max(0, min( x->nb_link, tmp));
end = atom_getfloatarg(1, argc, argv);
@@ -449,7 +449,7 @@ void pmpd2d_setL(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
}
}
else if ( (argc >= 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) )
- {
+ { // set a class of link to value from a table
K=1;
if ((argc >= 3) && ( argv[2].a_type == A_FLOAT )) K=atom_getfloatarg(2, argc, argv);
if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class)))
@@ -471,7 +471,7 @@ void pmpd2d_setL(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
}
}
else if ( (argc >= 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_SYMBOL ) )
- {
+ {
K=1;
if ((argc >= 3) && ( argv[2].a_type == A_FLOAT )) K=atom_getfloatarg(2, argc, argv);
if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class)))
@@ -484,7 +484,7 @@ void pmpd2d_setL(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
n=min(npoints,x->nb_link-atom_getfloatarg(1, argc, argv));
for (i=0; i < n; i++)
{
- x->link[i+offset].L = K*vec[i].w_float;
+ x->link[i+offset].L = K*vec[i].w_float;
}
}
}
@@ -586,7 +586,7 @@ void pmpd2d_addL(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
void pmpd2d_setLCurrent(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i, end;
- t_float valeur;
+ t_float valeur, tmp2;
if ( ( argc == 1 ) && ( argv[0].a_type == A_FLOAT ) )
{ // set a link to it's current length
@@ -605,20 +605,35 @@ void pmpd2d_setLCurrent(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
}
}
else if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) )
- { // set a link to a mix between it's curent length and it's size
+ { // set a link to a mix between it's current length and it's size
i = atom_getfloatarg(0, argc, argv);
i = max(0, min( x->nb_link-1, i));
- x->link[i].L = mix(x->link[i].L,x->link[i].distance,atom_getfloatarg(1, argc, argv));
+ if (x->link[i].lType != 3) {
+ x->link[i].L = mix(x->link[i].L,x->link[i].distance,atom_getfloatarg(1, argc, argv));
+ }
+ else {
+ tmp2 = mod2Pi(x->link[i].L - x->link[i].distance);
+ x->link[i].L = mix(x->link[i].L,x->link[i].L-tmp2,atom_getfloatarg(1, argc, argv));
+ }
}
else if ( (argc == 3) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) )
- {
+ { // set a range of link to a mix between it's curent length and it's size
tmp = atom_getfloatarg(0, argc, argv);
tmp = max(0, min( x->nb_link-1, tmp));
end = atom_getfloatarg(1, argc, argv);
end = max(tmp, min( x->nb_link-1, end));
valeur = atom_getfloatarg(2, argc, argv);
for (i=tmp; i<=end; i++)
- x->link[i].L = mix(x->link[i].L,x->link[i].distance,valeur);
+ {
+ //x->link[i].L = mix(x->link[i].L,x->link[i].distance,valeur);
+ if (x->link[i].lType != 3) {
+ x->link[i].L = mix(x->link[i].L,x->link[i].distance,valeur);
+ }
+ else {
+ tmp2 = mod2Pi(x->link[i].L- x->link[i].distance);
+ x->link[i].L = mix(x->link[i].L,x->link[i].L-tmp2,valeur);
+ }
+ }
}
else if ( (argc == 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) )
{ // set a class of link to a mix between it's curent length and it's size
@@ -626,7 +641,14 @@ void pmpd2d_setLCurrent(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv)
{
if ( atom_getsymbolarg(0,argc,argv) == x->link[i].Id)
{
- x->link[i].L = mix(x->link[i].L,x->link[i].distance,atom_getfloatarg(1, argc, argv));
+ // x->link[i].L = mix(x->link[i].L,x->link[i].distance,atom_getfloatarg(1, argc, argv));
+ if (x->link[i].lType != 3) {
+ x->link[i].L = mix(x->link[i].L,x->link[i].distance,atom_getfloatarg(1, argc, argv));
+ }
+ else {
+ tmp2 = mod2Pi(x->link[i].L- x->link[i].distance);
+ x->link[i].L = mix(x->link[i].L,x->link[i].L-tmp2,atom_getfloatarg(1, argc, argv));
+ }
}
}
}