Update of /cvsroot/pure-data/externals/nusmuk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4827
Modified Files: msd.h Log Message: represent mobility by inverse mass, larger index tables
Index: msd.h =================================================================== RCS file: /cvsroot/pure-data/externals/nusmuk/msd.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** msd.h 3 May 2005 08:45:36 -0000 1.3 --- msd.h 3 May 2005 11:30:18 -0000 1.4 *************** *** 93,98 **** t_int nbr; const t_symbol *Id; ! bool mobile; ! t_float invM; t_float speed[N]; t_float pos[N]; --- 93,97 ---- t_int nbr; const t_symbol *Id; ! t_float M,invM; t_float speed[N]; t_float pos[N]; *************** *** 104,110 **** Mass(t_int n,const t_symbol *id,bool mob,t_float m,t_float p[N]) : nbr(n),Id(id) ! , mobile(mob) ! , invM(m?1.f/m:1) { for(int i = 0; i < N; ++i) { pos[i] = pos2[i] = p[i]; --- 103,110 ---- Mass(t_int n,const t_symbol *id,bool mob,t_float m,t_float p[N]) : nbr(n),Id(id) ! , M(m) { + if(mob) setMobile(); else setFixed(); + for(int i = 0; i < N; ++i) { pos[i] = pos2[i] = p[i]; *************** *** 127,147 **** } inline void compute(t_float limit[N][2]) { - // compute new masses position only if mobile = 1 - if(mobile) { - for(int i = 0; i < N; ++i) { - t_float pold = pos[i]; - t_float pnew = force[i] * invM + 2*pold - pos2[i]; // x[n] =Fx[n]/M+2x[n]-x[n-1] - if(pnew < limit[i][0]) pnew = limit[i][0]; else if(pnew > limit[i][1]) pnew = limit[i][1]; - speed[i] = (pos[i] = pnew) - (pos2[i] = pold); // x[n-2] = x[n-1], x[n-1] = x[n],vx[n] = x[n] - x[n-1] - } - } - // clear forces for(int i = 0; i < N; ++i) { out_force[i] = force[i]; force[i] = 0; // Fx[n] = 0 } } };
--- 127,159 ---- } + inline bool getMobile() const { return invM != 0; } + + inline void setMobile() { invM = M?1.f/M:1.; } + inline void setFixed() { invM = 0; } + inline void compute(t_float limit[N][2]) { for(int i = 0; i < N; ++i) { + t_float pold = pos[i]; + t_float pnew = force[i] * invM + 2*pold - pos2[i]; // x[n] =Fx[n]/M+2x[n]-x[n-1] + if(pnew < limit[i][0]) pnew = limit[i][0]; else if(pnew > limit[i][1]) pnew = limit[i][1]; + speed[i] = (pos[i] = pnew) - (pos2[i] = pold); // x[n-2] = x[n-1], x[n-1] = x[n],vx[n] = x[n] - x[n-1] + + // clear forces out_force[i] = force[i]; force[i] = 0; // Fx[n] = 0 } } + + static t_float dist(const Mass &m1,const Mass &m2) + { + if(N == 1) + return fabs(m1.pos[0]-m2.pos[0]); // L[n] = |x1 - x2| + else { + t_float distance = 0; + for(int i = 0; i < N; ++i) distance += sqr(m1.pos[i]-m2.pos[i]); + return sqrt(distance); + } + } };
*************** *** 156,173 **** t_float distance_old; - inline t_float compdist() const - { - const Mass<N> *m1 = mass1,*m2 = mass2; // cache locally - t_float distance; - if(N == 1) - distance = fabs(m1->pos[0]-m2->pos[0]); // L[n] = |x1 - x2| - else { - distance = 0; - for(int i = 0; i < N; ++i) distance += sqr(m1->pos[i]-m2->pos[i]); - distance = sqrt(distance); - } - return distance; - } - Link(t_int n,const t_symbol *id,Mass<N> *m1,Mass<N> *m2,t_float k1,t_float d1,t_float d2,t_float lmin,t_float lmax) : nbr(n),Id(id) --- 168,171 ---- *************** *** 176,180 **** , long_min(lmin),long_max(lmax) { ! distance_old = longueur = compdist(); // L[n-1]
mass1->links.insert(this); --- 174,178 ---- , long_min(lmin),long_max(lmax) { ! distance_old = longueur = Mass<N>::dist(*mass1,*mass2); // L[n-1]
mass1->links.insert(this); *************** *** 192,197 **** { Mass<N> *m1 = mass1,*m2 = mass2; // cache locally ! t_float distance = compdist(); ! if (distance < long_min || distance > long_max || distance == 0) { for(int i = 0; i < N; ++i) { --- 190,194 ---- { Mass<N> *m1 = mass1,*m2 = mass2; // cache locally ! t_float distance = Mass<N>::dist(*m1,*m2); if (distance < long_min || distance > long_max || distance == 0) { for(int i = 0; i < N; ++i) { *************** *** 225,232 **** template <typename T> class IndexMap ! : TablePtrMap<unsigned int,T,16> { public: ! typedef TablePtrMap<unsigned int,T,16> Parent; virtual ~IndexMap() { reset(); } --- 222,229 ---- template <typename T> class IndexMap ! : TablePtrMap<unsigned int,T,64> { public: ! typedef TablePtrMap<unsigned int,T,64> Parent; virtual ~IndexMap() { reset(); } *************** *** 259,263 **** template <typename T> class IDMap ! : TablePtrMap<const t_symbol *,TablePtrMap<T,T,4> *> { public: --- 256,260 ---- template <typename T> class IDMap ! : TablePtrMap<const t_symbol *,TablePtrMap<T,T,4> *,4> { public: *************** *** 265,269 **** typedef TablePtrMap<T,T,4> Container; // that's the map for the key ID (symbol,int) relating to the data items ! typedef TablePtrMap<const t_symbol *,Container *> Parent;
typedef typename Container::iterator iterator; --- 262,266 ---- typedef TablePtrMap<T,T,4> Container; // that's the map for the key ID (symbol,int) relating to the data items ! typedef TablePtrMap<const t_symbol *,Container *,4> Parent;
typedef typename Container::iterator iterator; *************** *** 460,464 **** t_mass *m = mass.find(GetAInt(argv[0])); if(m) ! m->mobile = mob; else error("%s - %s : Index not found",thisName(),GetString(thisTag())); --- 457,462 ---- t_mass *m = mass.find(GetAInt(argv[0])); if(m) ! if(mob) m->setMobile(); ! else m->setFixed(); else error("%s - %s : Index not found",thisName(),GetString(thisTag())); *************** *** 850,855 **** SetInt((sortie[0]),m->nbr); SetSymbol((sortie[1]),m->Id); ! SetBool((sortie[2]),m->mobile); ! SetFloat((sortie[3]),1.f/m->invM); for(int i = 0; i < N; ++i) SetFloat((sortie[4+i]),m->pos[i]); ToOutAnything(1,s,4+N,sortie); --- 848,853 ---- SetInt((sortie[0]),m->nbr); SetSymbol((sortie[1]),m->Id); ! SetBool((sortie[2]),m->getMobile()); ! SetFloat((sortie[3]),m->M); for(int i = 0; i < N; ++i) SetFloat((sortie[4+i]),m->pos[i]); ToOutAnything(1,s,4+N,sortie);