/*Alcys_Billard * 1) clic droit et drag: change le point de vue * 2) selectionner la boule: * clic gauche et drag : déplace le sélecteur juste au dessus de la boule qui sera jouée. Puis faire: * touche 'p' : selectionne la bille qui est à une distance inférieure à un rayon du sélecteur * 3) armer le tir * clic gauche et drag : déplacer la queue de billard et lui donner sa force et sa direction * 4) tirer * clic relaché : declanche le coup * 1)to move the camera :click and drag right * 2)to select the ball * :click and drag left :to move the selector right with the top of the ball * press the space key * 3)to arm the shooting * click and drag left :to move the billiard cue and to give him its force and its direction * 4)to draw: to release the left button * **/ Camera cam; float theta,phi,distanceEcranOeil,rayon,dx,dy; Quat lequat; Vecteur camX,camY,camZ,camX0,camY0,camZ0,vectOriginMouse,vectEyeMouse,vectImpact ; int doInverse; PFont mafont; LeJeu billesys; void setup(){ size(800,600,P3D); distanceEcranOeil=height/(2*(float)Math.tan(PI/6)); theta=1.0f; phi=1.0f; doInverse=1; lequat=new Quat(1,0,0,0); camZ0=new Vecteur(0,0,-1); camY0=new Vecteur(0,1,0); camX0=new Vecteur(-1,0,0); Quat lequa=Quat.mul(new Quat(cos(-0.65),sin(-0.65),0,0),lequat); camZ0=lequa.tourner(camZ0); camY0=lequa.tourner(camY0); camX0=lequa.tourner(camX0); camZ=camZ0.cloner(); camY=camY0.cloner(); camX=camX0.cloner(); cam=new Camera(camX0,camY0,camZ0); vectOriginMouse=new Vecteur(0,0,0); vectImpact=new Vecteur(0,0,0); mafont=loadFont("Arial.vlw"); textFont(mafont,20); rayon=15;//rayon des billes dx=280;//largeur du billard dy=430;//longueur du billard billesys=new LeJeu(); } void draw(){ background(0,30,80); cam.placercamera(); damier(); billesys.dessiner(); pointeur(); //repere(); } void repere(){ stroke(255 ,0 , 0); line(0,0,0,100,0,0); stroke(0 ,255 ,0 ); line(0,0,0,0,100,0); stroke(0 ,0 ,255 ); line(0,0,0,0,0,100); } Vecteur absolu(float x,float y,float z){ float xx=modelX(x,y,z); float yy=modelY(x,y,z); float zz=modelZ(x,y,z); return new Vecteur(xx,yy,zz); } void keyPressed(){ if(key==' ')billesys.CalculerLeBilleMobile(); if(key=='r')billesys.mobile=-1; } void mouseReleased(){ if(billesys.mobile>-1){ ( billesys.billes[billesys.mobile]).attraction=true; (billesys.billes[billesys.mobile]).vit=billesys.billes[billesys.mobile].pos.ajouter(vectImpact,-1); if((billesys.billes[billesys.mobile]).vit.length()>250)(billesys.billes[billesys.mobile]).vit.normalize(250); billesys.mobile=-1 ;//le pion n'est plus sous contrainte } } void mouseDragged(){ if(mouseButton==RIGHT){//Déplacer la caméra en calculant son nouveau repere //theta=(mouseY-pmouseY)/200.0f; phi=(mouseX-pmouseX)/200.0f; //lequat=Quat.mul(new Quat(cos(theta/2),sin(theta/2),0,0),lequat); lequat=Quat.mul(new Quat(cos(phi/2),0,0,sin(phi/2)),lequat); camZ=lequat.tourner(camZ0); camY=lequat.tourner(camY0); camX=lequat.tourner(camX0); } if(mouseButton==LEFT){//déplacer le sélecteur en calculant le vecteur vectImpact vectEyeMouse=camZ.mul(distanceEcranOeil).ajouter(camY,mouseY-height/2). ajouter(camX,-mouseX+width/2); vectOriginMouse=cam.oeil.ajouter(vectEyeMouse,1); intersectionRayonPlanXY(); } } public void intersectionRayonPlanXY(){ if(vectEyeMouse.z!=0){ float lambda=(rayon-cam.oeil.z)/vectEyeMouse.z; vectImpact=cam.oeil.ajouter(vectEyeMouse,lambda); vectImpact.z=0; } } public void pointeur(){ //dessiner le pointeur au point d'impact pushMatrix(); translate(vectImpact.x,vectImpact.y,rayon); fill(185,255,205); noStroke(); beginShape(TRIANGLES); for(int i=0;i<=12;i++){ float a1=PI/6*i,a2=PI/6*(i+1); vertex(0,0,0); vertex(10*cos(a1),10*sin(a1),rayon); vertex(10*cos(a2),10*sin(a2),rayon); } endShape(); beginShape(TRIANGLE_STRIP); for(int i=0;i<=12;i++){ float a1=PI/6*i; if(i%2==0){ vertex(4*cos(a1),4*sin(a1),rayon/2); vertex(4*cos(a1),4*sin(a1),rayon*4); } } endShape(); popMatrix(); } void damier(){ noStroke(); float dxr=dx+rayon; float dyr=dy+rayon; float dxd=dx+2*rayon; float dyd=dy+2*rayon; rect(-dx,-dy,2*dx,2*dy); beginShape(QUADS); fill(10,140,25); vertex(-dx,-dy,0); fill(20,95,35); vertex(dx,-dy,0); fill(0,135,15); vertex(dx,dy,0); fill(10,90,25); vertex(-dx,dy,0); vertex(-dxr,-dyr,0); vertex(-dx,-dy,rayon); vertex(dx,-dy,rayon); vertex(dxr,-dyr,0); vertex(-dxr,dyr,0); vertex(-dx,dy,rayon); vertex(dx,dy,rayon); vertex(dxr,dyr,0); vertex(-dxr,-dyr,0); vertex(-dx,-dy,rayon); vertex(-dx,dy,rayon); vertex(-dxr,dyr,0); vertex(dxr,-dyr,0); vertex(dx,-dy,rayon); vertex(dx,dy,rayon); vertex(dxr,dyr,0); fill(10,130,25); vertex(-dxd,-dyd,rayon); vertex(-dx,-dy,rayon); vertex(dx,-dy,rayon); fill(20,95,35); vertex(dxd,-dyd,rayon); fill(10,110,25); vertex(-dxd,dyd,rayon); vertex(-dx,dy,rayon); vertex(dx,dy,rayon); fill(20,95,35); vertex(dxd,dyd,rayon); fill(10,120,25); vertex(-dxd,-dyd,rayon); vertex(-dx,-dy,rayon); vertex(-dx,dy,rayon); fill(20,95,35); vertex(-dxd,dyd,rayon); fill(10,110,25); vertex(dxd,-dyd,rayon); vertex(dx,-dy,rayon); vertex(dx,dy,rayon); fill(20,95,35); vertex(dxd,dyd,rayon); endShape(); }