//Alcys_ROuTE_De_Nuit version du 08/04/2004 //Interactivité: click==>speedX++ Systeme sys; void setup(){ size(700,500); sys=new Systeme(); ellipseMode(CENTER_DIAMETER); } void loop(){ background(45,45,155); push(); translate(1000,800,-400); rotateX(1.28); rotateZ(PI/2); sys.afficher(); pop(); } class Systeme{ Trajectoire trajet; float v,t; public Systeme(){ this.v=0.03; this.t=0; float rr=1500; trajet=new Trajectoire(rr); } void afficher(){ if (mousePressed == true) { trajet.balle.vitesse.x+=-20; }; trajet.dessinerlaroute(); } } class Trajectoire{ float rayon,alfa,beta,t; Mobile balle; Vecteur c,v; public Trajectoire(float rayon){ this.rayon=rayon; this.alfa=0; this.beta=0; this.t=0; c=new Vecteur(800,700,0); v=new Vecteur(-80,20,0); this.balle=new Mobile(c,v); } Vecteur route(float tt){ Vecteur p=new Vecteur(0,0,0); p.x=tt*2000; p.y=rayon/3*sin(tt*2); p.z=0; return p; } Vecteur routeT(float tt){ Vecteur p=new Vecteur(0,0,0); p.x=2000.0f; p.y=rayon/3*2*cos(tt*2); p.z=0; p.normer(); return p; } Vecteur routeN(float tt){ Vecteur p=new Vecteur(0,0,0); p.x=0; p.y=-rayon/3*4*sin(tt*2); p.z=0; p.normer(); return p; } void repere(){ stroke(255,0,0);line(0,0,0,1000,0,0); stroke(0,255,0);line(0,0,0,0,1000,0); stroke(0,0,255);line(0,0,0,0,0,1000);} void dessinerlaroute(){ t+=((balle.coords.x+600)/2000-t)/10;//la pendule Vecteur pabs=route(t);//la nouvelle position de la camera dans le repère absolu Vecteur vuabs=routeT(t); Vecteur nabs=routeN(t); Vecteur angles=vuabs.anguler(nabs);//les angles du repere contenant dans x0y n et t Vecteur ancp0=route(t);//init des vecteurs Vecteur ancp=(ancp0.soustraire(pabs)).coordonner(angles); for(float i=t;i>t-6.28;i-=0.03){ Vecteur p=route(i);Vecteur resp=p.soustraire(pabs); Vecteur nouvp=resp.coordonner(angles); noStroke(); beginShape(QUAD_STRIP); fill(0,250,0); vertex(nouvp.x,nouvp.y,nouvp.z); vertex(ancp.x,ancp.y,ancp.z); fill(155,50,255); vertex(ancp.x,ancp.y+1500,ancp.z); vertex(nouvp.x,nouvp.y+1500,nouvp.z); endShape(); beginShape(QUAD_STRIP); fill(255,250,55); vertex(ancp.x,ancp.y+1500,ancp.z+30); vertex(nouvp.x,nouvp.y+1500,nouvp.z+30);fill(25,115,0); vertex(nouvp.x,nouvp.y+1800,nouvp.z+30); vertex(ancp.x,ancp.y+1800,ancp.z+30); endShape(); beginShape(QUAD_STRIP); fill(55,250,155); vertex(ancp.x,ancp.y+1800,ancp.z+30); vertex(nouvp.x,nouvp.y+1800,nouvp.z+30); vertex(nouvp.x,nouvp.y+1800,nouvp.z+300);fill(25,115,0); vertex(ancp.x,ancp.y+1800,ancp.z+300); endShape(); beginShape(QUAD_STRIP); fill(255,255,0); vertex(ancp.x,ancp.y,ancp.z+30); vertex(nouvp.x,nouvp.y,nouvp.z+30);fill(25,115,0); vertex(nouvp.x,nouvp.y-300,nouvp.z+30); vertex(ancp.x,ancp.y-300,ancp.z+30);endShape(); beginShape(QUAD_STRIP); fill(155,155,0); vertex(ancp.x,ancp.y-300,ancp.z+30); vertex(nouvp.x,nouvp.y-300,nouvp.z+30); vertex(nouvp.x,nouvp.y-300,nouvp.z+330);fill(25,515,0); vertex(ancp.x,ancp.y-300,ancp.z+330);endShape(); ancp=nouvp; } // int t0=(int)t; fill(200,200,255); for(int i=t0;i>t-6.28;i--){ Vecteur rout0=route(i);Vecteur resp=rout0.soustraire(pabs); Vecteur rout=resp.coordonner(angles); push(); translate(rout.x,rout.y-200,rout.z+400);println(rout.x); if(rout.x<0){ fill(200,200,255);box(30,30,800); translate(0,0,400); fill(255,255,0); push();rotateY(PI/2);ellipse(-70,0,100,100);fill(255,255,0,80);ellipse(-70,0,280,280);pop(); fill(255,255,0,80);push(); translate(0,400,-700);ellipse(0,0,800,800);pop(); fill(200,200,255);translate(0,1900,-400);box(30,30,800); translate(0,0,400); fill(255,255,0); push();rotateY(PI/2);ellipse(-70,0,140,140);fill(255,255,0,80);ellipse(-70,0,280,280);pop(); fill(255,255,0,80); translate(0,-400,-700);ellipse(0,0,800,800);} pop(); } // Vecteur posballe=route(balle.coords.x/2000); balle.dessinerlaballe(t,pabs,angles,route(balle.coords.x/2000),routeT(balle.coords.x/2000),routeN(balle.coords.x/2000)); } } class Vecteur{ float x,y,z; Vecteur(float x1,float y1,float z1){ this.x=x1; this.y=y1; this.z=z1; } Vecteur normer(){ float lg=dist(0,0,0,x,y,z); Vecteur prov; if(lg==0){prov=new Vecteur(0,0,0);}else { prov=new Vecteur( x/=lg,y/=lg, z/=lg);} return prov; } Vecteur produitvectoriel(Vecteur w){ Vecteur p=new Vecteur(0,0,0); p.x=y*w.z-w.y*z; p.y=z*w.x-w.z*x; p.z=x*w.y-w.x*y; return p; } float produitscalaire(Vecteur w){ float ps=x*w.x+y*w.y+z*w.z; return ps; } Vecteur anguler(Vecteur vv){ float alfa=atan2(y,x); float beta=atan2(z,dist(0,0,x,y)); return (new Vecteur(0,-beta,alfa)); } void xRotation(float a){ float yt=y*cos(a)-z*sin(a); z=y*sin(a)+z*cos(a); y=yt;} void yRotation(float a){ float zt=z*cos(a)-x*sin(a); x=z*sin(a)+x*cos(a); z=zt;} void zRotation(float a){ float xt=x*cos(a)-y*sin(a); y=x*sin(a)+y*cos(a); x=xt;} Vecteur soustraire(Vecteur d){ Vecteur dif=new Vecteur(x-d.x,y-d.y,z-d.z); return dif;} Vecteur coordonner(Vecteur a){ Vecteur res=new Vecteur(x,y,z); res.zRotation(-a.z); res.yRotation(-a.y); res.xRotation(-a.x); return res; } } class Mobile{ Vecteur coords ,vitesse; Mobile(Vecteur c,Vecteur v){ this.coords=c; this.vitesse=v; } void dessinerlaballe(float time,Vecteur posrepere,Vecteur angls,Vecteur posbords,Vecteur tang,Vecteur norm){ //calculs dans le repere absolu:choc avec les bords float lim=posbords.y; if(coords.ylim+1450){modifiervitesse(tang,norm);coords.y=lim+1450;}; coords.y+=vitesse.y; coords.x+=vitesse.x; //dessin dans le repere relatif Vecteur acp=(coords.soustraire(posrepere)).coordonner(angls); beginShape(QUAD_STRIP); fill(255,255,255); vertex(acp.x-50,acp.y-50,acp.z+3); vertex(acp.x-50,acp.y+50,acp.z+3); vertex(acp.x+50,acp.y+50,acp.z+3); vertex(acp.x+50,acp.y-50,acp.z+3); ;endShape(); } void modifiervitesse(Vecteur ta,Vecteur no){ Vecteur nta=ta.normer(); Vecteur nno=no.normer(); float vta=vitesse.produitscalaire(nta); float vno=vitesse.produitscalaire(nno); vitesse.x=vta*nta.x-vno*nno.x; vitesse.y=vta*nta.y-vno*nno.y; } }