From d061f5a28acc0bdaf0ad91307c19739ccba1a0e1 Mon Sep 17 00:00:00 2001 From: Cyrille Henry Date: Sat, 25 Jan 2014 16:26:17 +0000 Subject: new interactor : iTable svn path=/trunk/externals/pmpd/; revision=17254 --- examples/65_2d_interactors.pd | 24 +++++++++--- pmpd2d.c | 1 + pmpd2d_interactor.c | 89 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 5 deletions(-) diff --git a/examples/65_2d_interactors.pd b/examples/65_2d_interactors.pd index 8200345..4fc0818 100644 --- a/examples/65_2d_interactors.pd +++ b/examples/65_2d_interactors.pd @@ -1,10 +1,10 @@ -#N canvas 141 668 905 372 10; +#N canvas 222 423 905 391 10; #X declare -lib Gem; -#X obj 52 193 pmpd2d; +#X obj 52 253 pmpd2d; #X obj 52 78 loadbang; #X obj 64 101 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; -#N canvas 667 329 692 614 creation 0; +#N canvas 665 334 692 614 creation 0; #X obj 41 20 inlet; #X obj 51 48 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144 -1 -1; @@ -88,7 +88,7 @@ RaZ \$3 \$4 0.3 0; #X connect 4 0 0 0; #X connect 5 0 3 0; #X restore 188 148 pd gemmouse; -#X obj 52 216 route massPos; +#X obj 52 276 route massPos; #N canvas 1023 474 425 448 mass_render 0; #X obj 148 49 inlet; #X obj 67 285 separator; @@ -115,7 +115,7 @@ RaZ \$3 \$4 0.3 0; #X connect 8 2 10 2; #X connect 9 0 2 0; #X connect 10 0 11 0; -#X restore 52 237 pd mass_render; +#X restore 52 297 pd mass_render; #X msg 187 122 bang \, massPos mobil; #X msg 188 170 iLine mobil \$1 \$2 0.5 0.5 0.1 1 0 0.3; #X msg 485 71 set iCircle mobil \, adddollar 1 \, adddollar 2 \, add2 @@ -132,6 +132,19 @@ RaZ \$3 \$4 0.3 0; 0 0 -0.1 1 -0.1 0.1; #X text 483 12 select an interactor and clik-drag the mouse on the gem windows to see the effect.; +#N canvas 50 82 657 333 iTable 0; +#X obj 192 129 s iteractorX; +#X obj 191 207 s iteractorY; +#X msg 90 62 iTable mobil 0 1 0 1 3 3 iteractorX iteractorY; +#X obj 404 122 table iteractorX 9; +#X msg 193 185 0 0 -1 0 0 0 0 0 1 0; +#X obj 404 142 table iteractorY 9; +#X msg 194 105 0 -0 -1 0 0 1 0 0 0 0; +#X obj 55 214 outlet; +#X connect 2 0 7 0; +#X connect 4 0 1 0; +#X connect 6 0 0 0; +#X restore 188 211 pd iTable; #X connect 0 0 10 0; #X connect 1 0 3 0; #X connect 2 0 3 0; @@ -149,3 +162,4 @@ gem windows to see the effect.; #X connect 17 0 13 0; #X connect 18 0 13 0; #X connect 19 0 13 0; +#X connect 21 0 0 0; diff --git a/pmpd2d.c b/pmpd2d.c index a5be220..84878d4 100644 --- a/pmpd2d.c +++ b/pmpd2d.c @@ -277,6 +277,7 @@ void pmpd2d_setup(void) class_addmethod(pmpd2d_class, (t_method)pmpd2d_iCircle, gensym("iCircle"), A_GIMME, 0); class_addmethod(pmpd2d_class, (t_method)pmpd2d_iLine, gensym("iLine"), A_GIMME, 0); + class_addmethod(pmpd2d_class, (t_method)pmpd2d_iTable, gensym("iTable"), A_GIMME, 0); /* pmpd2d_various diff --git a/pmpd2d_interactor.c b/pmpd2d_interactor.c index 86cbaf6..75b263e 100644 --- a/pmpd2d_interactor.c +++ b/pmpd2d_interactor.c @@ -1,3 +1,5 @@ + + void pmpd2d_iCircle_i(t_pmpd2d *x, int i, t_float a, t_float b, t_float r, t_float K, t_float power, t_float Kt, t_float powert, t_float Rmin, t_float Rmax) { t_float distance, X, Y, rayon, tmp; @@ -188,3 +190,90 @@ void pmpd2d_iLine(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) } } } + +// -------------------------------------------------------- + +void pmpd2d_iTable_i(t_pmpd2d *x, int i, t_float zone_x_min, t_float zone_x_max, t_float zone_y_min, t_float zone_y_max, int taille_x, int taille_y, t_word *tableX, t_word *tableY) +{ + t_float Xtable, Ytable, Xindex, Yindex, force1, force2, force; + int index; + + if ( (x->mass[i].posX >= zone_x_min) && (x->mass[i].posX < zone_x_max) && (x->mass[i].posY >= zone_y_min) && (x->mass[i].posY < zone_y_max) ) + { + Xtable = (x->mass[i].posX - zone_x_min) / (zone_x_max - zone_x_min); + Ytable = (x->mass[i].posY - zone_y_min) / (zone_y_max - zone_y_min); + Xtable *= taille_x - 1; //from [ 0 to table size - 1[ + Ytable *= taille_y - 1; + index = (int)Xtable; + index += (int)Ytable*taille_y; + Xtable = Xtable - (int)(Xtable); + Ytable = Ytable - (int)(Ytable); + force1 = (1-Xtable) * tableX[index].w_float + (Xtable) * tableX[index+1].w_float ; + force2 = (1-Xtable) * tableX[index+taille_y].w_float + (Xtable) * tableX[index+1+taille_y].w_float; + force = (1-Ytable) * force1 + Ytable * force2; + x->mass[i].forceX += force; + force1 = (1-Xtable) * tableY[index].w_float + (Xtable) * tableY[index+1].w_float ; + force2 = (1-Xtable) * tableY[index+taille_y].w_float + (Xtable) * tableY[index+1+taille_y].w_float; + force = (1-Ytable) * force1 + Ytable * force2; + x->mass[i].forceY += force; + } +} + +void pmpd2d_iTable(t_pmpd2d *x, t_symbol *s, int argc, t_atom *argv) +{ + // Argument : + // 0 : mass to apply this interactor + // 1, 2 : Xmin, Xmax + // 3, 4 : Ymin, Ymax physical location of the interator + // 5, 6 : matrix size + // 7, 8 : table name containing the matrix + + t_garray *a1, *a2; + int npoints1, npoints2; + t_word *vec1, *vec2; + + t_float Xmin, Xmax, Ymin, Ymax; + int X, Y, i; + + if (!((argc==9) && (argv[1].a_type == A_FLOAT) && (argv[2].a_type == A_FLOAT) && + (argv[3].a_type == A_FLOAT) && (argv[4].a_type == A_FLOAT) && (argv[5].a_type == A_FLOAT) && + (argv[6].a_type == A_FLOAT) && (argv[7].a_type == A_SYMBOL) && (argv[8].a_type == A_SYMBOL) ) ) + { + pd_error(x,"bad argument for iTable"); + return; + } + + if (!(a1 = (t_garray *)pd_findbyclass(atom_getsymbolarg(7,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(7,argc,argv)->s_name); + else if (!garray_getfloatwords(a1, &npoints1, &vec1)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(7,argc,argv)->s_name); + else if (!(a2 = (t_garray *)pd_findbyclass(atom_getsymbolarg(8,argc,argv), garray_class))) + pd_error(x, "%s: no such array", atom_getsymbolarg(8,argc,argv)->s_name); + else if (!garray_getfloatwords(a2, &npoints2, &vec2)) + pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(8,argc,argv)->s_name); + else if ( ( npoints1 < atom_getfloatarg(5,argc,argv) * atom_getfloatarg(6,argc,argv) ) || ( npoints2 < atom_getfloatarg(5,argc,argv) * atom_getfloatarg(6,argc,argv) ) ) + pd_error(x, "not enough point in tables for iTable"); + else + { + + Xmin = atom_getfloatarg(1, argc, argv); + Xmax = atom_getfloatarg(2, argc, argv); + Ymin = atom_getfloatarg(3, argc, argv); + Ymax = atom_getfloatarg(4, argc, argv); + X = atom_getfloatarg(5, argc, argv); + Y = atom_getfloatarg(6, argc, argv); + + if ( argv[0].a_type == A_FLOAT ) + { + pmpd2d_iTable_i(x, (int)atom_getfloatarg(0,argc,argv), Xmin, Xmax, Ymin, Ymax, X, Y, vec1, vec2); + } + else if ( argv[0].a_type == A_SYMBOL ) + { for (i=0; i < x->nb_mass; i++) + { if (atom_getsymbolarg(0,argc,argv) == x->mass[i].Id) + { + pmpd2d_iTable_i(x, i, Xmin, Xmax, Ymin, Ymax, X, Y, vec1, vec2); + } + } + } + } +} -- cgit v1.2.1