-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtCircle2D.c
142 lines (109 loc) · 3.64 KB
/
tCircle2D.c
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
// --------------------------------------------------------------------------
// This file is part of the pmpd software.
//
// pmpd software is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// pmpd firmware is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with pmpd software. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------------
//
// pmpd = physical modeling for pure data
#include "m_pd.h"
#include <math.h>
#include "pmpd_export.h"
#include "pmpd_version.h"
static t_class *tCircle2D_class;
typedef struct _tCircle2D {
t_object x_obj;
t_float X, Y, Rmin, Rmax, distance_old;
t_outlet *force_new, *distance, *vitesse; // outlet
} t_tCircle2D;
void tCircle2D_position2D(t_tCircle2D *x, t_float X, t_float Y)
{
t_float tmp, vitesse;
tmp = sqrt((X-x->X)*(X-x->X) + (Y-x->Y)*(Y-x->Y));
vitesse = tmp - x->distance_old ;
x->distance_old = tmp;
outlet_float(x->vitesse, vitesse);
outlet_float(x->distance, tmp);
if ( (tmp < x->Rmax) & (tmp >= x->Rmin))
{
outlet_float(x->force_new, 1);
}
else
{
outlet_float(x->force_new, 0);
}
}
void tCircle2D_XY(t_tCircle2D *x, t_float X, t_float Y)
{
x->X= X;
x->Y= Y;
}
void tCircle2D_X(t_tCircle2D *x, t_float X)
{
x->X= X;
}
void tCircle2D_Y(t_tCircle2D *x, t_float X)
{
x->Y= X;
}
void tCircle2D_Rmin(t_tCircle2D *x, t_float X)
{
x->Rmin= X;
}
void tCircle2D_Rmax(t_tCircle2D *x, t_float X)
{
x->Rmax= X;
}
void *tCircle2D_new(t_symbol *s, int argc, t_atom *argv)
{
t_tCircle2D *x = (t_tCircle2D *)pd_new(tCircle2D_class);
x->force_new=outlet_new(&x->x_obj, 0);
x->distance=outlet_new(&x->x_obj, 0);
x->vitesse=outlet_new(&x->x_obj, 0);
x->distance_old = 0;
if (argc>=4)
x->Rmax = atom_getfloatarg(3, argc, argv);
else
x->Rmax = 1;
if (argc>=3)
x->Rmin = atom_getfloatarg(2, argc, argv);
else
x->Rmin = 0;
if (argc>=2)
x->Y = atom_getfloatarg(1, argc, argv);
else
x->Y = 0;
if (argc>=1)
x->X = atom_getfloatarg(0, argc, argv);
else
x->X = 0;
return (x);
}
PMPD_EXPORT void tCircle2D_setup(void)
{
tCircle2D_class = class_new(gensym("tCircle2D"),
(t_newmethod)tCircle2D_new,
0, sizeof(t_tCircle2D),
CLASS_DEFAULT, A_GIMME, 0);
if(!tCircle2D_class)
return;
//verbose(4, "tCircle2D version %s (%s)", pmpd_tag(), pmpd_sha());
class_addcreator((t_newmethod)tCircle2D_new, gensym("pmpd.tCircle2D"), A_GIMME, 0);
class_addmethod(tCircle2D_class, (t_method)tCircle2D_position2D, gensym("position2D"), A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(tCircle2D_class, (t_method)tCircle2D_XY, gensym("setXY"), A_DEFFLOAT, A_DEFFLOAT, 0);
class_addmethod(tCircle2D_class, (t_method)tCircle2D_X, gensym("setX"), A_DEFFLOAT, 0);
class_addmethod(tCircle2D_class, (t_method)tCircle2D_Y, gensym("setY"), A_DEFFLOAT, 0);
class_addmethod(tCircle2D_class, (t_method)tCircle2D_Rmin, gensym("setRmin"), A_DEFFLOAT, 0);
class_addmethod(tCircle2D_class, (t_method)tCircle2D_Rmax, gensym("setRmax"), A_DEFFLOAT, 0);
}