import saito.objloader.*; // OBJLoader de SAITO doit être placé dans le dossier "libraries" //le modèle mannequin.obj provient de : http://www.cis.uab.edu/info/grads/hux/Data/obj.html Camera cam; float theta,phi,distanceEcranOeil,cote; Vecteur vectOriginMouse,vectEyeMouse,vectImpact,vectImpact0 ; LesVertex lesSommets; Pointeur3D pointeur; void setup(){ size(800,600,P3D); distanceEcranOeil=height/(2*(float)Math.tan(PI/6)); theta=1.0f; phi=1.0f; cote=40; cam=new Camera(); vectOriginMouse=new Vecteur(0,0,0); vectImpact=new Vecteur(200,-200,cote); lesSommets=new LesVertex(this); pointeur=new Pointeur3D(30.0f); } void draw(){ background(100,100,130); cam.placercamera(); damier(); repere(); lesSommets.dessiner(); pointeur.dessiner(); } void repere(){ stroke(255 ,0 , 0); line(0,0,0,1,0,0); stroke(0 ,255 ,0 ); line(0,0,0,0,1,0); stroke(0 ,0 ,255 ); line(0,0,0,0,0,1); } 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=='a')lesSommets.doAnim*=-1; if(keyCode==UP ||key=='q')cote=cote+1; if(keyCode==DOWN || key=='w')cote=cote-1; vectImpact.z=cote; if(key=='i')pointeur.doInverse*=-1; if(key=='p'){ if(lesSommets.indicesMobiles.size()==0) { Vecteur cb=new Vecteur(vectImpact.x,vectImpact.y,vectImpact.z-pointeur.rayonSphere); lesSommets.calculerLesVertexMobiles(cb,pointeur.rayonSphere); vectImpact0=vectImpact.cloner(); } else { lesSommets.indicesMobiles.removeAllElements(); } } if(key=='r')lesSommets.indicesMobiles.removeAllElements(); if(key=='o')lesSommets.doOpaque=405-lesSommets.doOpaque; if(key=='+')pointeur.rayonSphere+=1; if(key=='-')pointeur.rayonSphere-=1; } void mousePressed(){ cam.arcball.mousePress(); } void mouseDragged(){ if(mouseButton==LEFT){//Déplacer la caméra en calculant son nouveau repere cam.arcball.mouseDrag(); } if(mouseButton==RIGHT){//déplacer le sélecteuren calculant le vecteur vectImpact vectEyeMouse=cam.camZ.mul(distanceEcranOeil).ajouter(cam.camY,mouseY-height/2). ajouter(cam.camX,-mouseX+width/2); vectOriginMouse=cam.oeil.ajouter(vectEyeMouse,1); intersectionRayonPlanXY(); } } public void intersectionRayonPlanXY(){ if(vectEyeMouse.z!=0){ float lambda=(cote-cam.oeil.z)/vectEyeMouse.z; vectImpact=cam.oeil.ajouter(vectEyeMouse,lambda); } } void damier(){ noStroke(); pushMatrix(); translate(0,0,-130); int coul=200; for(int li=-5;li<5;li++){ coul=290-coul; for(int co=-5;co<5;co++){ coul=290-coul; fill(coul,40); rect(co*50f-25f,li*50f-25f,50f,50f); } } popMatrix(); }