1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
|
#include "m_pd.h"
#include "math.h"
#define max(a,b) ( ((a) > (b)) ? (a) : (b) )
#define min(a,b) ( ((a) < (b)) ? (a) : (b) )
static t_class *mass2D_class;
typedef struct _mass2D {
t_object x_obj;
t_float posX_old_1, posX_old_2, posY_old_1, posY_old_2, Xinit, Yinit;
t_float forceX, forceY, VX, VY, dX, dY, onoff;
t_float mass2D, seuil, damp;
t_float minX, maxX, minY, maxY;
t_atom pos_new[2], vitesse[3], force[3];
t_outlet *position2D_new, *vitesse_out, *force_out;
t_symbol *x_sym; // receive
unsigned int x_state; // random
t_float x_f; // random
} t_mass2D;
static int makeseed2D(void)
{
static unsigned int random_nextseed = 1489853723;
random_nextseed = random_nextseed * 435898247 + 938284287;
return (random_nextseed & 0x7fffffff);
}
static float random_bang2D(t_mass2D *x)
{
int nval;
int range = 2000000;
float rnd;
unsigned int randval = x->x_state;
x->x_state = randval = randval * 472940017 + 832416023;
nval = ((double)range) * ((double)randval)
* (1./4294967296.);
if (nval >= range) nval = range-1;
rnd=nval;
rnd-=1000000;
rnd=rnd/1000000.; //pour mettre entre -1 et 1;
return (rnd);
}
void mass2D_seuil(t_mass2D *x, t_floatarg f1)
{
x->seuil = f1;
}
void mass2D_on(t_mass2D *x)
{
x->onoff = 1;
}
void mass2D_off(t_mass2D *x)
{
x->onoff = 0;
}
void mass2D_minX(t_mass2D *x, t_floatarg f1)
{
x->minX = f1;
}
void mass2D_maxX(t_mass2D *x, t_floatarg f1)
{
x->maxX = f1;
}
void mass2D_minY(t_mass2D *x, t_floatarg f1)
{
x->minY = f1;
}
void mass2D_maxY(t_mass2D *x, t_floatarg f1)
{
x->maxY = f1;
}
void mass2D_force(t_mass2D *x, t_floatarg f1, t_floatarg f2)
{
x->forceX = x->forceX+f1;
x->forceY = x->forceY+f2;
}
void mass2D_displace(t_mass2D *x, t_floatarg f1, t_floatarg f2)
{
x->dX += f1;
x->dY += f2;
}
void mass2D_damp(t_mass2D *x, t_floatarg f1)
{
x->damp = f1;
}
void mass2D_dX(t_mass2D *x, t_floatarg f1)
{
x->dX += f1;
}
void mass2D_dY(t_mass2D *x, t_floatarg f1)
{
x->dY += f1;
}
void mass2D_bang(t_mass2D *x)
{
t_float posX_new, posY_new, vX=1, vY=1;
if (x->onoff != 0)
{
if (x->seuil > 0)
{
if (x->posY_old_1 == x->minY) // si on est en dehors de la structure -> frottement sec sur les bords
{
if (fabs(x->forceX)<=(x->seuil * -(x->forceY)))
vX = 0; // on est a l'interieur du cone de frotement,
}
if (x->posY_old_1 == x->maxY) // si on est en dehors de la structure -> frottement sec sur les bords
{
if (fabs(x->forceX)<=(x->seuil * (x->forceY)))
vX = 0; // on est a l'interieur du cone de frotement,
}
if (x->posX_old_1 == x->minX) // si on est en dehors de la structure -> frottement sec sur les bords
{
if (fabs(x->forceX)<=(x->seuil * -(x->forceY)))
vY = 0; // on est a l'interieur du cone de frotement,
}
if (x->posX_old_1 == x->maxX) // si on est en dehors de la structure -> frottement sec sur les bords
{
if (fabs(x->forceX)<=(x->seuil * (x->forceY)))
vY = 0; // on est a l'interieur du cone de frotement,
}
}
x->forceX += x->damp * ((x->posX_old_2)-(x->posX_old_1));
x->forceY += x->damp * ((x->posY_old_2)-(x->posY_old_1)); // damping
if (x->mass2D != 0)
{
posX_new = x->forceX/x->mass2D + 2*x->posX_old_1 - x->posX_old_2;
posY_new = x->forceY/x->mass2D + 2*x->posY_old_1 - x->posY_old_2;
}
else
{
posX_new = x->posX_old_1;
posY_new = x->posY_old_1;
}
if (vX==0)
posX_new = x->posX_old_1; // on n'a pas de mv qd on est a l'interieur du cone de frotement
if (vY==0)
posY_new = x->posY_old_1;
posX_new = max(min(posX_new, x->maxX), x->minX);
posY_new = max(min(posY_new, x->maxY), x->minY);
posX_new += x->dX;
posY_new += x->dY;
x->posX_old_1 += x->dX; // pour eviter l'inertie
x->posY_old_1 += x->dY;
SETFLOAT(&(x->pos_new[0]), posX_new );
SETFLOAT(&(x->pos_new[1]), posY_new );
x->posX_old_2 = x->posX_old_1;
x->posX_old_1 = posX_new;
x->posY_old_2 = x->posY_old_1;
x->posY_old_1 = posY_new;
SETFLOAT(&(x->force[0]), x->forceX );
SETFLOAT(&(x->force[1]), x->forceY );
SETFLOAT(&(x->force[2]), sqrt( (x->forceX * x->forceX) + (x->forceY * x->forceY) ));
// x->forceX=0;
// x->forceY=0;
x->forceX = random_bang2D(x)*1e-25;
x->forceY = random_bang2D(x)*1e-25; // avoiding denormal problem by adding low amplitude noise
x->dX=0;
x->dY=0;
x->VX = x->posX_old_1 - x->posX_old_2;
x->VY = x->posY_old_1 - x->posY_old_2;
SETFLOAT(&(x->vitesse[0]), x->VX );
SETFLOAT(&(x->vitesse[1]), x->VY );
SETFLOAT(&(x->vitesse[2]), sqrt( (x->VX * x->VX) + (x->VY * x->VY) ));
outlet_anything(x->vitesse_out, gensym("velocity2D"), 3, x->vitesse);
outlet_anything(x->force_out, gensym("force2D"), 3, x->force);
outlet_anything(x->position2D_new, gensym("position2D"), 2, x->pos_new);
}
}
void mass2D_reset(t_mass2D *x)
{
x->posX_old_2 = x->Xinit;
x->posX_old_1 = x->Xinit;
x->forceX=0;
x->posY_old_2 = x->Yinit;
x->posY_old_1 = x->Yinit;
x->forceY=0;
x->VX = 0;
x->VY = 0;
x->dX=0;
x->dY=0;
x->seuil=0;
x->onoff = 1;
SETFLOAT(&(x->pos_new[0]), x->Xinit );
SETFLOAT(&(x->pos_new[1]), x->Yinit );
SETFLOAT(&(x->force[0]), 0 );
SETFLOAT(&(x->force[1]), 0 );
SETFLOAT(&(x->force[2]), 0 );
SETFLOAT(&(x->vitesse[0]), 0 );
SETFLOAT(&(x->vitesse[1]), 0 );
SETFLOAT(&(x->vitesse[2]), 0 );
outlet_anything(x->vitesse_out, gensym("velocity2D"), 3, x->vitesse);
outlet_anything(x->force_out, gensym("force2D"), 3, x->force);
outlet_anything(x->position2D_new, gensym("position2D"), 2, x->pos_new);
}
void mass2D_resetf(t_mass2D *x)
{
x->dX=0;
x->dY=0;
x->forceX=0;
x->forceY=0;
}
void mass2D_setXY(t_mass2D *x, t_float posX, t_float posY)
{
x->posX_old_2 = posX;
x->posX_old_1 = posX;
x->forceX=0;
x->posY_old_2 = posY;
x->posY_old_1 = posY;
x->forceY=0;
SETFLOAT(&(x->pos_new[0]), posX );
SETFLOAT(&(x->pos_new[1]), posY );
outlet_anything(x->position2D_new, gensym("position2D"), 2, x->pos_new);
}
void mass2D_setX(t_mass2D *x, t_float posX)
{
x->posX_old_2 = posX;
x->posX_old_1 = posX;
x->forceX=0;
SETFLOAT(&(x->pos_new[0]), posX );
outlet_anything(x->position2D_new, gensym("position2D"), 2, x->pos_new);
}
void mass2D_setY(t_mass2D *x, t_float posY)
{
x->posY_old_2 = posY;
x->posY_old_1 = posY;
x->forceY=0;
SETFLOAT(&(x->pos_new[1]), posY );
outlet_anything(x->position2D_new, gensym("position2D"), 2, x->pos_new);
}
void mass2D_loadbang(t_mass2D *x)
{
outlet_anything(x->position2D_new, gensym("position2D"), 2, x->pos_new);
}
void mass2D_set_mass2D(t_mass2D *x, t_float mass)
{
x->mass2D=mass;
}
void mass2D_inter_ambient(t_mass2D *x, t_symbol *s, int argc, t_atom *argv)
{
if (argc == 12)
// 0 : FX
// 1 : FY
// 2 : RndX
// 3 : RndY
// 4 : D2
// 5 : rien
// 6 : Xmin
// 7 : Xmax
// 8 : Ymin
// 9 : Ymax
// 10 : dX
// 11 : dY
{
if (x->posX_old_1 > atom_getfloatarg(6, argc, argv))
{
if (x->posX_old_1 < atom_getfloatarg(7, argc, argv))
{
if (x->posY_old_1 > atom_getfloatarg(8, argc, argv))
{
if (x->posY_old_1 < atom_getfloatarg(9, argc, argv))
{
x->forceX += atom_getfloatarg(0, argc, argv);
x->forceY += atom_getfloatarg(1, argc, argv); // constant
x->forceX += random_bang2D(x)*atom_getfloatarg(2, argc, argv);
x->forceY += random_bang2D(x)*atom_getfloatarg(3, argc, argv); // random
x->forceX += atom_getfloatarg(4, argc, argv) * ((x->posX_old_2)-(x->posX_old_1));
x->forceY += atom_getfloatarg(4, argc, argv) * ((x->posY_old_2)-(x->posY_old_1)); // damping
x->dX += atom_getfloatarg(10, argc, argv);
x->dY += atom_getfloatarg(11, argc, argv); // constant
}
}
}
}
}
else
{
error("bad ambient interraction message");
}
}
void mass2D_inter_seg(t_mass2D *x, t_symbol *s, int argc, t_atom *argv)
{
t_float a1, b1, c1, a2, b2, c2, a3, b3, c3, tmp;
t_float posx1, posx2, posy1, posy2;
t_float profondeur;
if (argc == 12)
// 0 : posx1
// 1 : posy1
// 2 : posx2
// 3 : posy2
// 4 : profondeur max
// 5 : F CT Normal
// 6 : F CT Tengentiel
// 7 : K normal
// 8 : Damp2 normal
// 9 : Damp2 tan
// 10 : displacement Normal
// 11 : d Tan
{
posx1 = atom_getfloatarg(0, argc, argv);
posy1 = atom_getfloatarg(1, argc, argv);
posx2 = atom_getfloatarg(2, argc, argv);
posy2 = atom_getfloatarg(3, argc, argv);
b1 = posx2 - posx1;
a1 = -posy2 + posy1;
if (!((a1==0) & (b1==0)))
{
tmp = sqrt((a1*a1)+(b1*b1)); // = longueur du vecteur pour renormalisation
if (tmp !=0)
{
a1 = a1/tmp;
b1 = b1/tmp;
}
else
{
a1 = 0;
b1 = 0;
}
c1 = a1*posx1+b1*posy1;
profondeur = ( (a1 * x->posX_old_1) + (b1 * x->posY_old_1) ) - c1;
if ( ( profondeur < 0) & (profondeur > - atom_getfloatarg(4, argc, argv)) )
{
a2 = b1;
b2 = -a1;
c2 = a2*posx1+b2*posy1;
if (( (a2 * x->posX_old_1) + (b2 * x->posY_old_1) ) > c2)
{
a3 = a2;
b3 = b2;
c3 = a3*posx2+b3*posy2;
if (( (a3 * x->posX_old_1) + (b3 * x->posY_old_1) ) < c3)
{
tmp = atom_getfloatarg(5, argc, argv); // force ct normal
x->forceX += tmp * a1;
x->forceY += tmp * b1;
tmp = atom_getfloatarg(6, argc, argv); // force ct normal
x->forceX -= tmp * b1;
x->forceY -= tmp * -a1;
tmp = atom_getfloatarg(7, argc, argv); // force K normal
tmp *= profondeur;
x->forceX -= tmp * a1;
x->forceY -= tmp * b1;
tmp = atom_getfloatarg(8, argc, argv); // damping2 normal
tmp *= ( x->VX * a1 + x->VY * b1 );
x->forceX -= tmp * a1 ;
x->forceY -= tmp * b1 ;
tmp = atom_getfloatarg(9, argc, argv); // damping2 tangentiel
tmp *= ( x->VX * b1 - x->VY * a1 );
x->forceX -= tmp * b1 ;
x->forceY -= tmp * -a1 ;
tmp = atom_getfloatarg(10, argc, argv); // displacement normal
x->dX += tmp * a1 ;
x->dY += tmp * b1 ;
tmp = atom_getfloatarg(11, argc, argv); // displacement tengentiel
x->dX -= tmp * b1 ;
x->dY -= tmp * -a1 ;
}
}
}
}
}
else
{
error("bad interact_2D_segment message");
}
}
void mass2D_inter_line(t_mass2D *x, t_symbol *s, int argc, t_atom *argv)
{
t_float a1, b1, c1, tmp;
t_float posx1, posx2, posy1, posy2;
t_float profondeur;
if (argc == 12)
// 0 : posx1
// 1 : posy1
// 2 : posx2
// 3 : posy2
// 4 : profondeur max
// 5 : F CT Normal
// 6 : F CT Tengentiel
// 7 : K normal
// 8 : Damp2 normal
// 9 : Damp2 tan
// 10 : d normal
// 11 : d tengential
{
posx1 = atom_getfloatarg(0, argc, argv);
posy1 = atom_getfloatarg(1, argc, argv);
posx2 = atom_getfloatarg(2, argc, argv);
posy2 = atom_getfloatarg(3, argc, argv);
b1 = posx2 - posx1;
a1 = -posy2 + posy1;
if (!((a1==0) & (b1==0)))
{
tmp = sqrt((a1*a1)+(b1*b1)); // = longueur du vecteur pour renormalisation
a1 = a1/tmp; // composante X de la normal
b1 = b1/tmp; // composante Y de la normal
c1 = a1*posx1+b1*posy1; //
profondeur = ( (a1 * x->posX_old_1) + (b1 * x->posY_old_1) ) - c1;
if ( ( profondeur < 0) & (profondeur > - atom_getfloatarg(4, argc, argv)) )
{
tmp = atom_getfloatarg(5, argc, argv); // force ct normal
x->forceX += tmp * a1;
x->forceY += tmp * b1;
tmp = atom_getfloatarg(6, argc, argv); // force ct tengentiel
x->forceX -= tmp * b1;
x->forceY -= tmp * -a1;
tmp = atom_getfloatarg(7, argc, argv); // force K normal
tmp *= profondeur ;
x->forceX -= tmp * a1;
x->forceY -= tmp * b1;
tmp = atom_getfloatarg(8, argc, argv); // damping2 normal
tmp *= ( x->VX * a1 + x->VY * b1 ) ;
x->forceX -= tmp * a1 ;
x->forceY -= tmp * b1 ;
tmp = atom_getfloatarg(9, argc, argv); // damping2 tangentiel
tmp *= ( x->VX * b1 - x->VY * a1 );
x->forceX -= tmp * b1 ;
x->forceY -= tmp * -a1 ;
tmp = atom_getfloatarg(10, argc, argv); // d normal
x->dX += tmp * a1;
x->dY += tmp * b1;
tmp = atom_getfloatarg(11, argc, argv); // d tangentiel
x->dX -= tmp * b1;
x->dY -= tmp * -a1;
}
}
}
else
{
error("bad interact_2D_line message");
}
}
void mass2D_inter_circle(t_mass2D *x, t_symbol *s, int argc, t_atom *argv)
{
t_float posx1, posy1, Nx, Ny, distance, Dmax, tmp;
t_float deltaX_old, deltaY_old, distance_old ;
t_float fnx=0;
t_float ftx=0;
if (argc == 20)
// 0 : Xcentre
// 1 : Ycendre
// 2 : Rmin
// 3 : Rmax
// 4 : F normal
// 5 : F tangentiel
// 6 : K normal
// 7 : K tengentiel
// 8 : F normal proportionel a 1/R
// 9 : F tengentiel proportionel a 1/R
// 10 : Damp2 normal
// 11 : Damp2 tan
// 12 : deplacement N proportionel a 1/R
// 13 : deplacement tengentiel proportionel a 1/R
// 14 : position ancienne de l'interacteur en X
// 15 : position abcienne de l'interacteur en Y
// 16 : damping de liaison
// 17 : F normal proportionel a 1/R*R
// 18 : normal displacement
// 19 : tengential displacement
{
posx1 = atom_getfloatarg(0, argc, argv);
posy1 = atom_getfloatarg(1, argc, argv);
Nx = (x->posX_old_1)-posx1; // vecteur deplacement X
Ny = (x->posY_old_1)-posy1; // vecteur deplacement Y
distance = sqrt((Nx * Nx)+(Ny * Ny)); // distance entre le centre de l'interaction, et le pts
Dmax= atom_getfloatarg(3, argc, argv); // distance max de l'interaction
if ( (distance > atom_getfloatarg(2, argc, argv)) & (distance < Dmax) )
{
Nx = Nx/distance; // composante X de la normal (normalisé)
Ny = Ny/distance; // composante Y de la normal.
tmp = atom_getfloatarg(4, argc, argv); // force constante normal
// x->forceX += tmp * Nx;
// x->forceY += tmp * Ny;
fnx +=tmp;
// fny +=tmp;
tmp = atom_getfloatarg(5, argc, argv); // force constante tengentiel
// x->forceX += tmp * Ny;
// x->forceY += tmp * -Nx;
ftx +=tmp;
// fty +=tmp;
tmp = atom_getfloatarg(6, argc, argv); // force variable (K) normal
tmp *= ( Dmax-distance );
// x->forceX += tmp * Nx ;
// x->forceY += tmp * Ny ;
fnx +=tmp;
// fny +=tmp;
tmp = atom_getfloatarg(7, argc, argv); // force variable (K) tengentiel
tmp *= ( Dmax-distance );
// x->forceX += tmp * Ny ;
// x->forceY += tmp * -Nx ;
ftx +=tmp;
// fty +=tmp;
tmp = atom_getfloatarg(8, argc, argv); // force normal proportionel a 1/r
if (distance != 0)
{
tmp /= distance;
// x->forceX += tmp * Nx ;
// x->forceY += tmp * Ny ;
fnx +=tmp;
// fny +=tmp;
}
tmp = atom_getfloatarg(9, argc, argv); // force tengentiel proportionel a 1/r
if (distance != 0)
{
tmp /= distance;
// x->forceX -= tmp * Ny ;
// x->forceY -= tmp * -Nx ;
ftx -=tmp;
// fty -=tmp;
}
tmp = atom_getfloatarg(10, argc, argv); // damping2 normal
tmp *= ( x->VX * Nx + x->VY * Ny );
// x->forceX -= tmp * Nx ;
// x->forceY -= tmp * Ny ;
fnx -=tmp;
// fny -=tmp;
tmp = atom_getfloatarg(11, argc, argv); // damping2 tangentiel
tmp *= ( x->VX * Ny - x->VY * Nx );
// x->forceX -= tmp * Ny ;
// x->forceY -= tmp * -Ny ;
ftx -=tmp;
// fty -=tmp;
tmp = atom_getfloatarg(12, argc, argv); // d normal
if (distance != 0)
{
tmp /= distance;
x->dX += tmp * Nx ;
x->dY += tmp * Ny ;
}
tmp = atom_getfloatarg(13, argc, argv); // d tangentiel
if (distance != 0)
{
tmp /= distance;
x->dX -= tmp * Ny ;
x->dY -= tmp * -Nx ;
}
tmp = atom_getfloatarg(16, argc, argv); // damping de liaison
if (tmp!= 0)
{
deltaX_old = atom_getfloatarg(14, argc, argv) - x->posX_old_2;
deltaY_old = atom_getfloatarg(15, argc, argv) - x->posY_old_2;
distance_old = sqrt( (deltaX_old * deltaX_old) + (deltaY_old * deltaY_old));
// x->forceX -= Nx * tmp * (distance - distance_old);
// x->forceY -= Ny * tmp * (distance - distance_old);
tmp *= (distance - distance_old);
fnx -=tmp;
// fny -=tmp;
}
tmp = atom_getfloatarg(17, argc, argv); // force normal proportionel a 1/r2
if (distance != 0)
{
tmp /= (distance*distance);
// x->forceX -= tmp * Nx;
// x->forceY -= tmp * Ny;
fnx +=tmp;
// fny +=tmp;
}
tmp = atom_getfloatarg(18, argc, argv); // deplacement constante normal
x->dX += tmp * Nx;
x->dY += tmp * Ny;
tmp = atom_getfloatarg(19, argc, argv); // deplacement constante tengentiel
x->dX -= tmp * Ny;
x->dY -= tmp * -Nx;
x->forceX += fnx * Nx + ftx * Ny; // optimisation, but does not change anything...
x->forceY += fnx * Ny - ftx * Nx;
}
}
else
{
error("bad interact_2D_circle message");
}
}
void *mass2D_new(t_symbol *s, int argc, t_atom *argv)
{
t_mass2D *x = (t_mass2D *)pd_new(mass2D_class);
x->x_sym = atom_getsymbolarg(0, argc, argv);
x->x_state = makeseed2D();
pd_bind(&x->x_obj.ob_pd, atom_getsymbolarg(0, argc, argv));
x->position2D_new=outlet_new(&x->x_obj, 0);
x->force_out=outlet_new(&x->x_obj, 0);
x->vitesse_out=outlet_new(&x->x_obj, 0);
x->forceX=0;
x->forceY=0;
if (argc >= 2)
x->mass2D = atom_getfloatarg(1, argc, argv) ;
else
x->mass2D = 1;
x->onoff = 1;
x->VX = 0;
x->VY = 0;
x->dX=0;
x->dY=0;
if (argc >= 3)
x->Xinit = atom_getfloatarg(2, argc, argv);
else
x->Xinit = 0 ;
x->posX_old_1 = x->Xinit ;
x->posX_old_2 = x->Xinit;
SETFLOAT(&(x->pos_new[0]), x->Xinit);
if (argc >= 4)
x->Yinit = atom_getfloatarg(3, argc, argv);
else
x->Yinit = 0 ;
x->posY_old_1 = x->Yinit ;
x->posY_old_2 = x->Yinit;
SETFLOAT(&(x->pos_new[1]), x->Yinit);
if (argc >= 5)
x->minX = atom_getfloatarg(4, argc, argv) ;
else
x->minX = -100000;
if (argc >= 6)
x->maxX = atom_getfloatarg(5, argc, argv) ;
else
x->maxX = 100000;
if (argc >= 7)
x->minY = atom_getfloatarg(6, argc, argv) ;
else
x->minY = -100000;
if (argc >= 8)
x->maxY = atom_getfloatarg(7, argc, argv) ;
else
x->maxY = 100000;
if (argc >= 9)
x->seuil = atom_getfloatarg(8, argc, argv) ;
else
x->seuil = 0;
if (argc >= 10)
x->damp = atom_getfloatarg(9, argc, argv) ;
else
x->damp = 0;
return (x);
}
static void mass2D_free(t_mass2D *x)
{
pd_unbind(&x->x_obj.ob_pd, x->x_sym);
}
void mass2D_setup(void)
{
mass2D_class = class_new(gensym("mass2D"),
(t_newmethod)mass2D_new,
(t_method)mass2D_free, sizeof(t_mass2D),
CLASS_DEFAULT, A_GIMME, 0);
class_addcreator((t_newmethod)mass2D_new, gensym("masse2D"), A_GIMME, 0);
class_addbang(mass2D_class, mass2D_bang);
class_addmethod(mass2D_class, (t_method)mass2D_force, gensym("force2D"),A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_displace, gensym("dXY"),A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_dX, gensym("dX"),A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_dY, gensym("dY"),A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_inter_ambient, gensym("interactor_ambient_2D"), A_GIMME, 0);
class_addmethod(mass2D_class, (t_method)mass2D_inter_line, gensym("interactor_line_2D"), A_GIMME, 0);
class_addmethod(mass2D_class, (t_method)mass2D_inter_seg, gensym("interactor_segment_2D"), A_GIMME, 0);
class_addmethod(mass2D_class, (t_method)mass2D_inter_circle, gensym("interactor_circle_2D"), A_GIMME, 0);
class_addmethod(mass2D_class, (t_method)mass2D_seuil, gensym("setT"), A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_set_mass2D, gensym("setM"), A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_setX, gensym("setX"), A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_setY, gensym("setY"), A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_minX, gensym("setXmin"), A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_minY, gensym("setYmin"), A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_maxX, gensym("setXmax"), A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_maxY, gensym("setYmax"), A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_setXY, gensym("setXY"), A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_damp, gensym("setD"), A_DEFFLOAT, 0);
class_addmethod(mass2D_class, (t_method)mass2D_on, gensym("on"), 0);
class_addmethod(mass2D_class, (t_method)mass2D_off, gensym("off"), 0);
class_addmethod(mass2D_class, (t_method)mass2D_reset, gensym("reset"), 0);
class_addmethod(mass2D_class, (t_method)mass2D_resetf, gensym("resetF"), 0);
class_addmethod(mass2D_class, (t_method)mass2D_loadbang, gensym("loadbang"), 0);
}
|