Update of /cvsroot/pure-data/externals/nusmuk/msd3D In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7919/nusmuk/msd3D
Modified Files: main.cpp Log Message: some small changes for Windows compilation
Index: main.cpp =================================================================== RCS file: /cvsroot/pure-data/externals/nusmuk/msd3D/main.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** main.cpp 22 Apr 2005 09:33:32 -0000 1.5 --- main.cpp 26 Apr 2005 11:39:49 -0000 1.6 *************** *** 40,45 **** // define constants #define MSD3D_VERSION 0.03 ! #define nb_max_link 4000 ! #define nb_max_mass 4000 #define Id_length 20
--- 40,45 ---- // define constants #define MSD3D_VERSION 0.03 ! #define nb_max_link 4000 ! #define nb_max_mass 4000 #define Id_length 20
*************** *** 49,82 **** #endif
! #define max(a,b) ( ((a) > (b)) ? (a) : (b) ) #define min(a,b) ( ((a) < (b)) ? (a) : (b) )
! typedef struct _mass { t_symbol *Id; t_int nbr; ! t_int mobile; ! t_float invM; ! t_float speedX; t_float posX; ! t_float posX2; t_float forceX; t_float out_forceX; ! t_float speedY; t_float posY; ! t_float posY2; t_float forceY; t_float out_forceY; t_float speedZ; t_float posZ; ! t_float posZ2; t_float forceZ; t_float out_forceZ; ! } t_mass; ! ! typedef struct _link { t_symbol *Id; ! t_int nbr; ! t_mass *mass1; ! t_mass *mass2; t_float K1, D1, D2; t_float longx, longy, longz, longueur, long_min, long_max; --- 49,92 ---- #endif
! #define max(a,b) ( ((a) > (b)) ? (a) : (b) ) #define min(a,b) ( ((a) < (b)) ? (a) : (b) )
! #ifdef _MSC_VER ! #define NEWARR(type,var,size) type *var = new type[size] ! #define DELARR(var) delete[] var ! #else ! #define NEWARR(type,var,size) type var[size] ! #define DELARR(var) ((void)0) ! #endif ! ! ! ! typedef struct _mass { t_symbol *Id; t_int nbr; ! t_int mobile; ! t_float invM; ! t_float speedX; t_float posX; ! t_float posX2; t_float forceX; t_float out_forceX; ! t_float speedY; t_float posY; ! t_float posY2; t_float forceY; t_float out_forceY; t_float speedZ; t_float posZ; ! t_float posZ2; t_float forceZ; t_float out_forceZ; ! } t_mass; ! ! typedef struct _link { t_symbol *Id; ! t_int nbr; ! t_mass *mass1; ! t_mass *mass2; t_float K1, D1, D2; t_float longx, longy, longz, longueur, long_min, long_max; *************** *** 111,115 **** { t_int i; ! t_atom sortie[0];
for (i=0; i<nb_mass; i++) { --- 121,125 ---- { t_int i; ! // t_atom sortie[0];
for (i=0; i<nb_mass; i++) { *************** *** 119,124 **** delete link[i]; } ! ToOutAnything(1,S_Reset,0,sortie); ! nb_link = 0; nb_mass = 0; id_mass = 0; --- 129,134 ---- delete link[i]; } ! ToOutAnything(1,S_Reset,0,NULL); ! nb_link = 0; nb_mass = 0; id_mass = 0; *************** *** 130,138 **** void m_bang() { ! t_float F=0,Fx=0,Fy=0, Fz=0,distance,vitesse, X_new, Y_new, Z_new; t_int i; ! struct _mass mass_1, mass_2; ! for (i=0; i<nb_link; i++) { // compute link forces distance = sqrt(pow(link[i]->mass1->posX-link[i]->mass2->posX,2) + pow(link[i]->mass1->posY --- 140,148 ---- void m_bang() { ! t_float F=0,Fx=0,Fy=0, Fz=0,distance,vitesse, X_new, Y_new, Z_new; t_int i; ! struct _mass mass_1, mass_2; ! for (i=0; i<nb_link; i++) { // compute link forces distance = sqrt(pow(link[i]->mass1->posX-link[i]->mass2->posX,2) + pow(link[i]->mass1->posY *************** *** 151,173 **** Fz = F * (link[i]->mass1->posZ - link[i]->mass2->posZ)/distance; // Fy[n] = F * Lz[n]/L[n] } ! } link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx ! link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1] link[i]->mass2->forceX += Fx; // Fx2[n] = Fx link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1] link[i]->mass1->forceY -= Fy; // Fy1[n] = -Fy ! link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1] link[i]->mass2->forceY += Fy; // Fy2[n] = Fy link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY; // Fy2[n] = Fy2[n] - D2 * vy2[n-1] link[i]->mass1->forceZ -= Fz; // Fz1[n] = -Fz ! link[i]->mass1->forceZ -= link[i]->D2*link[i]->mass1->speedZ; // Fz1[n] = Fz1[n] - D2 * vz1[n-1] link[i]->mass2->forceZ += Fz; // Fz2[n] = Fz link[i]->mass2->forceZ -= link[i]->D2*link[i]->mass2->speedZ; // Fz2[n] = Fz2[n] - D2 * vz2[n-1] link[i]->distance_old = distance; // L[n-1] = L[n] } ! ! for (i=0; i<nb_mass; i++) ! // compute new masses position only if mobile = 1 ! if (mass[i]->mobile == 1) { X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1] mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1] --- 161,183 ---- Fz = F * (link[i]->mass1->posZ - link[i]->mass2->posZ)/distance; // Fy[n] = F * Lz[n]/L[n] } ! } link[i]->mass1->forceX -= Fx; // Fx1[n] = -Fx ! link[i]->mass1->forceX -= link[i]->D2*link[i]->mass1->speedX; // Fx1[n] = Fx1[n] - D2 * vx1[n-1] link[i]->mass2->forceX += Fx; // Fx2[n] = Fx link[i]->mass2->forceX -= link[i]->D2*link[i]->mass2->speedX; // Fx2[n] = Fx2[n] - D2 * vx2[n-1] link[i]->mass1->forceY -= Fy; // Fy1[n] = -Fy ! link[i]->mass1->forceY -= link[i]->D2*link[i]->mass1->speedY; // Fy1[n] = Fy1[n] - D2 * vy1[n-1] link[i]->mass2->forceY += Fy; // Fy2[n] = Fy link[i]->mass2->forceY -= link[i]->D2*link[i]->mass2->speedY; // Fy2[n] = Fy2[n] - D2 * vy2[n-1] link[i]->mass1->forceZ -= Fz; // Fz1[n] = -Fz ! link[i]->mass1->forceZ -= link[i]->D2*link[i]->mass1->speedZ; // Fz1[n] = Fz1[n] - D2 * vz1[n-1] link[i]->mass2->forceZ += Fz; // Fz2[n] = Fz link[i]->mass2->forceZ -= link[i]->D2*link[i]->mass2->speedZ; // Fz2[n] = Fz2[n] - D2 * vz2[n-1] link[i]->distance_old = distance; // L[n-1] = L[n] } ! ! for (i=0; i<nb_mass; i++) ! // compute new masses position only if mobile = 1 ! if (mass[i]->mobile == 1) { X_new = mass[i]->forceX * mass[i]->invM + 2*mass[i]->posX - mass[i]->posX2; // x[n] =Fx[n]/M+2x[n]-x[n-1] mass[i]->posX2 = mass[i]->posX; // x[n-2] = x[n-1] *************** *** 184,203 **** }
! for (i=0; i<nb_mass; i++) { // clear forces ! mass[i]->out_forceX = mass[i]->forceX; mass[i]->forceX = 0; ! mass[i]->out_forceY = mass[i]->forceY; mass[i]->forceY = 0; ! mass[i]->out_forceZ = mass[i]->forceZ; mass[i]->forceZ = 0; ! } }
// -------------------------------------------------------------- MASSES // ---------------------------------------------------------------------- ! void m_mass(int argc,t_atom *argv) ! // add a mass ! // Id, nbr, mobile, invM, speedX, posX, forceX { t_atom sortie[7], aux[2]; --- 194,213 ---- }
! for (i=0; i<nb_mass; i++) { // clear forces ! mass[i]->out_forceX = mass[i]->forceX; mass[i]->forceX = 0; ! mass[i]->out_forceY = mass[i]->forceY; mass[i]->forceY = 0; ! mass[i]->out_forceZ = mass[i]->forceZ; mass[i]->forceZ = 0; ! } }
// -------------------------------------------------------------- MASSES // ---------------------------------------------------------------------- ! void m_mass(int argc,t_atom *argv) ! // add a mass ! // Id, nbr, mobile, invM, speedX, posX, forceX { t_atom sortie[7], aux[2]; *************** *** 207,211 **** error("mass : Id mobile mass X Y Z");
! mass[nb_mass] = new t_mass; // new mass mass[nb_mass]->Id = GetSymbol(argv[0]); // Id mass[nb_mass]->mobile = GetInt(argv[1]); // mobile --- 217,221 ---- error("mass : Id mobile mass X Y Z");
! mass[nb_mass] = new t_mass; // new mass mass[nb_mass]->Id = GetSymbol(argv[0]); // Id mass[nb_mass]->mobile = GetInt(argv[1]); // mobile *************** *** 214,232 **** else M = GetFloat(argv[2]); mass[nb_mass]->invM = 1/(M); // 1/M ! mass[nb_mass]->speedX = 0; // vx[n] mass[nb_mass]->posX = GetFloat(argv[3]); // x[n] ! mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1] mass[nb_mass]->forceX = 0; // Fx[n] ! mass[nb_mass]->speedY = 0; // vy[n] mass[nb_mass]->posY = GetFloat(argv[4]); // y[n] ! mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1] mass[nb_mass]->forceY = 0; // Fz[n] ! mass[nb_mass]->speedZ = 0; // vz[n] mass[nb_mass]->posZ = GetFloat(argv[5]); // z[n] ! mass[nb_mass]->posZ2 = GetFloat(argv[5]); // z[n-1] mass[nb_mass]->forceZ = 0; // Fz[n] mass[nb_mass]->nbr = id_mass; // id number nb_mass++ ; ! id_mass++; nb_mass = min ( nb_max_mass -1, nb_mass ); SetFloat((sortie[0]),id_mass-1); --- 224,242 ---- else M = GetFloat(argv[2]); mass[nb_mass]->invM = 1/(M); // 1/M ! mass[nb_mass]->speedX = 0; // vx[n] mass[nb_mass]->posX = GetFloat(argv[3]); // x[n] ! mass[nb_mass]->posX2 = GetFloat(argv[3]); // x[n-1] mass[nb_mass]->forceX = 0; // Fx[n] ! mass[nb_mass]->speedY = 0; // vy[n] mass[nb_mass]->posY = GetFloat(argv[4]); // y[n] ! mass[nb_mass]->posY2 = GetFloat(argv[4]); // y[n-1] mass[nb_mass]->forceY = 0; // Fz[n] ! mass[nb_mass]->speedZ = 0; // vz[n] mass[nb_mass]->posZ = GetFloat(argv[5]); // z[n] ! mass[nb_mass]->posZ2 = GetFloat(argv[5]); // z[n-1] mass[nb_mass]->forceZ = 0; // Fz[n] mass[nb_mass]->nbr = id_mass; // id number nb_mass++ ; ! id_mass++; nb_mass = min ( nb_max_mass -1, nb_mass ); SetFloat((sortie[0]),id_mass-1); *************** *** 240,245 **** }
! void m_forceX(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; --- 250,255 ---- }
! void m_forceX(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; *************** *** 256,261 **** }
! void m_forceY(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; --- 266,271 ---- }
! void m_forceY(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; *************** *** 272,277 **** }
! void m_forceZ(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; --- 282,287 ---- }
! void m_forceZ(int argc,t_atom *argv) ! { // add a force to mass(es) named Id t_int i; *************** *** 289,294 ****
void m_posX(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); --- 299,304 ----
void m_posX(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); *************** *** 306,311 ****
void m_posY(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); --- 316,321 ----
void m_posY(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); *************** *** 324,329 ****
void m_posZ(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); --- 334,339 ----
void m_posZ(int argc,t_atom *argv) ! { ! // displace mass(es) named Id to a certain position t_int i; const t_symbol *sym = GetSymbol(argv[0]); *************** *** 342,347 ****
void m_set_mobile(int argc,t_atom *argv) ! { ! // set mass No to mobile t_int i,aux; --- 352,357 ----
void m_set_mobile(int argc,t_atom *argv) ! { ! // set mass No to mobile t_int i,aux; *************** *** 359,364 ****
void m_set_fixe(int argc,t_atom *argv) ! { ! // set mass No to fixed t_int i,aux; --- 369,374 ----
void m_set_fixe(int argc,t_atom *argv) ! { ! // set mass No to fixed t_int i,aux; *************** *** 379,383 **** // Delete mass t_int i,nb_link_delete=0; ! t_atom sortie[7], aux[nb_link];
if (argc != 1) --- 389,394 ---- // Delete mass t_int i,nb_link_delete=0; ! t_atom sortie[7]; ! NEWARR(t_atom,aux,nb_link);
if (argc != 1) *************** *** 411,419 **** break; } }
void m_Xmax(int argc,t_atom *argv) ! { // set X max if (argc != 1) --- 422,431 ---- break; } + DELARR(aux); }
void m_Xmax(int argc,t_atom *argv) ! { // set X max if (argc != 1) *************** *** 423,427 ****
void m_Xmin(int argc,t_atom *argv) ! { // set X min if (argc != 1) --- 435,439 ----
void m_Xmin(int argc,t_atom *argv) ! { // set X min if (argc != 1) *************** *** 430,434 **** } void m_Ymax(int argc,t_atom *argv) ! { // set Y max if (argc != 1) --- 442,446 ---- } void m_Ymax(int argc,t_atom *argv) ! { // set Y max if (argc != 1) *************** *** 438,442 ****
void m_Ymin(int argc,t_atom *argv) ! { // set Y min if (argc != 1) --- 450,454 ----
void m_Ymin(int argc,t_atom *argv) ! { // set Y min if (argc != 1) *************** *** 446,450 ****
void m_Zmax(int argc,t_atom *argv) ! { // set maximum Z of all masses if (argc != 1) --- 458,462 ----
void m_Zmax(int argc,t_atom *argv) ! { // set maximum Z of all masses if (argc != 1) *************** *** 454,458 ****
void m_Zmin(int argc,t_atom *argv) ! { // set minimum Z of all masses if (argc != 1) --- 466,470 ----
void m_Zmin(int argc,t_atom *argv) ! { // set minimum Z of all masses if (argc != 1) *************** *** 464,470 **** // --------------------------------------------------------------------- void m_link(int argc,t_atom *argv) ! // add a link ! // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax) ! { t_atom sortie[7], aux[2]; t_int i; --- 476,482 ---- // --------------------------------------------------------------------- void m_link(int argc,t_atom *argv) ! // add a link ! // Id, *mass1, *mass2, K1, D1, D2, (Lmin,Lmax) ! { t_atom sortie[7], aux[2]; t_int i; *************** *** 479,483 **** else if(mass[i]->nbr==GetAInt(argv[2])) // pointer to mass2 link[nb_link]->mass2 = mass[i]; ! link[nb_link]->K1 = GetFloat(argv[3]); // K1 link[nb_link]->D1 = GetFloat(argv[4]); // D1 link[nb_link]->D2 = GetFloat(argv[5]); // D2 --- 491,495 ---- else if(mass[i]->nbr==GetAInt(argv[2])) // pointer to mass2 link[nb_link]->mass2 = mass[i]; ! link[nb_link]->K1 = GetFloat(argv[3]); // K1 link[nb_link]->D1 = GetFloat(argv[4]); // D1 link[nb_link]->D2 = GetFloat(argv[5]); // D2 *************** *** 503,507 **** } nb_link++; ! id_link++; nb_link = min ( nb_max_link -1, nb_link ); SetFloat((sortie[0]),id_link-1); --- 515,519 ---- } nb_link++; ! id_link++; nb_link = min ( nb_max_link -1, nb_link ); SetFloat((sortie[0]),id_link-1); *************** *** 512,524 **** SetFloat((sortie[5]),link[nb_link-1]->D1); SetFloat((sortie[6]),link[nb_link-1]->D2); ! ToOutAnything(1,S_Link,7,sortie); }
void m_ilink(int argc,t_atom *argv) ! // add interactor link ! // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax) ! { t_atom aux[2], arglist[8]; ! t_int i,j, imass1[nb_mass], nbmass1=0, imass2[nb_mass], nbmass2=0; t_symbol *Id1, *Id2;
--- 524,538 ---- SetFloat((sortie[5]),link[nb_link-1]->D1); SetFloat((sortie[6]),link[nb_link-1]->D2); ! ToOutAnything(1,S_Link,7,sortie); }
void m_ilink(int argc,t_atom *argv) ! // add interactor link ! // Id, Id masses1, Id masses2, K1, D1, D2, (Lmin, Lmax) ! { t_atom aux[2], arglist[8]; ! t_int i,j, nbmass1=0, nbmass2=0; ! NEWARR(t_int,imass1,nb_mass); ! NEWARR(t_int,imass2,nb_mass); t_symbol *Id1, *Id2;
*************** *** 561,568 **** m_link(argc,arglist); } }
void m_setK(int argc,t_atom *argv) ! { // set rigidity of link(s) named Id t_int i; --- 575,584 ---- m_link(argc,arglist); } + DELARR(imass1); + DELARR(imass2); }
void m_setK(int argc,t_atom *argv) ! { // set rigidity of link(s) named Id t_int i; *************** *** 580,584 ****
void m_setD(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; --- 596,600 ----
void m_setD(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; *************** *** 596,600 ****
void m_setD2(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; --- 612,616 ----
void m_setD2(int argc,t_atom *argv) ! { // set damping of link(s) named Id t_int i; *************** *** 828,832 **** // List of masses positions on first outlet { ! t_atom sortie[3*nb_mass]; t_int i; --- 844,848 ---- // List of masses positions on first outlet { ! NEWARR(t_atom,sortie,3*nb_mass); t_int i; *************** *** 837,840 **** --- 853,857 ---- } ToOutAnything(0, S_massesPosL, 3*nb_mass, sortie); + DELARR(sortie); }
*************** *** 842,846 **** // List of masses positions on first outlet { ! t_atom sortie[3*nb_mass]; t_int i; --- 859,863 ---- // List of masses positions on first outlet { ! NEWARR(t_atom,sortie,3*nb_mass); t_int i; *************** *** 851,854 **** --- 868,872 ---- } ToOutAnything(0, S_massesForcesL, 3*nb_mass, sortie); + DELARR(sortie); }
*************** *** 885,889 **** // -------------------------------------------------------------- GLOBAL VARIABLES // -------------------------------------------------------------------------------- ! t_link * link[nb_max_link]; t_mass * mass[nb_max_mass]; t_float Xmin, Xmax, Ymin, Ymax, Zmin, Zmax; --- 903,907 ---- // -------------------------------------------------------------- GLOBAL VARIABLES // -------------------------------------------------------------------------------- ! t_link * link[nb_max_link]; t_mass * mass[nb_max_mass]; t_float Xmin, Xmax, Ymin, Ymax, Zmin, Zmax;