aboutsummaryrefslogtreecommitdiff
path: root/pmpd3d.c
diff options
context:
space:
mode:
authorN.N. <nimon@users.sourceforge.net>2012-08-09 10:09:50 +0000
committerN.N. <nimon@users.sourceforge.net>2012-08-09 10:09:50 +0000
commit02ba30b42ffc1f8591b25f5a22fecb515c6b972d (patch)
tree093b37baddea4b5424ad75cc6674ecbbc2dac673 /pmpd3d.c
parentc53c7827595ee506d0f3d6d29159a675b1e963f2 (diff)
adding closestMass function to pmpd3d
svn path=/trunk/externals/pmpd/; revision=16161
Diffstat (limited to 'pmpd3d.c')
-rw-r--r--pmpd3d.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/pmpd3d.c b/pmpd3d.c
index b275f49..6349373 100644
--- a/pmpd3d.c
+++ b/pmpd3d.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.
@@ -4395,6 +4395,33 @@ void pmpd3d_grabMass(t_pmpd3d *x, t_float posX, t_float posY, t_float posZ, t_fl
}
}
+void pmpd3d_closestMass(t_pmpd3d *x, t_float posX, t_float posY, t_float posZ)
+{
+ t_float dist, tmp;
+ t_int i;
+ t_atom std_out[4];
+
+ if ((x->nb_mass > 0))
+ {
+ dist = sqr(x->mass[0].posX - posX) + sqr(x->mass[0].posY - posY) + sqr(x->mass[0].posZ - posZ);
+ for (i=1; i<x->nb_mass; i++)
+ {
+ tmp = sqr(x->mass[i].posX - posX) + sqr(x->mass[i].posY - posY) + sqr(x->mass[i].posZ - posZ);
+ 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);
+ SETFLOAT(&(std_out[3]), x->mass[x->grab_nb].posZ);
+ outlet_anything(x->main_outlet, gensym("closestMass"),4,std_out);
+
+}
+
void *pmpd3d_new()
{
t_pmpd3d *x = (t_pmpd3d *)pd_new(pmpd3d_class);
@@ -4562,6 +4589,7 @@ void pmpd3d_setup(void)
*/
class_addmethod(pmpd3d_class, (t_method)pmpd3d_grabMass, gensym("grabMass"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
+ class_addmethod(pmpd3d_class, (t_method)pmpd3d_closestMass, gensym("closestMass"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0);
}