diff options
author | Cyrille Henry <nusmuk@users.sourceforge.net> | 2006-06-13 17:54:51 +0000 |
---|---|---|
committer | Cyrille Henry <nusmuk@users.sourceforge.net> | 2006-06-13 17:54:51 +0000 |
commit | 60b6f66d66cdae09d382323779f835ba1991207a (patch) | |
tree | 2fd4a275d337fd1ce8f37e3aaa697583814336c8 | |
parent | 46fbfa2f1c8ae91ab393170ba7b9dc24f01d7abe (diff) |
*** empty log message ***
svn path=/trunk/externals/pmpd/; revision=5225
-rwxr-xr-x | help/help-link.pd | 112 | ||||
-rwxr-xr-x | help/help-mass.pd | 53 | ||||
-rwxr-xr-x | src/tLink2D.c | 157 | ||||
-rwxr-xr-x | src/tLink3D.c | 152 |
4 files changed, 474 insertions, 0 deletions
diff --git a/help/help-link.pd b/help/help-link.pd new file mode 100755 index 0000000..a5ee327 --- /dev/null +++ b/help/help-link.pd @@ -0,0 +1,112 @@ +#N canvas 331 134 656 710 10; +#N canvas 85 7 622 478 physical 0; +#X text 23 268 Generated force is the sum of 3 differents forces : +; +#X text 102 142 eL[t] = L[t] - L[0]; +#X text 78 166 -> Elongation-Speed of a link :; +#X text 101 184 speedOf(eL[t]) = eL[t] - eL[t-1]; +#X text 78 106 -> Elongation of a link (eL) is equal to the length +of the link minus its initial length :; +#X text 78 46 -> Length of a link (L) is equal to the difference between +positions of Masses (M1 \, M2) :; +#X text 102 79 L[t] = positionOf(M1[t]) - positionOf(M2[t]); +#X text 78 206 -> Speed of a mass :; +#X text 77 346 -> Damping of a link (proportional to) :; +#X text 77 385 -> Damping of a mass is proportional to :; +#X text 102 224 speedOf(M[t]) = positionOf(M[t-1]) - positionOf(M[t]) +; +#X text 77 306 -> Rigidity of a link (proportional to) :; +#X text 100 403 Fdm :: D2 * speedOf(M[t]); +#X text 100 364 Fdl :: D * speedOf(eL[t]); +#X text 100 324 Frl :: K * eL[t]; +#X text 24 8 Notation (at time t) :; +#X restore 239 679 pd physical equations; +#X text 217 593 value range :; +#X text 260 13 link between 2 masses; +#X text 88 562 1 : force to apply to mass 1 (float); +#X text 89 530 2 : force to apply to mass 2 (float); +#X text 257 381 if the size of the link is < Lmin then force of the +link will be null; +#X text 263 432 if the size of the link is > Lmax then force of the +link will be null; +#X text 242 622 K \, D \, D2 are positive. Negative values make strange +(non physical) things. High values can cause numerical instability. +; +#X obj 25 501 link; +#X text 127 471 2 : position of mass 2 (float); +#X floatatom 25 562 5 0 0 0 - - -; +#X floatatom 44 529 5 0 0 0 - - -; +#X text 225 68 1 : name; +#X floatatom 93 471 5 0 0 0 - - -; +#X msg 105 125 setL 0; +#X msg 105 154 setK 0; +#X msg 105 184 setD 0; +#X msg 104 214 setD2 0; +#X text 226 122 2 : Lenght; +#X text 250 139 change Length of the link; +#X text 226 153 3 : rigidity; +#X text 249 168 change rigidity; +#X text 230 238 change position of mass 1; +#X msg 106 265 bang; +#X text 228 258 compute and output forces \, according to the last +masses positions; +#X msg 107 291 reset; +#X msg 109 316 resetF; +#X msg 109 338 resetL; +#X msg 110 366 setLmin 0; +#X text 229 185 4 : Damping of the link deformation; +#X text 231 214 5 : Damping of the masses speed; +#X obj 105 240 0; +#X text 227 288 reset position of masses and set speed of the link +to zero; +#X text 230 314 reset damping and inertial force of the link.; +#X text 228 339 set the length of the liaison to it's curent lengh +; +#X text 234 363 set the minimum size of the link; +#X text 233 416 set the maximum size of the link; +#X msg 110 416 setLmax 10000; +#X text 250 84 you can use it in pd to send messages / bang / etc to +the lia. this is for simplifying connection.; +#N canvas 292 12 556 402 Lmin 0; +#X text 23 14 Lmin and Lmax are useful for non-linear links; +#X text 24 42 If the length of the link is < Lmin then force of the +link will be null; +#X text 24 86 If the length of the link is > Lmax then force of the +link will be null; +#X text 13 137 Case Lmin = 0 and Lmax = 10 :; +#X text 38 163 At L = 0 \, links can break (a bit like a magnet.); +#X text 38 183 At L = 10 \, this is a repulsive-only link useful for +interaction between two structures.; +#X text 12 237 Case Lmin = 10 and Lmax = very positive :; +#X text 38 262 At L = 10 \, this is an attractive link only; +#X text 13 304 note : D2 is damping associated with the mass but not +the link. So it's not affected by Lmin and Lmax; +#X restore 477 456 pd Lmin Lmax exemple; +#N canvas 0 0 231 186 name 0; +#X obj 23 6 bng 15 250 50 0 empty empty empty 0 -6 0 8 -262144 -1 -1 +; +#X obj 23 27 s lia_foo; +#X obj 116 102 lia lia_foo; +#X obj 19 125 print lia1; +#X obj 116 126 print lia2; +#X obj 19 101 lia lia_foo; +#X connect 0 0 1 0; +#X connect 2 0 4 0; +#X connect 5 0 3 0; +#X restore 496 117 pd name example; +#X text 138 33 link : get position of masses \, output forces to apply +; +#X connect 8 0 10 0; +#X connect 8 1 11 0; +#X connect 13 0 8 1; +#X connect 14 0 8 0; +#X connect 15 0 8 0; +#X connect 16 0 8 0; +#X connect 17 0 8 0; +#X connect 23 0 8 0; +#X connect 25 0 8 0; +#X connect 26 0 8 0; +#X connect 27 0 8 0; +#X connect 28 0 8 0; +#X connect 31 0 8 0; +#X connect 37 0 8 0; diff --git a/help/help-mass.pd b/help/help-mass.pd new file mode 100755 index 0000000..5344cdc --- /dev/null +++ b/help/help-mass.pd @@ -0,0 +1,53 @@ +#N canvas 10 17 695 631 10; +#X text 317 6 masse; +#X text 153 80 M is positive. negative value give non physical things. +; +#X text 152 37 the somme of the forces apply to a masse modifie its +velocity (depending of it's weight). the position his change according +to the velocity and the weight of the masse; +#X text 259 169 2 : M = weith of the masse; +#X text 304 321 if the position of the masse is < Xmin then position +will be Xmin; +#X msg 123 448 resetF; +#X text 258 452 reset the total forces applied to the masse; +#X msg 124 417 reset; +#X text 258 413 reset position (to it's initial value) and forces to +zero. send it's position to it's outlet.; +#X text 281 224 change position of the masse \, and reset memory (for +history).; +#X text 283 188 change weith of the masse; +#X text 302 307 set the minimum and maximum position of the masse; +#X msg 124 356 bang; +#X msg 122 483 loadbang; +#X text 251 485 output curent position; +#X text 262 353 compute position and output it; +#X text 260 387 add force to this mass; +#X msg 120 173 setM 1; +#X text 261 117 1 : name; +#X text 282 135 this is the name of the mass. you can set value to +this name instead of making a pd connection.; +#X text 156 23 mass : get liaison forces and output position; +#X msg 120 283 setXmin -10000 \, setXmax 10000; +#X msg 121 209 setX 0; +#X text 259 208 3 : position of the masse; +#X obj 36 520 mass; +#X floatatom 36 589 5 0 0 0 - - -; +#X floatatom 45 572 5 0 0 0 - - -; +#X floatatom 55 554 5 0 0 0 - - -; +#X text 97 553 X velocity of the masse; +#X text 95 572 X force apply to the masse; +#X text 95 590 X positin of the masse; +#X text 260 308 Xmin; +#X text 260 324 Xmax; +#X obj 124 386 0; +#X connect 5 0 24 0; +#X connect 7 0 24 0; +#X connect 12 0 24 0; +#X connect 13 0 24 0; +#X connect 17 0 24 0; +#X connect 21 0 24 0; +#X connect 22 0 24 0; +#X connect 24 0 25 0; +#X connect 24 1 26 0; +#X connect 24 2 27 0; +#X connect 33 0 24 0; diff --git a/src/tLink2D.c b/src/tLink2D.c new file mode 100755 index 0000000..c1e27ed --- /dev/null +++ b/src/tLink2D.c @@ -0,0 +1,157 @@ +#include "m_pd.h"
+#include "math.h"
+
+static t_class *tLink2D_class;
+
+typedef struct _tLink2D {
+ t_object x_obj;
+ t_float distance_old, position2Dx1, position2Dy1, position2Dx2, position2Dy2;
+ t_outlet *force1;
+ t_outlet *force2;
+ t_outlet *force3;
+ t_outlet *force4;
+ t_symbol *x_sym; // receive
+} t_tLink2D;
+
+void tLink2D_reset(t_tLink2D *x)
+{
+}
+
+void tLink2D_resetF(t_tLink2D *x)
+{
+}
+
+void tLink2D_resetL(t_tLink2D *x)
+{
+}
+
+void tLink2D_setK(t_tLink2D *x, t_float K)
+{
+}
+
+void tLink2D_setL(t_tLink2D *x, t_float L)
+{
+}
+
+void tLink2D_setD(t_tLink2D *x, t_float D)
+{
+}
+
+void tLink2D_setD2(t_tLink2D *x, t_float D)
+{
+}
+
+void tLink2D_Lmin(t_tLink2D *x, t_float Lmin)
+{
+}
+
+void tLink2D_Lmax(t_tLink2D *x, t_float Lmax)
+{
+}
+
+void tLink2D_position2D(t_tLink2D *x, t_floatarg f1, t_floatarg f2)
+{
+ x->position2Dx1 = f1;
+ x->position2Dy1 = f2;
+}
+
+void tLink2D_position2D2(t_tLink2D *x, t_floatarg f1, t_floatarg f2)
+{
+ x->position2Dx2 = f1;
+ x->position2Dy2 = f2;
+}
+
+void tLink2D_bang(t_tLink2D *x)
+{
+ t_float vitesse, distance, orientation;
+ t_atom force1[2];
+
+ distance = sqrt ( pow((x->position2Dx2-x->position2Dx1), 2) + pow((x->position2Dy2-x->position2Dy1), 2) );
+
+ vitesse = x->distance_old - distance;
+
+ SETFLOAT(&(force1[0]), (x->position2Dx2 + x->position2Dx1)/ 2);
+ SETFLOAT(&(force1[1]), (x->position2Dy2 + x->position2Dy1)/ 2);
+
+ outlet_anything(x->force4, gensym("position2D"), 2, force1);
+
+ if ((x->position2Dx2-x->position2Dx1) != 0)
+ {
+ orientation = 180/3.14159 * atan((float)(x->position2Dy2 - x->position2Dy1)/(x->position2Dx2 - x->position2Dx1));
+ if ((x->position2Dx2 - x->position2Dx1)<0)
+ orientation +=180;
+ if (orientation<0)
+ orientation +=360;
+
+ outlet_float(x->force3, orientation);
+ }
+ else
+ {
+ if ((x->position2Dy2 - x->position2Dy1)<0)
+ outlet_float(x->force3,270);
+ else
+ outlet_float(x->force3,90);
+ }
+
+ outlet_float(x->force2, vitesse);
+
+ outlet_float(x->force1, distance);
+
+ x->distance_old = distance;
+
+}
+
+
+static void tLink2D_free(t_tLink2D *x)
+{
+ pd_unbind(&x->x_obj.ob_pd, x->x_sym);
+}
+
+void *tLink2D_new(t_symbol *s)
+{
+ t_tLink2D *x = (t_tLink2D *)pd_new(tLink2D_class);
+
+ x->x_sym = s;
+ pd_bind(&x->x_obj.ob_pd, s);
+
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("position2D"), gensym("position2D2"));
+
+ x->force1=outlet_new(&x->x_obj, 0);
+ x->force2=outlet_new(&x->x_obj, 0);
+ x->force3=outlet_new(&x->x_obj, 0);
+ x->force4=outlet_new(&x->x_obj, 0);
+
+ x->distance_old = 0;
+
+ return (x);
+}
+
+void tLink2D_setup(void)
+{
+
+ tLink2D_class = class_new(gensym("tLink2D"),
+ (t_newmethod)tLink2D_new,
+ (t_method)tLink2D_free,
+ sizeof(t_tLink2D),
+ CLASS_DEFAULT, A_DEFSYM, 0);
+
+ class_addcreator((t_newmethod)tLink2D_new, gensym("tLia2D"), A_DEFSYM, 0);
+
+
+ class_addbang(tLink2D_class, tLink2D_bang);
+
+ class_addmethod(tLink2D_class, (t_method)tLink2D_position2D, gensym("position2D"), A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(tLink2D_class, (t_method)tLink2D_position2D2, gensym("position2D2"), A_DEFFLOAT, A_DEFFLOAT, 0);
+
+ // only for the object not to output erreor when having the same name as the link
+ class_addmethod(tLink2D_class, (t_method)tLink2D_reset, gensym("reset"), 0);
+ class_addmethod(tLink2D_class, (t_method)tLink2D_resetL, gensym("resetL"), 0);
+ class_addmethod(tLink2D_class, (t_method)tLink2D_resetF, gensym("resetF"), 0);
+ class_addmethod(tLink2D_class, (t_method)tLink2D_setD, gensym("setD"), A_DEFFLOAT, 0);
+ class_addmethod(tLink2D_class, (t_method)tLink2D_setD2, gensym("setD2"), A_DEFFLOAT, 0);
+ class_addmethod(tLink2D_class, (t_method)tLink2D_setK, gensym("setK"), A_DEFFLOAT, 0);
+ class_addmethod(tLink2D_class, (t_method)tLink2D_setL, gensym("setL"), A_DEFFLOAT, 0);
+ class_addmethod(tLink2D_class, (t_method)tLink2D_Lmin, gensym("setLmin"), A_DEFFLOAT, 0);
+ class_addmethod(tLink2D_class, (t_method)tLink2D_Lmax, gensym("setLmax"), A_DEFFLOAT, 0);
+
+}
diff --git a/src/tLink3D.c b/src/tLink3D.c new file mode 100755 index 0000000..b4f623c --- /dev/null +++ b/src/tLink3D.c @@ -0,0 +1,152 @@ +#include "m_pd.h"
+#include "math.h"
+
+static t_class *tLink3D_class;
+
+typedef struct _tLink3D {
+ t_object x_obj;
+ t_float distance_old, position2Dx1, position2Dy1, position2Dz1, position2Dx2, position2Dy2, position2Dz2;
+ t_outlet *force1;
+ t_outlet *force2;
+ t_outlet *force3;
+ t_outlet *force4;
+ t_symbol *x_sym; // receive
+} t_tLink3D;
+
+void tLink3D_reset(t_tLink3D *x)
+{
+}
+
+void tLink3D_resetF(t_tLink3D *x)
+{
+}
+
+void tLink3D_resetL(t_tLink3D *x)
+{
+}
+
+
+void tLink3D_setK(t_tLink3D *x, t_float K)
+{
+}
+
+void tLink3D_setL(t_tLink3D *x, t_float L)
+{
+}
+
+void tLink3D_setD(t_tLink3D *x, t_float D)
+{
+}
+
+void tLink3D_setD2(t_tLink3D *x, t_float D)
+{
+}
+
+void tLink3D_Lmin(t_tLink3D *x, t_float Lmin)
+{
+}
+
+void tLink3D_Lmax(t_tLink3D *x, t_float Lmax)
+{
+}
+
+
+void tLink3D_position3D(t_tLink3D *x, t_floatarg f1, t_floatarg f2, t_floatarg f3)
+{
+ x->position2Dx1 = f1;
+ x->position2Dy1 = f2;
+ x->position2Dz1 = f3;
+}
+
+void tLink3D_position3D2(t_tLink3D *x, t_floatarg f1, t_floatarg f2, t_floatarg f3)
+{
+ x->position2Dx2 = f1;
+ x->position2Dy2 = f2;
+ x->position2Dz2 = f3;
+}
+
+void tLink3D_bang(t_tLink3D *x)
+{
+ t_float vitesse, distance, orientation;
+ t_atom force1[3];
+
+ distance = sqrt ( pow((x->position2Dx2-x->position2Dx1), 2) + pow((x->position2Dy2-x->position2Dy1), 2) + pow((x->position2Dz2-x->position2Dz1), 2) );
+
+ vitesse = x->distance_old - distance;
+
+
+ SETFLOAT(&(force1[0]), (x->position2Dx2 + x->position2Dx1)/ 2);
+ SETFLOAT(&(force1[1]), (x->position2Dy2 + x->position2Dy1)/ 2);
+ SETFLOAT(&(force1[2]), (x->position2Dz2 + x->position2Dz1)/ 2);
+
+ outlet_anything(x->force4, gensym("position3D"), 3, force1);
+
+
+ SETFLOAT(&(force1[0]), (x->position2Dx2 - x->position2Dx1)/ distance);
+ SETFLOAT(&(force1[1]), (x->position2Dy2 - x->position2Dy1)/ distance);
+ SETFLOAT(&(force1[2]), (x->position2Dz2 - x->position2Dz1)/ distance);
+
+ outlet_anything(x->force3, gensym("vector3D"), 3, force1);
+
+ outlet_float(x->force2, vitesse);
+
+ outlet_float(x->force1, distance);
+
+ x->distance_old = distance;
+
+}
+
+
+static void tLink3D_free(t_tLink3D *x)
+{
+ pd_unbind(&x->x_obj.ob_pd, x->x_sym);
+}
+
+void *tLink3D_new(t_symbol *s)
+{
+
+ t_tLink3D *x = (t_tLink3D *)pd_new(tLink3D_class);
+
+ x->x_sym = s;
+ pd_bind(&x->x_obj.ob_pd, s);
+
+ inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("position3D"), gensym("position3D2"));
+
+ x->force1=outlet_new(&x->x_obj, 0);
+ x->force2=outlet_new(&x->x_obj, 0);
+ x->force3=outlet_new(&x->x_obj, 0);
+ x->force4=outlet_new(&x->x_obj, 0);
+
+ x->distance_old = 0;
+
+ return (x);
+}
+
+void tLink3D_setup(void)
+{
+
+ tLink3D_class = class_new(gensym("tLink3D"),
+ (t_newmethod)tLink3D_new,
+ (t_method)tLink3D_free,
+ sizeof(t_tLink3D),
+ CLASS_DEFAULT, A_DEFSYM, 0);
+
+ class_addcreator((t_newmethod)tLink3D_new, gensym("tLia3D"), A_DEFSYM, 0);
+
+ class_addbang(tLink3D_class, tLink3D_bang);
+
+ class_addmethod(tLink3D_class, (t_method)tLink3D_position3D, gensym("position3D"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(tLink3D_class, (t_method)tLink3D_position3D2, gensym("position3D2"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+
+ // only for the object not to output erreor when having the same name as the link
+ class_addmethod(tLink3D_class, (t_method)tLink3D_reset, gensym("reset"), 0);
+ class_addmethod(tLink3D_class, (t_method)tLink3D_resetL, gensym("resetL"), 0);
+ class_addmethod(tLink3D_class, (t_method)tLink3D_resetF, gensym("resetF"), 0);
+ class_addmethod(tLink3D_class, (t_method)tLink3D_setD, gensym("setD"), A_DEFFLOAT, 0);
+ class_addmethod(tLink3D_class, (t_method)tLink3D_setD2, gensym("setD2"), A_DEFFLOAT, 0);
+ class_addmethod(tLink3D_class, (t_method)tLink3D_setK, gensym("setK"), A_DEFFLOAT, 0);
+ class_addmethod(tLink3D_class, (t_method)tLink3D_setL, gensym("setL"), A_DEFFLOAT, 0);
+ class_addmethod(tLink3D_class, (t_method)tLink3D_Lmin, gensym("setLmin"), A_DEFFLOAT, 0);
+ class_addmethod(tLink3D_class, (t_method)tLink3D_Lmax, gensym("setLmax"), A_DEFFLOAT, 0);
+
+}
|