aboutsummaryrefslogtreecommitdiff
path: root/msd2D
diff options
context:
space:
mode:
authorN.N. <nimon@users.sourceforge.net>2005-05-02 12:43:10 +0000
committerN.N. <nimon@users.sourceforge.net>2005-05-02 12:43:10 +0000
commit08139b3d3bf914933c2e040e559d4a62ded735ea (patch)
treea12efdad407c62de06e761ff5b4c66a80466cbd1 /msd2D
parentedac6167f8516c37e96ac1821678178c7cd0caf9 (diff)
MSD version 0.05
svn path=/trunk/externals/nusmuk/; revision=2880
Diffstat (limited to 'msd2D')
-rw-r--r--msd2D/01_msd2Dtest.pd90
-rw-r--r--msd2D/02_msd2Dadd.pd285
-rwxr-xr-xmsd2D/main.cpp50
3 files changed, 236 insertions, 189 deletions
diff --git a/msd2D/01_msd2Dtest.pd b/msd2D/01_msd2Dtest.pd
index ebb3dff..7b20575 100644
--- a/msd2D/01_msd2Dtest.pd
+++ b/msd2D/01_msd2Dtest.pd
@@ -33,7 +33,6 @@
#X obj 53 323 t b;
#X msg 53 345 bang \, get massesPos \, get linksPos;
#X text 292 313 COMPUTE AND GET ALL MASSES AND LINKS POSITIONS;
-#X msg 85 383 setD souple 0.01;
#X msg 216 384 setK souple 1;
#X msg 85 403 setD souple 1;
#X msg 216 404 setK souple 2;
@@ -49,24 +48,24 @@
#X obj 127 109 - 4;
#X obj 192 87 / 12.5;
#X obj 192 110 - 4;
-#X obj 64 114 gemhead;
#X obj 48 177 separator;
#X obj 48 153 any;
#X obj 125 136 t b f;
#X obj 127 57 unpack f f f;
-#X connect 0 0 11 0;
+#X obj 64 114 gemhead 45;
+#X connect 0 0 10 0;
#X connect 1 0 2 0;
#X connect 3 0 4 0;
-#X connect 4 0 10 0;
+#X connect 4 0 9 0;
#X connect 5 0 6 0;
#X connect 6 0 1 2;
-#X connect 7 0 9 1;
-#X connect 8 0 1 0;
+#X connect 7 0 1 0;
+#X connect 8 0 7 0;
#X connect 9 0 8 0;
-#X connect 10 0 9 0;
-#X connect 10 1 1 1;
-#X connect 11 1 3 0;
-#X connect 11 2 5 0;
+#X connect 9 1 1 1;
+#X connect 10 1 3 0;
+#X connect 10 2 5 0;
+#X connect 11 0 8 1;
#X restore 134 591 pd massrender;
#X obj 53 562 route linksPos massesPos;
#X text 261 572 DISPLAY MASSES AND LINKS;
@@ -109,7 +108,6 @@
#X obj 127 109 - 4;
#X obj 187 87 / 12.5;
#X obj 187 110 - 4;
-#X obj 64 114 gemhead;
#X obj 48 177 separator;
#X obj 48 153 any;
#X obj 125 136 t b f;
@@ -121,43 +119,45 @@
#X obj 155 189 pack f f 0;
#X obj 241 190 pack f f 0;
#X obj 127 57 unpack f f f f f;
-#X connect 0 0 16 0;
+#X obj 64 114 gemhead 45;
+#X connect 0 0 15 0;
#X connect 1 0 2 0;
-#X connect 2 0 8 0;
+#X connect 2 0 7 0;
#X connect 3 0 4 0;
-#X connect 4 0 14 1;
-#X connect 5 0 7 1;
-#X connect 6 0 13 0;
+#X connect 4 0 13 1;
+#X connect 5 0 12 0;
+#X connect 6 0 5 0;
#X connect 7 0 6 0;
-#X connect 8 0 7 0;
-#X connect 8 1 14 0;
-#X connect 9 0 10 0;
-#X connect 10 0 15 0;
-#X connect 11 0 12 0;
-#X connect 12 0 15 1;
-#X connect 14 0 13 1;
-#X connect 15 0 13 2;
-#X connect 16 1 1 0;
-#X connect 16 2 3 0;
-#X connect 16 3 9 0;
-#X connect 16 4 11 0;
+#X connect 7 1 13 0;
+#X connect 8 0 9 0;
+#X connect 9 0 14 0;
+#X connect 10 0 11 0;
+#X connect 11 0 14 1;
+#X connect 13 0 12 1;
+#X connect 14 0 12 2;
+#X connect 15 1 1 0;
+#X connect 15 2 3 0;
+#X connect 15 3 8 0;
+#X connect 15 4 10 0;
+#X connect 16 0 6 1;
#X restore 53 613 pd linkrender;
#X msg 153 160 50 50;
#X msg 189 91 mass fix 0 100 50 50;
+#X msg 85 383 setD souple 0;
#X connect 0 0 20 0;
#X connect 3 0 2 0;
#X connect 4 0 5 0;
#X connect 6 0 2 0;
-#X connect 7 0 38 0;
+#X connect 7 0 37 0;
#X connect 7 1 1 0;
#X connect 16 0 7 0;
#X connect 17 0 20 0;
#X connect 18 0 16 0;
#X connect 20 0 24 0;
-#X connect 20 1 48 0;
+#X connect 20 1 47 0;
#X connect 20 1 22 0;
-#X connect 20 2 46 0;
-#X connect 20 3 49 0;
+#X connect 20 2 45 0;
+#X connect 20 3 48 0;
#X connect 20 4 18 0;
#X connect 21 0 16 0;
#X connect 22 0 16 0;
@@ -168,18 +168,18 @@
#X connect 29 0 7 0;
#X connect 30 0 7 0;
#X connect 31 0 7 0;
-#X connect 32 0 7 0;
+#X connect 34 0 7 0;
#X connect 35 0 7 0;
-#X connect 36 0 7 0;
-#X connect 38 0 47 0;
-#X connect 38 1 37 0;
-#X connect 38 2 1 0;
-#X connect 40 0 42 0;
-#X connect 40 0 43 0;
-#X connect 41 0 40 0;
+#X connect 37 0 46 0;
+#X connect 37 1 36 0;
+#X connect 37 2 1 0;
+#X connect 39 0 41 0;
+#X connect 39 0 42 0;
+#X connect 40 0 39 0;
+#X connect 41 0 7 0;
#X connect 42 0 7 0;
-#X connect 43 0 7 0;
-#X connect 45 0 16 0;
-#X connect 46 0 45 0;
-#X connect 48 0 40 1;
-#X connect 49 0 16 0;
+#X connect 44 0 16 0;
+#X connect 45 0 44 0;
+#X connect 47 0 39 1;
+#X connect 48 0 16 0;
+#X connect 49 0 7 0;
diff --git a/msd2D/02_msd2Dadd.pd b/msd2D/02_msd2Dadd.pd
index 6703238..549c132 100644
--- a/msd2D/02_msd2Dadd.pd
+++ b/msd2D/02_msd2Dadd.pd
@@ -10,9 +10,8 @@
#X msg 511 526 0 \, destroy;
#X obj 481 320 gemhead;
#X obj 481 343 world_light;
-#X msg 191 106 mass fix 0 100 50 50;
-#N canvas 177 95 946 729 synthese 0;
-#X obj 268 68 inlet;
+#N canvas 177 95 946 729 synthese 1;
+#X obj 267 9 inlet;
#X msg -35 224 \$1 50;
#X obj -35 246 line~;
#X obj -75 250 *~;
@@ -84,12 +83,6 @@
#X obj 616 453 line~;
#X obj 576 457 *~;
#X obj 433 505 dac~;
-#X obj -87 398 osc~ 55;
-#X obj 9 398 osc~ 110;
-#X obj 102 400 osc~ 166;
-#X obj 194 398 osc~ 222;
-#X obj 295 401 osc~ 444;
-#X obj 390 401 osc~ 890;
#X obj 483 403 osc~ 1113;
#X obj 575 401 osc~ 2229;
#X obj 307 371 / 500;
@@ -103,10 +96,16 @@
#X obj 112 196 osc~ 165;
#X obj 305 197 osc~ 267;
#X obj 400 197 osc~ 311;
-#X obj 493 199 osc~ 444;
-#X obj 585 197 osc~ 509;
-#X obj 268 99 route 1 5 9 13 17 21 25 29;
-#X connect 0 0 93 0;
+#X obj 268 44 route 1 5 9 13 17 21 25 29;
+#X obj 493 199 osc~ 366;
+#X obj 585 197 osc~ 421;
+#X obj -87 398 osc~ 444;
+#X obj 9 398 osc~ 554;
+#X obj 102 400 osc~ 664;
+#X obj 194 398 osc~ 776;
+#X obj 295 401 osc~ 888;
+#X obj 390 401 osc~ 1000;
+#X connect 0 0 85 0;
#X connect 1 0 2 0;
#X connect 2 0 3 1;
#X connect 3 0 13 0;
@@ -186,98 +185,80 @@
#X connect 68 0 69 0;
#X connect 69 0 70 1;
#X connect 70 0 71 1;
-#X connect 72 0 44 0;
-#X connect 73 0 47 0;
-#X connect 74 0 50 0;
-#X connect 75 0 53 0;
-#X connect 76 0 61 0;
-#X connect 77 0 64 0;
-#X connect 78 0 67 0;
-#X connect 79 0 70 0;
-#X connect 80 0 59 0;
-#X connect 81 0 62 0;
-#X connect 82 0 55 0;
-#X connect 82 1 56 0;
-#X connect 83 0 57 0;
-#X connect 83 1 58 0;
-#X connect 84 0 80 0;
-#X connect 84 1 81 0;
-#X connect 85 0 87 0;
-#X connect 85 1 86 0;
-#X connect 86 0 68 0;
-#X connect 87 0 65 0;
-#X connect 88 0 9 0;
-#X connect 89 0 20 0;
-#X connect 90 0 23 0;
-#X connect 91 0 26 0;
-#X connect 92 0 29 0;
-#X connect 93 0 36 0;
-#X connect 93 1 37 0;
-#X connect 93 2 38 0;
-#X connect 93 3 39 0;
-#X connect 93 4 82 0;
-#X connect 93 5 83 0;
-#X connect 93 6 84 0;
-#X connect 93 7 85 0;
+#X connect 72 0 67 0;
+#X connect 73 0 70 0;
+#X connect 74 0 59 0;
+#X connect 75 0 62 0;
+#X connect 76 0 55 0;
+#X connect 76 1 56 0;
+#X connect 77 0 57 0;
+#X connect 77 1 58 0;
+#X connect 78 0 74 0;
+#X connect 78 1 75 0;
+#X connect 79 0 81 0;
+#X connect 79 1 80 0;
+#X connect 80 0 68 0;
+#X connect 81 0 65 0;
+#X connect 82 0 9 0;
+#X connect 83 0 20 0;
+#X connect 84 0 23 0;
+#X connect 85 0 36 0;
+#X connect 85 1 37 0;
+#X connect 85 2 38 0;
+#X connect 85 3 39 0;
+#X connect 85 4 76 0;
+#X connect 85 5 77 0;
+#X connect 85 6 78 0;
+#X connect 85 7 79 0;
+#X connect 86 0 26 0;
+#X connect 87 0 29 0;
+#X connect 88 0 44 0;
+#X connect 89 0 47 0;
+#X connect 90 0 50 0;
+#X connect 91 0 53 0;
+#X connect 92 0 61 0;
+#X connect 93 0 64 0;
#X restore 230 679 pd synthese;
-#N canvas 311 224 409 530 gemmouse 0;
-#X obj 114 29 gemmouse;
-#X obj 96 266 outlet;
-#X obj 114 83 - 0;
-#X obj 165 97 + 100;
-#X obj 114 60 / 5;
-#X obj 165 74 / -5;
-#X obj 32 81 t b;
-#X obj 32 37 inlet;
-#X obj 96 206 pack 0 0;
-#X obj 32 108 spigot;
-#X obj 96 177 f;
-#X connect 0 0 4 0;
-#X connect 0 1 5 0;
-#X connect 0 2 9 1;
-#X connect 2 0 10 1;
-#X connect 3 0 8 1;
-#X connect 4 0 2 0;
-#X connect 5 0 3 0;
-#X connect 6 0 9 0;
-#X connect 7 0 6 0;
-#X connect 8 0 1 0;
-#X connect 9 0 10 0;
-#X connect 10 0 8 0;
-#X restore 289 476 pd gemmouse;
-#X obj 256 447 gemhead;
-#X msg 253 515 posX fix \$1;
-#X msg 253 537 posY fix \$2;
-#X msg 155 225 50 50;
+#X obj 295 454 gemhead;
#X msg 155 258 Xmax 100 \, Xmin 0 \, Ymax 100 \, Ymin 0;
#X msg 511 503 reset \, create \, lighting 1 \, 1;
#X obj 52 399 t b;
-#N canvas 643 123 605 590 massrender 0;
+#N canvas 643 123 605 590 massrender 1;
#X obj 127 22 inlet;
-#X obj 48 203 translateXYZ;
-#X obj 48 229 sphere 0.1;
+#X obj 48 230 translateXYZ;
+#X obj 48 321 sphere 0.1;
#X obj 127 86 / 12.5;
#X obj 127 109 - 4;
#X obj 192 87 / 12.5;
#X obj 192 110 - 4;
#X obj 64 114 gemhead;
-#X obj 48 177 separator;
-#X obj 48 153 any;
-#X obj 125 136 t b f;
+#X obj 48 204 separator;
+#X obj 48 180 any;
#X obj 127 57 unpack f f f;
-#X connect 0 0 11 0;
-#X connect 1 0 2 0;
+#X obj 48 283 color 1 1 1;
+#X msg 171 224 1 \$1 \$1;
+#X obj 171 202 / 29;
+#X obj 127 136 t b f b;
+#X obj 171 177 f;
+#X connect 0 0 10 0;
+#X connect 1 0 11 0;
#X connect 3 0 4 0;
-#X connect 4 0 10 0;
+#X connect 4 0 14 0;
#X connect 5 0 6 0;
#X connect 6 0 1 2;
#X connect 7 0 9 1;
#X connect 8 0 1 0;
#X connect 9 0 8 0;
-#X connect 10 0 9 0;
-#X connect 10 1 1 1;
-#X connect 11 1 3 0;
-#X connect 11 2 5 0;
+#X connect 10 0 15 1;
+#X connect 10 1 3 0;
+#X connect 10 2 5 0;
+#X connect 11 0 2 0;
+#X connect 12 0 11 1;
+#X connect 13 0 12 0;
+#X connect 14 0 9 0;
+#X connect 14 1 1 1;
+#X connect 14 2 15 0;
+#X connect 15 0 13 0;
#X restore 141 657 pd massrender;
#N canvas 284 227 587 558 linkrender 0;
#X obj 93 25 inlet;
@@ -347,73 +328,91 @@
#X msg 71 498 forceX mob -200;
#X msg 52 420 bang \, get massesPos \, get linksPos \, get massesSpeeds
1 5 9 13 17 21 25 29;
-#X obj 173 126 repeat 40;
-#X obj 79 187 repeat 40;
#X msg 71 478 forceX mob 200;
#X text 175 41 Reset;
#X text 484 171 Random positions and masses;
#X text 370 502 1 Create window -->;
#X text 405 643 3 Drag mouse;
-#X text 174 480 Add force;
+#X text 196 484 Add force;
#X msg 522 585 \; pd dsp 1;
#X text 396 591 2 SET DSP ON -->;
+#N canvas 311 224 409 530 gemmouse2 0;
+#X obj 114 29 gemmouse;
+#X obj 96 266 outlet;
+#X obj 114 83 - 0;
+#X obj 165 97 + 100;
+#X obj 114 60 / 5;
+#X obj 165 74 / -5;
+#X obj 32 81 t b;
+#X obj 32 37 inlet;
+#X obj 96 177 f;
+#X obj 96 206 pack 0 0 0;
+#X connect 0 0 4 0;
+#X connect 0 1 5 0;
+#X connect 0 2 9 2;
+#X connect 2 0 8 1;
+#X connect 3 0 9 1;
+#X connect 4 0 2 0;
+#X connect 5 0 3 0;
+#X connect 6 0 8 0;
+#X connect 7 0 6 0;
+#X connect 8 0 9 0;
+#X connect 9 0 1 0;
+#X restore 295 476 pd gemmouse2;
+#X msg 295 518 grabMass \$1 \$2 \$3;
+#X obj 173 126 repeat 30;
+#X obj 79 187 repeat 29;
#X connect 0 0 6 0;
#X connect 1 0 4 0;
#X connect 2 0 0 0;
#X connect 3 0 4 0;
-#X connect 4 0 47 0;
-#X connect 4 1 16 0;
-#X connect 4 1 17 0;
-#X connect 4 2 46 0;
-#X connect 4 3 10 0;
+#X connect 4 0 52 0;
+#X connect 4 1 12 0;
+#X connect 4 2 51 0;
#X connect 4 4 2 0;
-#X connect 4 4 36 0;
-#X connect 4 4 28 0;
-#X connect 4 4 24 0;
-#X connect 4 4 27 0;
-#X connect 6 0 43 0;
+#X connect 4 4 31 0;
+#X connect 4 4 23 0;
+#X connect 4 4 19 0;
+#X connect 4 4 22 0;
+#X connect 6 0 38 0;
#X connect 6 1 5 0;
-#X connect 7 0 42 0;
+#X connect 7 0 37 0;
#X connect 8 0 9 0;
-#X connect 10 0 0 0;
-#X connect 12 0 14 0;
-#X connect 12 0 15 0;
-#X connect 13 0 12 0;
-#X connect 14 0 6 0;
-#X connect 15 0 6 0;
-#X connect 16 0 12 0;
+#X connect 11 0 49 0;
+#X connect 12 0 0 0;
+#X connect 13 0 37 0;
+#X connect 14 0 40 0;
#X connect 17 0 0 0;
-#X connect 18 0 42 0;
-#X connect 19 0 45 0;
-#X connect 22 0 0 0;
-#X connect 23 0 30 2;
-#X connect 24 0 23 0;
-#X connect 25 0 30 1;
-#X connect 26 0 29 0;
-#X connect 27 0 25 0;
-#X connect 28 0 26 0;
-#X connect 29 0 30 0;
-#X connect 30 0 22 0;
-#X connect 31 0 37 0;
-#X connect 32 0 34 0;
-#X connect 32 0 35 0;
-#X connect 32 0 37 1;
-#X connect 33 0 38 1;
-#X connect 34 0 33 1;
-#X connect 35 0 38 0;
-#X connect 35 1 33 0;
-#X connect 36 0 37 1;
-#X connect 37 0 32 0;
-#X connect 38 0 40 0;
-#X connect 39 0 26 0;
-#X connect 39 1 25 0;
-#X connect 39 2 23 0;
-#X connect 40 0 0 0;
-#X connect 41 0 19 0;
-#X connect 43 0 21 0;
-#X connect 43 1 20 0;
-#X connect 43 2 11 0;
-#X connect 45 0 6 0;
-#X connect 46 0 39 0;
-#X connect 47 0 31 0;
-#X connect 48 0 6 0;
+#X connect 18 0 25 2;
+#X connect 19 0 18 0;
+#X connect 20 0 25 1;
+#X connect 21 0 24 0;
+#X connect 22 0 20 0;
+#X connect 23 0 21 0;
+#X connect 24 0 25 0;
+#X connect 25 0 17 0;
+#X connect 26 0 32 0;
+#X connect 27 0 29 0;
+#X connect 27 0 30 0;
+#X connect 27 0 32 1;
+#X connect 28 0 33 1;
+#X connect 29 0 28 1;
+#X connect 30 0 33 0;
+#X connect 30 1 28 0;
+#X connect 31 0 32 1;
+#X connect 32 0 27 0;
+#X connect 33 0 35 0;
+#X connect 34 0 21 0;
+#X connect 34 1 20 0;
+#X connect 34 2 18 0;
+#X connect 35 0 0 0;
+#X connect 36 0 14 0;
+#X connect 38 1 15 0;
+#X connect 38 2 10 0;
+#X connect 39 0 6 0;
+#X connect 40 0 6 0;
+#X connect 41 0 6 0;
+#X connect 49 0 50 0;
+#X connect 50 0 6 0;
+#X connect 51 0 34 0;
+#X connect 52 0 26 0;
diff --git a/msd2D/main.cpp b/msd2D/main.cpp
index 4313bba..0c5f3fb 100755
--- a/msd2D/main.cpp
+++ b/msd2D/main.cpp
@@ -103,6 +103,7 @@ public:
nb_mass = 0;
id_mass = 0;
id_link = 0;
+ mouse_grab=0;
// --- define inlets and outlets ---
AddInAnything("bang, reset, etc."); // default inlet
@@ -444,6 +445,51 @@ protected:
Ymin = GetFloat(argv[0]);
}
+ void m_grab_mass(int argc,t_atom *argv)
+ {
+ // grab nearest mass X Y
+ t_mass **mi;
+ t_float aux, distance;
+ t_int i;
+
+ // if click
+ if (GetInt(argv[2])==1 && nb_mass>0) {
+
+ if (argc != 3)
+ error("grabMass : X Y click");
+ // first time we grab this mass?Find nearest mass
+ if (mouse_grab == 0) {
+ aux = pow(mass[0]->posX-GetFloat(argv[0]),2) + pow(mass[0]->posY-GetFloat(argv[1]),2);
+ nearest_mass = 0;
+ for (i=1, mi=(mass+1); i<nb_mass; mi++, i++) {
+ distance = pow((*mi)->posX-GetFloat(argv[0]),2) + pow((*mi)->posY-GetFloat(argv[1]),2);
+ if (distance<aux) {
+ aux = distance;
+ nearest_mass = i;
+ }
+ }
+ }
+
+ // Set fixed if mobile
+ i = mass[nearest_mass]->mobile;
+ mass[nearest_mass]->mobile = 0;
+
+ // Set XY
+ mass[nearest_mass]->posX = GetFloat(argv[0]);
+ mass[nearest_mass]->posX2 = GetFloat(argv[0]);
+ mass[nearest_mass]->posY = GetFloat(argv[1]);
+ mass[nearest_mass]->posY2 = GetFloat(argv[1]);
+
+ // Set mobile
+ mass[nearest_mass]->mobile = i;
+
+ // Current grabbing on
+ mouse_grab = 1;
+ }
+ else
+ // Grabing off
+ mouse_grab =0;
+ }
// -------------------------------------------------------------- LINKS
// ---------------------------------------------------------------------
@@ -898,7 +944,7 @@ protected:
t_link * link[nb_max_link];
t_mass * mass[nb_max_mass];
t_float Xmin, Xmax, Ymin, Ymax;
- int nb_link, nb_mass, id_mass, id_link;
+ t_int nb_link, nb_mass, id_mass, id_link, mouse_grab, nearest_mass;
// -------------------------------------------------------------- SETUP
// ---------------------------------------------------------------------
@@ -961,6 +1007,7 @@ private:
FLEXT_CADDMETHOD_(c,0,"massesForcesL",m_force_dumpl);
FLEXT_CADDMETHOD_(c,0,"setMobile",m_set_mobile);
FLEXT_CADDMETHOD_(c,0,"setFixed",m_set_fixe);
+ FLEXT_CADDMETHOD_(c,0,"grabMass",m_grab_mass);
}
// for every registered method a callback has to be declared
@@ -988,6 +1035,7 @@ private:
FLEXT_CALLBACK_V(m_get)
FLEXT_CALLBACK_V(m_delete_link)
FLEXT_CALLBACK_V(m_delete_mass)
+ FLEXT_CALLBACK_V(m_grab_mass)
};
const t_symbol *msd2D::S_Reset = MakeSymbol("Reset");