Holy Moly!
I got it to work! Well, Thomas Grill (also Chad Wood and Olaf Matthes helped) got it to work and I watched. Hopefully now I understand how this PD software thinks a bit and can write more externals sans help in the future.
The sphere~ works like this
Thanks again for all the help!
specail thanks to Thomas Grill
This may not be up for long. Im sorry. I know you will all be clamoring all over yourselves to snatch this little baby up but I have to keep a clean server...
A windows dll is available at the bottom of this page.
0 #include "m_pd.h"
1
2 /*-------------------------------------------------------*/
3 /*sphere~ */
4 /* A tool to control volumes based off of 3 dimentions */
5 /* using linier decay. Inlets are (from left to right): */
6 /* the center of the sphere x, y, z, the radius of the */
7 /* sphere and the location of the control point x, y, z. */
8 /* The outlet is a float from 0 to 1. The outlet returns */
9 /* 0 if the control point is outside the sphere and the */
10 /* output is linier from 0 to 1, from the edge to the */
11 /* center of the sphere if the control point lies within */
12 /* the sphere */
13 /* */
14 /* Major help recieved from: */
15 /* Thomas Grill, Chad Wood and Olaf Matthes */
16 /* Thanks for the Help! */
17 /*-------------------------------------------------------*/
18
19 static t_class *sphere_tilde_class;
20
21 typedef struct _sphere_tilde {
22 t_object x_obj;
23 t_sample dummy;
24 } t_sphere_tilde;
25
26 void *sphere_tilde_new(t_floatarg f)
27 {
28 t_symbol *p_signal = gensym("signal");
29
30 t_sphere_tilde *ref = (t_sphere_tilde *)pd_new(sphere_tilde_class);
31 ref->dummy=f;
32 inlet_new(&ref->x_obj, &ref->x_obj.ob_pd, p_signal, p_signal);
33 inlet_new(&ref->x_obj, &ref->x_obj.ob_pd, p_signal, p_signal);
34 inlet_new(&ref->x_obj, &ref->x_obj.ob_pd, p_signal, p_signal);
35 inlet_new(&ref->x_obj, &ref->x_obj.ob_pd, p_signal, p_signal);
36 inlet_new(&ref->x_obj, &ref->x_obj.ob_pd, p_signal, p_signal);
37 inlet_new(&ref->x_obj, &ref->x_obj.ob_pd, p_signal, p_signal);
38 outlet_new(&ref->x_obj, p_signal);
39 return (void *)ref;
40 }
41
42 t_int *sphere_tilde_perform(t_int *w)
43 {
44 t_sphere_tilde *ref = (t_sphere_tilde *)(w[1]);//data structure
45 t_sample *in1 = (t_sample *)(w[2]); //centerx
46 t_sample *in2 = (t_sample *)(w[3]); //centery
47 t_sample *in3 = (t_sample *)(w[4]); //centerz
48 t_sample *in4 = (t_sample *)(w[5]); //radius
49 t_sample *in5 = (t_sample *)(w[6]); //controlx
50 t_sample *in6 = (t_sample *)(w[7]); //controly
51 t_sample *in7 = (t_sample *)(w[8]); //controlz
52 t_sample *out = (t_sample *)(w[9]); //outlet
53 int n = (int)(w[10]); //number of samples in block
54
55 while (n--) {
56 t_sample cent_x=*in1++;
57 t_sample cent_y=*in2++;
58 t_sample cent_z=*in3++;
59 t_sample rad=*in4++;
60 t_sample cont_x=*in5++;
61 t_sample cont_y=*in6++;
62 t_sample cont_z=*in7++;
63 t_sample vol;
64 if ((rad>0.001) || (rad<-0.001)) {
65 vol=1-((((cont_x-cent_x)*(cont_x-cent_x))+((cont_y-cent_y)*(cont_y-cent_y))+((cont_z-cent_z)*(cont_z-cent_z)))/(rad*rad));
66 if (vol<0) *out++ = 0;
67 else *out++ = vol;
68 } else {
69 vol=1-((((cont_x-cent_x)*(cont_x-cent_x))+((cont_y-cent_y)*(cont_y-cent_y))+((cont_z-cent_z)*(cont_z-cent_z)))/(0.001*0.001));
70 if (vol<0) *out++ = 0;
71 else *out++ = 1;
72 }
73 }
74
75 return (w+11);
76 }
77
78 void sphere_tilde_dsp(t_sphere_tilde *ref, t_signal **sp)
79 {
80 dsp_add(sphere_tilde_perform, 10, ref,
81 sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec, sp[4]->s_vec, sp[5]->s_vec, sp[6]->s_vec, sp[7]->s_vec, sp[0]->s_n);
82 }
83
84
85 void sphere_tilde_setup(void) {
86 sphere_tilde_class = class_new(gensym("sphere~"),
87 (t_newmethod)sphere_tilde_new,
88 0, sizeof(t_sphere_tilde),
89 CLASS_DEFAULT,
90 A_DEFFLOAT, 0);
91
92 class_addmethod(sphere_tilde_class,
93 (t_method)sphere_tilde_dsp, gensym("dsp"), 0);
94 CLASS_MAINSIGNALIN(sphere_tilde_class, t_sphere_tilde, dummy);
95 post("sphere~: written by wade with help from the PD list");
96 }
97
My email is wade@aproximation.org
And the code is here. DLL is here