Allink  v0.1
ForcesDraw.cpp
00001 #include "Forces.h"
00002 #ifdef __glut_h__
00003 #include "../include/Draw.h"
00004 Draw *Dr;
00005 //OpenGL
00006 int Forces::Graphics(int argc,char **argv){
00007   Dr = new Draw();
00008   for(int d=0;d<3;d++) Dr->Edge[d] = pEdge(d);
00009   Dr->InvScaleUn = pInvEdge(0);
00010   Dr->Window(argc,argv);
00011   // Dr->xp = 0.;Dr->zp = 0.;
00012   Dr->xa = -60.;Dr->ya = -00.;Dr->za = -38.;
00013   Dr->xf = -30.;Dr->yf = 5.;Dr->yf = 0.;
00014   Dr->xi = -.4;Dr->yi = -.4;Dr->zi = 0.;
00015   for(int n=0;n<pNNano();n++){
00016     Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height);
00017   }
00018   glutPostRedisplay();
00019   glutMainLoop();
00020   //Interp();
00021 }
00022 void Figure(){
00023   //Dr->Draw1();
00024   Dr->DFigure();
00025   //Dr->DMinimal();
00026 }
00027 void ParticleRealTime(){
00028   return ;
00029   Dr->OpenImage("RadDistrNanoR1_0H0_4h32_0.tif");
00030   glPopMatrix();
00031   glRasterPos3d(-.35,-.4,-.32);
00032   glPixelZoom(.5,.5);
00033   glDrawPixels(Dr->ImWidth,Dr->ImHeight,GL_RGBA,GL_UNSIGNED_BYTE,Dr->pixel);
00034   glPushMatrix();
00035 }
00036 void reshape(int w,int h){
00037   Dr->Dreshape(w,h);
00038 }
00039 void Timer(int v){
00040   Dr->DTimer(v);
00041 }
00042 void MouseMove(int x,int y){
00043   Dr->DMouseMove(x,y);
00044 }
00045 void mouse(int button, int state,int x,int y){
00046   Dr->Dmouse(button,state,x,y);
00047 };
00048 void special(int k, int x, int y){
00049   Dr->Dspecial(k,x,y);
00050 }
00051 void Forces::DrawScene(){
00052   if(VAR_IF_TYPE(SysShape,SYS_2D) && !IfLine)
00053     DrawCarpet();
00054   else 
00055     DrawParticles();
00056 }
00057 void Forces::DynamicsView(void){
00058   double Num=0.;
00059   Dr->Diap++;
00060   Dr->tDiap=glutGet(GLUT_ELAPSED_TIME);
00061   double Speed=25.;
00062   double fps = Dr->Diap*1000.0/(Dr->tDiap-Dr->tDiapBase);
00063   double Ratio = 0.;
00064   double NRatio = 0.;
00065   if (Dr->tDiap - Dr->tDiapBase > 1000) {
00066     fprintf(stderr,"Frame per second %lf\r",fps);
00067     Dr->tDiapBase = Dr->tDiap;      
00068     Dr->Diap = 0;
00069   }
00070   if(Dr->tDiap - Dr->tDiapBase > 1000/Speed){
00071     for(int i=0;i<NUpdate;i++){
00072       Dynamics();
00073       //Interp();
00074       if(VAR_IF_TYPE(CalcMode,CALC_NcVT))
00075    Dr->Step += pNPCh()-1;
00076     }
00077     if(IfMovie && (pStep()%5)==0){
00078       Dr->Step++;
00079       Dr->Picture();
00080     }
00081     Dr->za += 1.;
00082     CurrTime = time(NULL);
00083     Ratio += Dr->Step/(1000.*(CurrTime-InitTime));
00084     NRatio += 1.;
00085     double v2 = 0.;
00086     for(int p=0;p<pNPart();p++){
00087       for(int d=0;d<3;d++){
00088    v2 += SQR(pVel(p,d));
00089       }
00090     }
00091     sprintf(Dr->info,"NPart %d loop/s %lf acc/step %lf in/out %lf T %lf Pot %lf",pNPart(),Ratio/NRatio,(NRemoval+NInsertion)/(double)pStep(),NInsertion/(double)NRemoval,v2/(double)(3*pNPart()),OldNrgSys);
00092     DrawScene();
00093     glutPostRedisplay();
00094     glutTimerFunc(1000, Timer, 1);
00095   }
00096 }
00097 void Forces::DrawSoil(){
00098   if(!VAR_IF_TYPE(SysShape,SYS_ELECTRO)){
00099     return;
00100   }
00101   glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);  
00102   glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00103   glEnable(GL_DEPTH_TEST);
00104   glEnable(GL_LIGHT1);
00105   glEnable(GL_LIGHTING);
00106   double InvScaleUn = Dr->InvScaleUn;
00107   int NBin = 30;
00108   double InvNBin = 1./(double)NBin;
00109   Vettore v1(3);
00110   Vettore v2(3);
00111   Vettore v3(3);
00112   Vettore v4(3);
00113   Vettore vN(3);
00114   int Typ = 1;
00115   for(int sx=0;sx<NBin-1;sx++){
00116     for(int sy=0;sy<NBin-1;sy++){
00117       v1.x[0] = sx*pEdge(0)*InvNBin;
00118       v2.x[0] = (sx+1)*pEdge(0)*InvNBin;
00119       v3.x[0] = (sx+1)*pEdge(0)*InvNBin;
00120       v4.x[0] = (sx)*pEdge(0)*InvNBin;
00121       v1.x[1] = sy*pEdge(1)*InvNBin;
00122       v2.x[1] = (sy)*pEdge(1)*InvNBin;
00123       v3.x[1] = (sy+1)*pEdge(1)*InvNBin;
00124       v4.x[1] = (sy+1)*pEdge(1)*InvNBin;
00125       v1.x[2] =  .2*pEdge(2)*sin(6*v1.x[0]*pInvEdge(0))*sin(4*v1.x[1]*pInvEdge(1)) + .4*pEdge(2);
00126       v2.x[2] =  .2*pEdge(2)*sin(6*v2.x[0]*pInvEdge(0))*sin(4*v2.x[1]*pInvEdge(1)) + .4*pEdge(2);
00127       v3.x[2] =  .2*pEdge(2)*sin(6*v3.x[0]*pInvEdge(0))*sin(4*v3.x[1]*pInvEdge(1)) + .4*pEdge(2);
00128       v4.x[2] =  .2*pEdge(2)*sin(6*v4.x[0]*pInvEdge(0))*sin(4*v4.x[1]*pInvEdge(1)) + .4*pEdge(2);
00129       for(int d=0;d<3;d++){
00130          v1.x[d] *= InvScaleUn;
00131          v2.x[d] *= InvScaleUn;
00132          v3.x[d] *= InvScaleUn;
00133          v4.x[d] *= InvScaleUn;
00134       }
00135       glColor4fv(ColorType[Typ]);
00136       glLightfv(GL_LIGHT0, GL_AMBIENT,ColorType[Typ]);
00137       glLightfv(GL_LIGHT1, GL_DIFFUSE,ColorType[Typ]);
00138       glLightfv(GL_LIGHT1, GL_POSITION,ColorType[Typ]);
00139       vN.Normalize();
00140       glPushMatrix();//Particle
00141       glBegin(GL_POLYGON);
00142       vN = v1^v2;
00143       glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
00144       glVertex3d(v1.x[0],v1.x[1],v1.x[2]);
00145       vN = v2^v3;
00146       glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
00147       glVertex3d(v2.x[0],v2.x[1],v2.x[2]); 
00148       vN = v3^v4;
00149       glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
00150       glVertex3d(v3.x[0],v3.x[1],v3.x[2]);
00151       vN = v4^v1;
00152       glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
00153       glVertex3d(v4.x[0],v4.x[1],v4.x[2]);
00154       glEnd();
00155       glPopMatrix();//Particle
00156     }
00157   }
00158   glDisable(GL_DEPTH_TEST);
00159   glDisable(GL_LIGHT1);
00160   glDisable(GL_LIGHTING);
00161 }
00162 void Forces::DrawCarpet(){
00163   if(!VAR_IF_TYPE(SysShape,SYS_2D)){
00164     return;
00165   }
00166   glDeleteLists(Dr->Particles,1);
00167   Dr->Particles = glGenLists(1);
00168   glNewList(Dr->Particles,GL_COMPILE);
00169   // glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);  
00170   // glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00171   // glEnable(GL_DEPTH_TEST);
00172   glEnable(GL_LIGHT1);
00173   glEnable(GL_LIGHTING);
00174   //glFrontFace(GL_CCW);
00175   //glShadeModel(GL_SMOOTH);
00176   double InvScaleUn = Dr->InvScaleUn;
00177   Vettore v1(3);
00178   Vettore v2(3);
00179   Vettore v3(3);
00180   Vettore vN(3);
00181   for(int sx=0;sx<nEdge[0]-1;sx++){
00182     for(int sy=0;sy<nEdge[1]-1;sy++){
00183       int pRight[3] = {sx*nEdge[1]+sy,(sx+1)*nEdge[1]+sy,(sx+1)*nEdge[1]+sy+1};
00184       for(int d=0;d<3;d++){
00185    v1.x[d] = pPos(pRight[0],d)*InvScaleUn;
00186    v2.x[d] = pPos(pRight[1],d)*InvScaleUn;
00187    v3.x[d] = pPos(pRight[2],d)*InvScaleUn;
00188       }
00189       int Typ = pType(sx*pNChain()+sy);
00190       glColor4fv(ColorType[Typ]);
00191       glLightfv(GL_LIGHT0, GL_AMBIENT,ColorType[Typ]);
00192       glLightfv(GL_LIGHT1, GL_DIFFUSE,ColorType[Typ]);
00193       //glLightfv(GL_LIGHT1, GL_POSITION,ColorType[Typ]);
00194       //vN = v1^v2;
00195       vN.x[0] = v1.x[1]*v2.x[2] - v1.x[2]*v2.x[1];
00196       vN.x[1] = v1.x[2]*v2.x[0] - v1.x[0]*v2.x[2];
00197       vN.x[2] = v1.x[0]*v2.x[1] - v1.x[1]*v2.x[0];
00198       vN.Normalize();
00199       glPushMatrix();//Particle
00200       //glColor4f(.2,1.,.2,1.);
00201       glBegin(GL_TRIANGLES);
00202       glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
00203       glVertex3d(v1.x[0],v1.x[1],v1.x[2]);
00204       glVertex3d(v2.x[0],v2.x[1],v2.x[2]);
00205       glVertex3d(v3.x[0],v3.x[1],v3.x[2]);
00206       glEnd();
00207       glPopMatrix();//Particle
00208       int pLeft[3] = {sx*pNChain()+sy,(sx+1)*pNChain()+sy+1,sx*pNChain()+sy+1};
00209       for(int d=0;d<3;d++){
00210    v1.x[d] = pPos(pLeft[0],d)*InvScaleUn;
00211    v2.x[d] = pPos(pLeft[1],d)*InvScaleUn;
00212    v3.x[d] = pPos(pLeft[2],d)*InvScaleUn;
00213       }
00214       vN.x[0] = v1.x[1]*v2.x[2] - v1.x[2]*v2.x[1];
00215       vN.x[1] = v1.x[2]*v2.x[0] - v1.x[0]*v2.x[2];
00216       vN.x[2] = v1.x[0]*v2.x[1] - v1.x[1]*v2.x[0];
00217       //      vN = v1^v2;
00218       vN.Normalize();
00219       glPushMatrix();//Particle
00220       //glColor4f(.2,.5,.2,1.);
00221       glBegin(GL_TRIANGLES);
00222       glNormal3f(vN.x[0],vN.x[1],vN.x[2]);
00223       glVertex3d(v1.x[0],v1.x[1],v1.x[2]);
00224       glVertex3d(v2.x[0],v2.x[1],v2.x[2]);
00225       glVertex3d(v3.x[0],v3.x[1],v3.x[2]);
00226       glEnd();
00227       glPopMatrix();//Particle
00228     }
00229   }
00230   DrawNano();
00231   glEndList();
00232 }
00233 void Forces::DrawParticles(){
00234   double InvScaleUn = Dr->InvScaleUn;
00235   double Diameter = .01;
00236   glDeleteLists(Dr->Particles,1);
00237   Dr->Particles = glGenLists(1);
00238   glNewList(Dr->Particles,GL_COMPILE);
00239   glDisable(GL_LIGHTING);
00240   glLineWidth(3);
00241   glPointSize(5);
00242   for(int p=0,link=0;p<pNPart();p++){
00243     float Red = Pm[p].Pos[2]*.5*pInvEdge(2);
00244     int Typ = pType(p) < 6 ? pType(p) : 5;
00245     glColor4f(Red*ColorType[Typ][0],ColorType[Typ][1],ColorType[Typ][2],1.);
00246     //glColor4fv(ColorType[Typ]);
00247     //Dr->Numera(Pm[p].Pos,p);
00248     if(IfLine && Ln[p].NLink >0) DrBondLine(p);
00249     if(Dr->IfPoint){
00250       glPushMatrix();//Particle
00251       //glBegin(GL_POINTS);     
00252       glTranslatef((GLfloat)(pPos(p,0)*InvScaleUn),
00253          (GLfloat)(pPos(p,1)*InvScaleUn),
00254          (GLfloat)(pPos(p,2)*InvScaleUn));
00255       //else if(IfColour) glCallList(Quad);
00256       int Typ = pType(p) < 6 ? pType(p) : 5;
00257       glColor4fv(ColorType[Typ]);
00258       if(!IfSphere) glCallList(Dr->Point);
00259       else glutSolidSphere(Diameter,20,20);
00260       glPopMatrix();//Particle
00261     }
00262   }
00263   if(VAR_IF_TYPE(SysShape,SYS_LEAVES)){
00264     glBegin(GL_LINES);
00265     glColor4f(.7,.7,.0,1.);
00266     glPushMatrix();//Line
00267     glVertex3f(0.,.5,.6);
00268     glVertex3f(1.,.5,.6);
00269     glPopMatrix();//Line    
00270     glPushMatrix();//Line
00271     glVertex3f(0.,.5,.4);
00272     glVertex3f(1.,.5,.4);
00273     glPopMatrix();//Line    
00274     glPushMatrix();//Line
00275     glVertex3f((GLfloat)(pPos(0,0)*InvScaleUn),
00276           (GLfloat)(pPos(0,1)*InvScaleUn),
00277           (GLfloat)(pPos(0,2)*InvScaleUn));
00278     glVertex3f((GLfloat)(pPos(NEdge-1,0)*InvScaleUn),
00279           (GLfloat)(pPos(NEdge-1,1)*InvScaleUn),
00280           (GLfloat)(pPos(NEdge-1,2)*InvScaleUn));
00281     glPopMatrix();//Line    
00282     glPushMatrix();//Line
00283     glVertex3f((GLfloat)(Pm[NEdge].Pos[0]*InvScaleUn),
00284           (GLfloat)(Pm[NEdge].Pos[1]*InvScaleUn),
00285           (GLfloat)(Pm[NEdge].Pos[2]*InvScaleUn));
00286     glVertex3f((GLfloat)(Pm[2*NEdge-1].Pos[0]*InvScaleUn),
00287           (GLfloat)(Pm[2*NEdge-1].Pos[1]*InvScaleUn),
00288           (GLfloat)(Pm[2*NEdge-1].Pos[2]*InvScaleUn));
00289     glPopMatrix();//Line    
00290     glEnd();
00291   }
00292   if(IfLine){
00293     for(int p=0;p<NShow-1;p++){
00294       //printf("%d (%lf %lf %lf)\n",p,Pl[p].Pos[0],Pl[p].Pos[1],Pl[p].Pos[2]);
00295       if(Pl[p].Idx == NEdge-2) continue;
00296       glPushMatrix();//Particle
00297       glColor4f(1.,.0,.0,1.);
00298       //glBegin(GL_POINTS);     
00299       glBegin(GL_LINES);
00300       glVertex3f((GLfloat)(Pl[p].Pos[0]*InvScaleUn),
00301        (GLfloat)(Pl[p].Pos[1]*InvScaleUn),
00302        (GLfloat)(Pl[p].Pos[2]*InvScaleUn));
00303       glVertex3f((GLfloat)(Pl[p+1].Pos[0]*InvScaleUn),
00304        (GLfloat)(Pl[p+1].Pos[1]*InvScaleUn),
00305        (GLfloat)(Pl[p+1].Pos[2]*InvScaleUn));
00306       glEnd();
00308 //           glTranslatef((GLfloat)(Pl[p].Pos[0]*InvScaleUn),
00309 //              (GLfloat)(Pl[p].Pos[1]*InvScaleUn),
00310 //              (GLfloat)(Pl[p].Pos[2]*InvScaleUn));
00311 //           glCallList(Point);
00312       glPopMatrix();//Particle
00313     }
00314   }
00315   DrawNano();
00316   DrawSoil();
00317   glEndList();
00318 }
00319 void Forces::DrBondLine(int p){
00320   double InvScaleUn = Dr->InvScaleUn;
00321   if(pNLink()==0)return;
00322   glDisable(GL_LIGHTING);
00323   for(int l=0;l<Ln[p].NLink;l++){
00324     int link = Ln[p].Link[l];
00325     double Pos[3] = {pPos(link,0),pPos(link,1),pPos(link,2)};
00326     double Mid[3];
00327     int IfContinue = 1;
00328     for(int d=0;d<3;d++){
00329       double Bf = floor((pPos(p,d) - pPos(link,d))*pInvEdge(d)+.5)*pEdge(d);
00330       if(fabs(Bf) > 0. & !PeriodicImage[d]) IfContinue = 0;
00331       else Pos[d] += Bf;
00332       Mid[d] = .5*(pPos(p,d)+Pos[d])*InvScaleUn;
00333     }
00334     //if(!IfContinue) continue;
00335     glPushMatrix();//Line
00336     glBegin(GL_LINES);
00337     glColor4fv(ColorType[pType(p)]);
00338     glVertex3d((pPos(p,0)*InvScaleUn),
00339           (pPos(p,1)*InvScaleUn),
00340           (pPos(p,2)*InvScaleUn));
00341     glVertex3d(Mid[0],Mid[1],Mid[2]);
00342     glColor4fv(ColorType[pType(link)]);
00343     glVertex3d(Mid[0],Mid[1],Mid[2]);
00344     glVertex3d(((Pos[0])*InvScaleUn),
00345           ((Pos[1])*InvScaleUn),
00346           ((Pos[2])*InvScaleUn));
00347     glEnd();
00348     glPopMatrix();//Line
00349    }
00350 }
00351 void Forces::DrawNano(){
00352   glDisable(GL_LIGHTING);
00353   for(int n=0;n<pNNano();n++){
00354     if(Nano[n].Shape == 0) continue;
00355     Vettore Ax(Nano[n].Axis[0],Nano[n].Axis[1],Nano[n].Axis[2]);
00356     Vettore Zed(0.,0.,1.);
00357     double Angle = Zed.Angle(&Ax,&Zed);
00358     Quadri q(Ax.x,Angle);
00359     Matrice M(q,4);
00360     glPushMatrix();//Nano
00361     glTranslated((pNanoPos(n,0)*Dr->InvScaleUn),
00362        (pNanoPos(n,1)*Dr->InvScaleUn),
00363        (pNanoPos(n,2)*Dr->InvScaleUn));
00364     glColor4f( 1.,.1,.1,1.);
00365     if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_SPH)){
00366       glutSolidSphere(Nano[n].Rad,20,20);
00367     }
00368     else if(VAR_IF_TYPE(Nano[n].Shape,SHAPE_CYL)){
00369       glCallList(Cylinder[n]);
00370     }
00371     glPopMatrix();//Nano
00372   }
00373 }
00374 void Forces::Menu(){
00375   //submenu = glutCreateMenu(processEvent);
00376   glutAddMenuEntry("SottoPrima",3);
00377 
00378   //menu = glutCreateMenu(processEvent);
00379   glutAddMenuEntry("Move",1);
00380   glutAddMenuEntry("Stop",2);
00381   glutAddSubMenu("Altro",submenu);
00382   glutAttachMenu(GLUT_RIGHT_BUTTON);
00383 }
00384 void Forces::keyboard(unsigned char key,int x, int y){
00385   double StepDiameter = 0.01;
00386   switch (key){
00387   case 'a':
00388     CreateInitial();
00389     DrawScene();
00390     glutPostRedisplay();
00391     break;
00392   case 'b':
00393     IfLine += 1;
00394     if(IfLine == 2) IfLine =0;
00395     sprintf(Dr->info,"Bonding visualisation");
00396     DrawScene();
00397     glutPostRedisplay();
00398     break;
00399   case 'c':
00400     IfExt++;
00401     if(IfExt==0)
00402       sprintf(Dr->info,"Increasing radius");
00403     else if(IfExt==1)
00404       sprintf(Dr->info,"Increasing height");
00405     else if(IfExt==2)
00406       sprintf(Dr->info,"Increasing angle");
00407     else if(IfExt==3)
00408       sprintf(Dr->info,"D^4 term");
00409     else if(IfExt==4)
00410       sprintf(Dr->info,"D^2 term");
00411     else if(IfExt==5)
00412       sprintf(Dr->info,"Elastic term");
00413     else if(IfExt==6)
00414       sprintf(Dr->info,"Moving center ->x");
00415     else if(IfExt==7)
00416       sprintf(Dr->info,"Moving center ->z");
00417     else 
00418       IfExt = -1;
00419     break;
00420   case 'd':
00421     if(IfExt == 0){
00422       for(int n=0;n<pNNano();n++)
00423    Nano[n].Rad += StepDiameter;
00424       sprintf(Dr->info,"Nano->Rad %lf",Nano->Rad);
00425     }
00426     else if(IfExt == 1){
00427       for(int n=0;n<pNNano();n++)
00428    Nano[n].Height += StepDiameter;
00429       sprintf(Dr->info,"Nano->Height %lf",Nano->Height);
00430     }
00431     else if(IfExt == 2){
00432       for(int n=0;n<pNNano();n++)
00433    Nano[n].Hamaker += 5.;
00434       if(Nano->Hamaker >= 90.) Nano->Hamaker = 0.;
00435       sprintf(Dr->info,"ExtAngle %lf",Nano->Hamaker);
00436     }
00437     else if(IfExt == 3){
00438       Kf.SLap *= 10.;
00439       sprintf(Dr->info,"D^4 %lf ratio %lf",Kf.SLap,pow(Kf.SLap/Kf.El[2],.25));
00440     }
00441     else if(IfExt == 4){
00442       Kf.Lap += 1.;
00443       sprintf(Dr->info,"D^2 %lf",Kf.Lap);
00444     }
00445     else if(IfExt == 5){
00446       Kf.El[2] += 10.;
00447      sprintf(Dr->info,"elastic %lf ratio %lf",Kf.El[2],pow(Kf.SLap/Kf.El[2],.25));
00448     }
00449     else if(IfExt == 6){
00450       //for(int n=0;n<pNNano();n++)
00451    Nano[0].Pos[0] += StepDiameter;
00452       sprintf(Dr->info,"Nano->Pos x %lf",Nano->Pos[0]);
00453     }
00454     else if(IfExt == 7){
00455       for(int n=0;n<pNNano();n++)
00456    Nano[n].Pos[2] += StepDiameter;
00457       sprintf(Dr->info,"Nano->Pos z %lf",Nano->Pos[2]);
00458     }
00459     for(int n=0;n<pNNano();n++)
00460       Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height);
00461     AddRigid();
00462     IfFillMatrix = 1;
00463     glutPostRedisplay();
00464     break;
00465   case 'D':
00466     if(IfExt == 0){
00467       for(int n=0;n<pNNano();n++)
00468       Nano[n].Rad -= StepDiameter;
00469       sprintf(Dr->info,"Rad %lf",Nano->Rad);
00470     }
00471     else if(IfExt == 1){
00472       for(int n=0;n<pNNano();n++)
00473    Nano[n].Height -= StepDiameter;
00474       sprintf(Dr->info,"Height %lf",Nano->Height);
00475     }
00476     else if(IfExt == 2){
00477       if(Nano->Hamaker < 0.) Nano->Hamaker = 0.;
00478       Nano->Hamaker -= 5.;
00479       sprintf(Dr->info,"ExtAngle %lf",Nano->Hamaker);
00480     }
00481     else if(IfExt == 3){
00482       Kf.SLap /= 10.;
00483       sprintf(Dr->info,"D^4 %lf ratio %lf",Kf.SLap,pow(Kf.SLap/Kf.El[2],.25));
00484     }
00485     else if(IfExt == 4){
00486       Kf.Lap -= 1.;
00487       sprintf(Dr->info,"D^2 %lf",Kf.Lap);
00488     }
00489     else if(IfExt == 5){
00490       Kf.El[2] -= 10.;
00491       sprintf(Dr->info,"elastic %lf ratio %lf",Kf.El[2],pow(Kf.SLap/Kf.El[2],.25));
00492     }
00493     else if(IfExt == 6){
00494       //for(int n=0;n<pNNano();n++)
00495    Nano[0].Pos[0] -= StepDiameter;
00496       sprintf(Dr->info,"Nano->Pos x %lf",Nano->Pos[0]);
00497     }
00498     else if(IfExt == 7){
00499       for(int n=0;n<pNNano();n++)
00500    Nano[n].Pos[2] -= StepDiameter;
00501       sprintf(Dr->info,"Nano->Pos z %lf",Nano->Pos[2]);
00502     }
00503     for(int n=0;n<pNNano();n++)
00504       Cylinder[n] = Dr->DefCylinder(Nano[n].Rad,Nano[n].Height);
00505     AddRigid();
00506     IfFillMatrix = 1;
00507     glutPostRedisplay();
00508     break;
00509   case 'e':
00510     IfSpline=1;
00511     IfInterp++;
00512     if(IfInterp == 7)
00513       IfInterp = 0;
00514     Interp();
00515     //Dynamics();
00516     //printf("IfInterp %d\n",IfInterp);
00517     glutPostRedisplay();    
00518     break;
00519   case 'I':
00520     Info();
00521     break;
00522   case 'm':
00523     //Menu();
00524     Bead2Move++;
00525     if(Bead2Move > pNPart()) Bead2Move = 0;
00526     SelectBead(Bead2Move);
00527     sprintf(Dr->info,"Part2Move %d",Bead2Move);
00528     DrawScene();
00529     glutPostRedisplay();
00530     break;
00531   case 'M':
00532     Bead2Move--;
00533     if(Bead2Move < 0) Bead2Move = pNPart();
00534     SelectBead(Bead2Move);
00535     sprintf(Dr->info,"Part2Move %d",Bead2Move);
00536     DrawScene();
00537     glutPostRedisplay();
00538     break;
00539   case 'o':
00540     Dynamics();
00541     DrawScene();
00542     glutPostRedisplay();
00543     break;
00544   case 'O':
00545     InitTime = time(NULL);
00546     glutIdleFunc(DynamicsMotion);
00547     break;
00548   case 'r':
00549     glutIdleFunc(NULL);
00550     Dr->InitConstant();
00551     sprintf(Dr->info,"initial configuration");
00552     glutPostRedisplay();
00553     break;
00554   case 'R':
00555     ReadConfDinamica(ConfFile);
00556     IfFillMatrix = 1;
00557     FillMatrix();
00558     sprintf(Dr->info,"reload configuration");
00559     glutPostRedisplay();
00560     break;
00561   case 'S':
00562     Solve();
00563     DrawScene();
00564     glutPostRedisplay();
00565     break;
00566   case 't':
00567     PullBead();
00568     DrawScene();
00569     glutPostRedisplay();
00570     break;
00571   case 'T':
00572     PushBead();
00573     //sprintf(info,"Perspective view");
00574     DrawScene();
00575     glutPostRedisplay();
00576     break;
00577   case 'u':
00578     Dynamics();
00579     DrawScene();
00580     glutPostRedisplay();
00581     break;
00582   case 'v':
00583     BeadType++;
00584     Pm[Bead2Move].Typ = BeadType;
00585     if(BeadType >= 4)
00586       BeadType = 0;
00587     glutPostRedisplay();
00588     break;
00589   case 'V':
00590     Pm[Bead2Move].Typ = 0;
00591     glutPostRedisplay();
00592     break;
00593   case 'w':
00594     VAR_REM_TYPE(SysType,VAR_SYS_TXVL);
00595     VAR_ADD_TYPE(SysType,VAR_SYS_XVT);
00596     SysFormat = VAR_SYS_TXVL;
00597     SetNBlock(1);
00598     Block[0].NChain = pNChain();
00599     Block[0].InitIdx = 0;
00600     Block[0].NPCh = pNPCh();
00601     Block[0].EndIdx = pNPart();
00602     sprintf(Block[0].Name,"GAS");
00603     char FileName[60];
00604     sprintf(FileName,"Trajectory%09d.dat",pStep());
00605     Write(FileName);
00606     break;
00607   case 27:
00608     exit(0);
00609     break;
00610   case 40:
00611     break;
00612   default:
00613     break;
00614   }
00615   Dr->keyboardDraw(key);
00616 }
00617 int Forces::Interp(){
00618   if(!IfSpline) return 0;
00619   if(IfInterp==FIT_SPLINE3){
00620     NShow = InterSpline3(Pm,Pl,pNPart(),NSpline);
00621     sprintf(Dr->info,"Interpolating via Spline3 %d",NShow);
00622   }
00623   else if(IfInterp==FIT_SPLINE4){
00624     NShow = InterSpline4(Pm,Pl,pNPart(),NSpline);
00625     sprintf(Dr->info,"Interpolating via Spline4 %d",NShow);
00626   }
00627   else if(IfInterp==FIT_PARAB2){
00628     NShow = InterParab2(Pm,Pl,pNPart(),NSpline);
00629     sprintf(Dr->info,"Interpolating via Parabola2 %d",NShow);
00630   }
00631   else if(IfInterp==FIT_CUBIC){
00632     NShow = InterCubica(Pm,Pl,pNPart(),NSpline);
00633     sprintf(Dr->info,"Interpolating via Cubic %d",NShow);
00634   }
00635   else if(IfInterp==FIT_FORTH){
00636     NShow = InterForth(Pm,Pl,pNPart(),NSpline);
00637     sprintf(Dr->info,"Interpolating via Forth %d",NShow);
00638   }
00639   else if(IfInterp==FIT_BSPLINE){
00640     NShow = InterBSpline(Pm,Pl,pNPart(),NSpline);
00641     sprintf(Dr->info,"Interpolating via BSpline %d",NShow);
00642   }
00643   else if(IfInterp==FIT_POLY){
00644     NShow = InterPoly(Pm,Pl,pNPart(),NSpline);
00645     sprintf(Dr->info,"Interpolating via %dth grade poly %d",pNPart()-1,NShow);
00646   }
00647   return 0;
00648 }
00649 #endif //__glut_h__