aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Henry <nusmuk@users.sourceforge.net>2015-10-02 12:46:42 +0000
committerCyrille Henry <nusmuk@users.sourceforge.net>2015-10-02 12:46:42 +0000
commite8c4bf707d8d8c0525b0d32c19fb1f406481b79e (patch)
tree37b764aa8815fb9e1419606f07e0e8a72bdb481b
parent117cfde55cb10f03546cc1088253eaaa8b8f4b8a (diff)
add spherical coordinate set and get messagesHEADsvn2git-headexternals/pmpd
svn path=/trunk/externals/pmpd/; revision=17571
-rw-r--r--pmpd3d.c2
-rw-r--r--pmpd3d_set.c120
-rw-r--r--pmpd3d_tab.c63
-rw-r--r--pmpd3d_various.c2
4 files changed, 186 insertions, 1 deletions
diff --git a/pmpd3d.c b/pmpd3d.c
index 5ff190a..46f2055 100644
--- a/pmpd3d.c
+++ b/pmpd3d.c
@@ -102,6 +102,7 @@ void pmpd3d_setup(void)
class_addmethod(pmpd3d_class, (t_method)pmpd3d_posX, gensym("setPosX"), A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_posY, gensym("setPosY"), A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_posZ, gensym("setPosZ"), A_GIMME, 0);
+ class_addmethod(pmpd3d_class, (t_method)pmpd3d_posSpherical, gensym("setPosSpherical"), A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_overdamp, gensym("setOverdamp"), A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_setEnd1, gensym("setEnd1"), A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_setEnd2, gensym("setEnd2"), A_GIMME, 0);
@@ -189,6 +190,7 @@ void pmpd3d_setup(void)
class_addmethod(pmpd3d_class, (t_method)pmpd3d_massesForcesZT, gensym("massesForcesZT"),A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_massesPosT, gensym("massPosT"), A_GIMME, 0);
+ class_addmethod(pmpd3d_class, (t_method)pmpd3d_massesPosSphericalT, gensym("massPosSphericalT"), A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_massesSpeedsT, gensym("massSpeedT"),A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_massesForcesT, gensym("massForceT"),A_GIMME, 0);
class_addmethod(pmpd3d_class, (t_method)pmpd3d_massesPosXT, gensym("massPosXT"), A_GIMME, 0);
diff --git a/pmpd3d_set.c b/pmpd3d_set.c
index b84010f..35c6ae7 100644
--- a/pmpd3d_set.c
+++ b/pmpd3d_set.c
@@ -1,3 +1,7 @@
+#define sph2carX(r,phy,teta) (r * cos(teta))
+#define sph2carY(r,phy,teta) (r * sin(teta) * cos(phy))
+#define sph2carZ(r,phy,teta) (r * sin(teta) * sin(phy))
+
void pmpd3d_setK(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
{
int tmp, i, offset;
@@ -1106,6 +1110,122 @@ void pmpd3d_pos(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
}
}
+void pmpd3d_posSpherical(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
+{
+// displace a mass to a certain position, using polar coordinat system
+ t_int tmp, i, offset;
+ t_garray *a;
+ int npoints, n;
+ t_word *vec;
+ t_float K;
+ t_float r, phy, teta, X,Y,Z;
+
+ if ( (argc == 4) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) )
+ {
+ tmp = atom_getfloatarg(0, argc, argv);
+ tmp = max(0, min( x->nb_mass-1, tmp));
+ r = atom_getfloatarg(1, argc, argv);
+ teta = atom_getfloatarg(2, argc, argv);
+ phy = atom_getfloatarg(3, argc, argv);
+ x->mass[tmp].posX = sph2carX(r,phy,teta);
+ x->mass[tmp].speedX = 0;
+ x->mass[tmp].forceX = 0;
+ x->mass[tmp].posY = sph2carY(r,phy,teta);
+ x->mass[tmp].speedY = 0;
+ x->mass[tmp].forceY = 0;
+ x->mass[tmp].posZ = sph2carZ(r,phy,teta);
+ x->mass[tmp].speedZ = 0;
+ x->mass[tmp].forceZ = 0;
+ }
+ else if ( (argc == 4) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_FLOAT ) && ( argv[2].a_type == A_FLOAT ) && ( argv[3].a_type == A_FLOAT ) )
+ {
+ for (i=0; i< x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ r = atom_getfloatarg(1, argc, argv);
+ teta = atom_getfloatarg(2, argc, argv);
+ phy = atom_getfloatarg(3, argc, argv);
+ x->mass[i].posX = sph2carX(r,phy,teta);
+ x->mass[i].speedX = 0;
+ x->mass[i].forceX = 0;
+ x->mass[i].posY = sph2carY(r,phy,teta);
+ x->mass[i].speedY = 0;
+ x->mass[i].forceY = 0;
+ x->mass[i].posZ = sph2carX(r,phy,teta);
+ x->mass[i].speedZ = 0;
+ x->mass[i].forceZ = 0;
+ }
+ }
+ }
+ else if ( (argc >= 2) && ( argv[0].a_type == A_SYMBOL ) && ( argv[1].a_type == A_SYMBOL ) )
+ {
+ K=1;
+ if ((argc >= 3) && ( argv[2].a_type == A_FLOAT )) K=atom_getfloatarg(2, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class)))
+ pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name);
+ else if (!garray_getfloatwords(a, &npoints, &vec))
+ pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name);
+ else
+ {
+ n=0;
+ for (i=0; i < x->nb_mass; i++)
+ {
+ if ( atom_getsymbolarg(0,argc,argv) == x->mass[i].Id)
+ {
+ r = K*vec[n].w_float;
+ n++;
+ teta = K*vec[n].w_float;
+ n++;
+ phy = K*vec[n].w_float;
+ n++;
+
+ x->mass[i].posX = sph2carX(r,phy,teta);
+ x->mass[i].speedX = 0;
+ x->mass[i].forceX = 0;
+ x->mass[i].posY = sph2carY(r,phy,teta);
+ x->mass[i].speedY = 0;
+ x->mass[i].forceY = 0;
+ x->mass[i].posZ = sph2carZ(r,phy,teta);
+ x->mass[i].speedZ = 0;
+ x->mass[i].forceZ = 0;
+ if (n >= npoints +2) break;
+ }
+ }
+ }
+ }
+ else if ( (argc >= 2) && ( argv[0].a_type == A_FLOAT ) && ( argv[1].a_type == A_SYMBOL ) )
+ {
+ K=1;
+ if ((argc >= 3) && ( argv[2].a_type == A_FLOAT )) K=atom_getfloatarg(2, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(atom_getsymbolarg(1,argc,argv), garray_class)))
+ pd_error(x, "%s: no such array", atom_getsymbolarg(1,argc,argv)->s_name);
+ else if (!garray_getfloatwords(a, &npoints, &vec))
+ pd_error(x, "%s: bad template for tabLink", atom_getsymbolarg(1,argc,argv)->s_name);
+ else
+ {
+ offset = atom_getfloatarg(0, argc, argv);
+ n=min((int)npoints/2,x->nb_mass-offset);
+ for (i=0; i < n; i++)
+ {
+ r = K*vec[3*i].w_float;
+ teta = K*vec[3*i+1].w_float;
+ phy = K*vec[3*i+1].w_float;
+
+ x->mass[i+offset].posX = sph2carX(r,phy,teta);
+ x->mass[i+offset].speedX = 0;
+ x->mass[i+offset].forceX = 0;
+ x->mass[i+offset].posY = sph2carY(r,phy,teta);
+ x->mass[i+offset].speedY = 0;
+ x->mass[i+offset].forceY = 0;
+ x->mass[i+offset].posZ = sph2carZ(r,phy,teta);
+ x->mass[i+offset].speedZ = 0;
+ x->mass[i+offset].forceZ = 0;
+ }
+ }
+ }
+}
+
void pmpd3d_posX(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
{
// displace a mass to a certain position
diff --git a/pmpd3d_tab.c b/pmpd3d_tab.c
index 0ca41da..cc8f454 100644
--- a/pmpd3d_tab.c
+++ b/pmpd3d_tab.c
@@ -1,3 +1,7 @@
+#define car2sphR(z,x,y) (sqrt(x*x + y*y + z*z))
+#define car2sphTeta(z,x,y,r) (acos(z/r))
+#define car2sphPhy(z,x,y) (atan2(y,x))
+
void pmpd3d_massesPosT(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
{
int i, j, vecsize;
@@ -54,6 +58,65 @@ void pmpd3d_massesPosT(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
}
}
+void pmpd3d_massesPosSphericalT(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
+{
+ int i, j, vecsize;
+ t_garray *a;
+ t_word *vec;
+ t_float R;
+
+ if ( (argc==1) && (argv[0].a_type == A_SYMBOL) ) // table name
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ int taille_max = x->nb_mass;
+ taille_max = min(taille_max, vecsize/3 );
+ for (i=0; i < taille_max ; i++)
+ {
+ R = car2sphR(x->mass[i].posX, x->mass[i].posY, x->mass[i].posZ);
+ vec[3*i ].w_float = R;
+ vec[3*i+1].w_float = car2sphTeta(x->mass[i].posX, x->mass[i].posY, x->mass[i].posZ, R);
+ vec[3*i+2].w_float = car2sphPhy(x->mass[i].posX, x->mass[i].posY, x->mass[i].posZ);
+ }
+ garray_redraw(a);
+ }
+ }
+ else
+ if ( (argc==2) && (argv[0].a_type == A_SYMBOL) && (argv[1].a_type == A_SYMBOL) ) // mass Id; table name;
+ {
+ t_symbol *tab_name = atom_getsymbolarg(0, argc, argv);
+ if (!(a = (t_garray *)pd_findbyclass(tab_name, garray_class)))
+ pd_error(x, "%s: no such array", tab_name->s_name);
+ else if (!garray_getfloatwords(a, &vecsize, &vec))
+ pd_error(x, "%s: bad template for tabwrite", tab_name->s_name);
+ else
+ {
+ i = 0;
+ j = 0;
+ while ((i < vecsize-2) && (j < x->nb_mass))
+ {
+ if (atom_getsymbolarg(1,argc,argv) == x->mass[j].Id)
+ {
+ R = car2sphR(x->mass[j].posX, x->mass[j].posY, x->mass[j].posZ);
+ vec[i].w_float = R;
+ i++;
+ vec[i].w_float = car2sphTeta(x->mass[j].posX, x->mass[j].posY, x->mass[j].posZ, R);
+ i++;
+ vec[i].w_float = car2sphPhy(x->mass[j].posX, x->mass[j].posY, x->mass[j].posZ);
+ i++;
+ }
+ j++;
+ }
+ garray_redraw(a);
+ }
+ }
+}
+
void pmpd3d_massesSpeedsT(t_pmpd3d *x, t_symbol *s, int argc, t_atom *argv)
{
int i, j, vecsize;
diff --git a/pmpd3d_various.c b/pmpd3d_various.c
index d3e4297..fd77306 100644
--- a/pmpd3d_various.c
+++ b/pmpd3d_various.c
@@ -12,7 +12,7 @@ void pmpd3d_infosL(t_pmpd3d *x)
}
post("list of %d link", x->nb_link);
- post("number, Id, mass1, mass2, K, D, Pow, L, Lmin, Lmax");
+ post("number, Id, active, mass1, mass2, K, D, Pow, L, Lmin, Lmax");
for(i=0; i < x->nb_link; i++)
{
switch (x->link[i].lType)