aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2014-01-27 11:27:51 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2014-01-27 11:27:51 +0000
commit355bfd8d94bbdac999247a7778a49a96837fae9e (patch)
tree1b09eaa0304c0fcd683d4a4d319ae529cbbb3944
parent8e2046a5796957c47871f95bc6496b6971043ccf (diff)
add rigididy for iTable
svn path=/trunk/externals/pmpd/; revision=17256
-rw-r--r--examples/65_2d_interactors.pd20
-rw-r--r--pmpd2d_interactor.c55
2 files changed, 38 insertions, 37 deletions
diff --git a/examples/65_2d_interactors.pd b/examples/65_2d_interactors.pd
index 4fc0818..9dcc65a 100644
--- a/examples/65_2d_interactors.pd
+++ b/examples/65_2d_interactors.pd
@@ -1,4 +1,4 @@
-#N canvas 222 423 905 391 10;
+#N canvas 214 443 905 391 10;
#X declare -lib Gem;
#X obj 52 253 pmpd2d;
#X obj 52 78 loadbang;
@@ -117,7 +117,7 @@ RaZ \$3 \$4 0.3 0;
#X connect 10 0 11 0;
#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 188 170 iCircle mobil \$1 \$2 0.2 0.05 1 0 1 -0.2 0;
#X msg 485 71 set iCircle mobil \, adddollar 1 \, adddollar 2 \, add2
0 0 1 0.01 1 0 0.2;
#X msg 486 108 set iCircle mobil \, adddollar 1 \, adddollar 2 \, add2
@@ -132,18 +132,18 @@ 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;
+#N canvas 432 102 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 92 251 outlet;
#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 msg 196 105 0 -1 0 1 -1 0 1 -1 0 1;
+#X msg 193 185 0 -1 -1 -1 0 0 0 1 1 1;
+#X msg 92 61 iTable mobil 0.1 0 1 0 1 3 3 iteractorX iteractorY;
+#X connect 5 0 0 0;
+#X connect 6 0 1 0;
+#X connect 7 0 3 0;
#X restore 188 211 pd iTable;
#X connect 0 0 10 0;
#X connect 1 0 3 0;
diff --git a/pmpd2d_interactor.c b/pmpd2d_interactor.c
index b1e4639..a2c7437 100644
--- a/pmpd2d_interactor.c
+++ b/pmpd2d_interactor.c
@@ -193,7 +193,7 @@ 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)
+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_float K, t_word *tableX, t_word *tableY)
{
t_float Xtable, Ytable, Xindex, Yindex, force1, force2, force;
int index;
@@ -211,11 +211,11 @@ void pmpd2d_iTable_i(t_pmpd2d *x, int i, t_float zone_x_min, t_float zone_x_max,
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;
+ x->mass[i].forceX += K * 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;
+ x->mass[i].forceY += K * force;
}
}
@@ -223,55 +223,56 @@ 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
+ // 1 : K;
+ // 2, 3 : Xmin, Xmax
+ // 4, 5 : Ymin, Ymax physical location of the interator
+ // 6, 7 : matrix size
+ // 8, 9 : table name containing the matrix
t_garray *a1, *a2;
int npoints1, npoints2;
t_word *vec1, *vec2;
- t_float Xmin, Xmax, Ymin, Ymax;
+ t_float Xmin, Xmax, Ymin, Ymax, K;
int X, Y, i;
- if (!((argc==9) && (argv[1].a_type == A_FLOAT) && (argv[2].a_type == A_FLOAT) &&
+ if (!((argc==10) && (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) ) )
+ (argv[6].a_type == A_FLOAT) && (argv[7].a_type == A_FLOAT) && (argv[8].a_type == A_SYMBOL) && (argv[9].a_type == A_SYMBOL) ) )
{
pd_error(x,"bad argument for iTable");
return;
}
+ X = atom_getfloatarg(6, argc, argv);
+ Y = atom_getfloatarg(7, argc, argv);
- 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)))
+ if (!(a1 = (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))
+ else if (!garray_getfloatwords(a1, &npoints1, &vec1))
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) ) )
+ else if (!(a2 = (t_garray *)pd_findbyclass(atom_getsymbolarg(9,argc,argv), garray_class)))
+ pd_error(x, "%s: no such array", atom_getsymbolarg(9,argc,argv)->s_name);
+ else if (!garray_getfloatwords(a2, &npoints2, &vec2))
+ pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(9,argc,argv)->s_name);
+ else if ( ( npoints1 < X * Y ) || ( npoints2 < X * Y ) )
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);
-
+ K = atom_getfloatarg(1, argc, argv);
+ Xmin = atom_getfloatarg(2, argc, argv);
+ Xmax = atom_getfloatarg(3, argc, argv);
+ Ymin = atom_getfloatarg(4, argc, argv);
+ Ymax = atom_getfloatarg(5, 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);
+ pmpd2d_iTable_i(x, (int)atom_getfloatarg(0,argc,argv), Xmin, Xmax, Ymin, Ymax, X, Y, K, 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);
+ pmpd2d_iTable_i(x, i, Xmin, Xmax, Ymin, Ymax, X, Y, K, vec1, vec2);
}
}
}