From d42c6bfc5c07014f122671a963278360deae846f Mon Sep 17 00:00:00 2001 From: Cyrille Henry Date: Fri, 31 Jan 2014 10:25:51 +0000 Subject: remoce forceXT messages familly and merge fonctionality with force messages familly (to be consistent with other messages that accept table input svn path=/trunk/externals/pmpd/; revision=17262 --- pmpd3d_various.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 4 deletions(-) (limited to 'pmpd3d_various.c') diff --git a/pmpd3d_various.c b/pmpd3d_various.c index cb316db..13912ea 100644 --- a/pmpd3d_various.c +++ b/pmpd3d_various.c @@ -41,7 +41,10 @@ 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; - + t_garray *a; + int npoints, n; + t_word *vec; + 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); @@ -62,13 +65,40 @@ void pmpd3d_force(t_pmpd3d *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 ) ) + { + if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name); + else + { + n=0; + for (i=0; i < x->nb_mass; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + if (n >= npoints-3) break; + x->mass[i].forceX += vec[n].w_float; + n++; + x->mass[i].forceY += vec[n].w_float; + n++; + x->mass[i].forceZ += vec[n].w_float; + n++; + } + } + } + } } 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; - + t_garray *a; + int npoints, n; + t_word *vec; + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); @@ -85,13 +115,36 @@ void pmpd3d_forceX(t_pmpd3d *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 ) ) + { + if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name); + else + { + n=0; + for (i=0; i < x->nb_mass; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + x->mass[i].forceX += vec[n].w_float; + n++; + if (n >= npoints) break; + } + } + } + } } 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; - + t_garray *a; + int npoints, n; + t_word *vec; + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); @@ -108,13 +161,36 @@ void pmpd3d_forceY(t_pmpd3d *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 ) ) + { + if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name); + else + { + n=0; + for (i=0; i < x->nb_mass; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + x->mass[i].forceY += vec[n].w_float; + n++; + if (n >= npoints) break; + } + } + } + } } 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; - + t_garray *a; + int npoints, n; + t_word *vec; + if ( (argc == 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) ) { tmp = atom_getfloatarg(0, argc, argv); @@ -131,6 +207,26 @@ void pmpd3d_forceZ(t_pmpd3d *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 ) ) + { + if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name); + else if (!garray_getfloatwords(a, &npoints, &vec)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name); + else + { + n=0; + for (i=0; i < x->nb_mass; i++) + { + if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + x->mass[i].forceZ += vec[n].w_float; + n++; + if (n >= npoints) break; + } + } + } + } } void pmpd3d_min(t_pmpd3d *x, t_float minX, t_float minY, t_float minZ) @@ -449,6 +545,7 @@ void pmpd3d_massDistances(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) } } +/* void pmpd3d_forcesXT(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) { // add forces to masses. forces comes from a table, masse can be filter on ther Id or not @@ -586,3 +683,4 @@ void pmpd3d_forcesZT(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv) } } } +*/ -- cgit v1.2.1