aboutsummaryrefslogtreecommitdiff
path: root/pmpd2d.c
diff options
context:
space:
mode:
authorN.N. <nimon@users.sourceforge.net>2012-08-09 09:46:44 +0000
committerN.N. <nimon@users.sourceforge.net>2012-08-09 09:46:44 +0000
commitc53c7827595ee506d0f3d6d29159a675b1e963f2 (patch)
treedcb3a11b9c64b115148238f963c726c8bde266b0 /pmpd2d.c
parente1d37ed3611732e48c7ee220628c66c731892584 (diff)
adding function closestMass to pmpd2d
svn path=/trunk/externals/pmpd/; revision=16160
Diffstat (limited to 'pmpd2d.c')
-rw-r--r--pmpd2d.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/pmpd2d.c b/pmpd2d.c
index 031931a..451867e 100644
--- a/pmpd2d.c
+++ b/pmpd2d.c
@@ -18,7 +18,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
Based on PureData by Miller Puckette and others.
@@ -3668,6 +3668,32 @@ void pmpd2d_grabMass(t_pmpd2d *x, t_float posX, t_float posY, t_float grab)
}
}
+void pmpd2d_closestMass(t_pmpd2d *x, t_float posX, t_float posY)
+{
+ t_float dist, tmp;
+ t_int i;
+ t_atom std_out[3];
+
+ if ((x->nb_mass > 0))
+ {
+ dist = sqr(x->mass[0].posX - posX) + sqr(x->mass[0].posY - posY);
+ for (i=1; i<x->nb_mass; i++)
+ {
+ tmp = sqr(x->mass[i].posX - posX) + sqr(x->mass[i].posY - posY);
+ if (tmp < dist)
+ {
+ dist = tmp;
+ x->grab_nb= i;
+ }
+ }
+ }
+ SETFLOAT(&(std_out[0]),x->grab_nb);
+ SETFLOAT(&(std_out[1]), x->mass[x->grab_nb].posX);
+ SETFLOAT(&(std_out[2]), x->mass[x->grab_nb].posY);
+ outlet_anything(x->main_outlet, gensym("closestMass"),3,std_out);
+
+}
+
void *pmpd2d_new()
{
t_pmpd2d *x = (t_pmpd2d *)pd_new(pmpd2d_class);
@@ -3812,6 +3838,7 @@ void pmpd2d_setup(void)
*/
class_addmethod(pmpd2d_class, (t_method)pmpd2d_grabMass, gensym("grabMass"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(pmpd2d_class, (t_method)pmpd2d_closestMass, gensym("closestMass"), A_DEFFLOAT, A_DEFFLOAT, 0);
}