//___________________________________________ //ALCYS_CHOC_3D3 version du 28/04/2004 //___________________________________________ Systeme sys; float anglx,angly; Vecteur gabs; void setup(){ size(700,500); background(105,120,150); ellipseMode(CENTER_DIAMETER); rectMode(CENTER_DIAMETER); anglx=0; angly=0; gabs=new Vecteur(0,1000,0); sys=new Systeme(15); } void loop(){ clear(); angly += (float)(width/2-mouseX)/1000-angly*0.1; anglx += (float)(height/2-mouseY)/1000-anglx*0.1; //calcul de la gravite dans le repere de la boite push(); rotateX(-anglx); rotateY(-angly); Vecteur gbox=gabs.composantesAbs(); pop(); push();//stocker le contexte absolu translate(200,200,-1100); rotateY(angly); rotateX(anglx); sys.controleChocs(gbox); sys.montreBox(); pop();//on revient dans le repere absolu sys.montreBalles(); } //____________________________________ //CLASSE SYSTEME //____________________________________ class Systeme { int nb; Balle[] table; Vecteur[] coorda; Systeme(int nb) { this.nb=nb; this.table = new Balle[nb]; this.coorda=new Vecteur[nb]; for(int i=0;i400-r) { pos.x = 400-r; vit.x *= -1; } if (pos.x<-400+r) { pos.x = -400+r; vit.x *= -1; } if (pos.y>400-r) { pos.y = 400-r; vit.y *= -1; } if (pos.y<-400+r) { pos.y = -400+r; vit.y *= -1; } if (pos.z>500-r) { pos.z = 500-r; vit.z *= -1; } if (pos.z<-500+r) { pos.z = -500+r; vit.z *= -1; } } } //____________________________________ //CLASSE VECTEUR //____________________________________ class Vecteur{ float x,y,z; public Vecteur(float x1,float y1,float z1){ this.x=x1; this.y=y1; this.z=z1; } public Vecteur(){ x=0; y=0; z=0;} void normer(){ float lg=(float) Math.sqrt(x*x+y*y+z*z); if(lg!=0) { x/=lg; y/=lg; z/=lg;} } Vecteur anguler(){ float alfa=(float) Math.atan2(y,x); float beta=(float) Math.atan2(z,Math.sqrt(x*x+y*y)); return (new Vecteur(0,beta,alfa)); } float produitscalaire(Vecteur v){ return x*v.x+y*v.y+z*v.z;} 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 distance(Vecteur v){ float dis=ajouter(v,-1).longueur(); return dis; } float longueur(){ return dist(0,0,0,x,y,z);} void multiplier(float m){ x*=m;y*=m;z*=m; } Vecteur ajouter(Vecteur v,float m){ Vecteur res=new Vecteur(x+v.x*m, y+v.y*m,z+v.z*m); return res; } Vecteur composantesAbs(){ float xx=objectX(x,y,z); float yy=objectY(x,y,z); float zz=objectZ(x,y,z); return new Vecteur(xx,yy,zz); } }