BImage acc; float tempo=0,haut ,rayon,angly=0,anglx=0; float large2=140,w,h; Bille balle,balle1; Barre bar; void setup(){ size(600,300); rectMode(CENTER_DIAMETER); background(0); haut=350; rayon=80; acc= new BImage(); acc=loadImage("acc.jpg"); w=acc.width;h=acc.height; ellipseMode(CENTER_DIAMETER); balle=new Bille(0,320,rayon); balle1=new Bille(800,320,rayon); bar=new Barre(-200,50,haut,rayon); } void loop(){ tempo+=0.01f; clear(); push(); translate(width/2,-100, -750); angly=(-mouseX+width/2)*0.01f; anglx=(-mouseY+height/2)*0.001f; rotateX(anglx); rotateY(angly); //afficherRepere(); push(); fill(255,215,180); translate(150,425,0); box(1340,50,900); pop(); push(); fill(155); translate(0,700,0); box(250,500,250); pop(); balle.dessiner(); balle1.dessiner(); if(bar.disdroite(balle.x,balle.y,bar.angle)xmin && y==320) {x+=vx;} else{ if (x<=xmin && y<700){ vy+=-30; y+=-vy; x+=vx; } else{ x=xmax;y=320;vy=0; } } if(xasortie) angle-=PI/2; if(disdroite(b.x,b.y,angle)>b.r ) {angle+=(PI/2-angle)/100; } else{ b.enContact=true;} } if(b.enContact){ float ang=PI-(float)Math.asin((b.y-b.r-y)/haut);; if(distance(b)=b.r); angle=ang; }else{ if(distance(b)b.r*b.r); angle=ang; }else{b.enContact=false;} } } } } // ------------------------------------------------------- static class Vecteur { public float x, y, z; public Vecteur() { } public Vecteur(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } public Vecteur(float x, float y, float z,float lon) { float no=(float) Math.sqrt(x * x + y * y + z * z); no=lon/no; this.x = x*no; this.y = y*no; this.z = z*no; } public void place(float xx, float yy, float zz) { this.x = xx; this.y = yy; this.z = zz; } public Vecteur normalize() { float length = length(); x /= length; y /= length; z /= length; return this; } public Vecteur normalize(float k) { float length = length(); x=x/ length*k; y =y/ length*k; z =z/ length*k; return this; } public float length() { return (float) Math.sqrt(x * x + y * y + z * z); } public Vecteur cross(Vecteur v2) { Vecteur res = new Vecteur(); res.x = y * v2.z - z * v2.y; res.y =z * v2.x - x * v2.z; res.z = x * v2.y - y * v2.x; return res; } public static float dot(Vecteur v1, Vecteur v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } public float dot(Vecteur v1) { return v1.x * x + v1.y *y + v1.z *z; } public Vecteur mul( float d) { Vecteur res = new Vecteur(); res.x =x * d; res.y = y * d; res.z = z * d; return res; } public static Vecteur comb(float a,Vecteur v1,float b, Vecteur v2) { float rx =a* v1.x + b*v2.x; float ry =a* v1.y + b*v2.y; float rz =a* v1.z + b*v2.z; return new Vecteur(rx,ry,rz); } public static Vecteur barycentre(float a,Vecteur v1,float b, Vecteur v2) { Vecteur res=comb(a,v1,b,v2); res=res.mul(1/(a+b)); return res; } public Vecteur ajouter(Vecteur v,float m){ Vecteur res=new Vecteur(x+v.x*m, y+v.y*m,z+v.z*m); return res; } public Vecteur ajouter(float ax,float ay,float az){ Vecteur res=new Vecteur(x+ax, y+ay,z+az); return res; } public void afficher(String tex,BApplet ba){ ba.println(tex+"x= "+x+" y= "+y+" z= "+z); } public Vecteur projete(Vecteur laxe){ laxe.normalize(); Vecteur res=laxe.mul(this.dot(laxe)); return res; } public Vecteur projeteSurAxe(Vecteur laxe){ laxe.normalize(); Vecteur res=laxe.mul(this.dot(laxe)); return res; } public Vecteur projeteSurPlan(Vecteur laxe){ laxe.normalize(); Vecteur res=projeteSurAxe(laxe); res=this.ajouter(res,-1); return res; } public Vecteur symetrique(Vecteur laxe){ laxe.normalize(); Vecteur res=projeteSurAxe(laxe); res=this.ajouter(res,-2.0f); return res; } public float distancePointDroite(Vecteur d, Vecteur v){ v.normalize(); Vecteur pd=d.ajouter(this,-1); Vecteur hd=v.mul(v.dot(pd)); Vecteur ph=pd.ajouter(hd,-1); return ph.length(); } public float donneAngle(Vecteur vc){ return (float) Math.acos(this.dot(vc)/(length()*vc.length())); } public Vecteur tourner(Vecteur axe,float angle){//axe est normé et orthogonal à this Vecteur vaxe=axe.mul(this.dot(axe)); Vecteur vx=this.ajouter(vaxe,-1); Vecteur ygrec=axe.cross(this); return vaxe.ajouter(Vecteur.comb((float)Math.cos(angle),this,(float)Math.sin(angle),ygrec),1); } public Vecteur cloner() { Vecteur res = new Vecteur(); res.x =x ; res.y = y ; res.z = z ; return res; } public Vecteur coorabs(BApplet ba) { float xa = ba.objectX(x,y,z); float ya = ba.objectY(x,y,z); float za = ba.objectZ(x,y,z); return new Vecteur(xa, ya, za); } // ******************************************* // ******************************************* // ******************************************* public static void afficherRepere(BApplet ba,float lon){ ba.stroke(255,0,0); ba.line(0,0,0,lon,0,0); ba.stroke(0,255,0); ba.line(0,0,0,0,lon,0); ba.stroke(0,0,255); ba.line(0,0,0,0,0,lon); } public static void afficherRepere(BApplet ba){ ba.stroke(255,0,0); ba.line(0,0,0,500,0,0); ba.stroke(0,255,0); ba.line(0,0,0,0,500,0); ba.stroke(0,0,255); ba.line(0,0,0,0,0,500); } // ******************************************* // ******************************************* // ******************************************* public void afficherLigne(float k,BApplet ba){ ba.line(x*k,y*k,z*k,-x*k,-y*k,-z*k); } }