float angleY, angleX, rx, ry, phi, psi, theta, temps, tempo, inct; Vecteur uu, vv, ww, ss, inter1, inter2,inter3,inter4, ww1; BFont metaBold; BFont futura; Quat qu, qv, qvuc, qqi, qvut, qs, qsvu,qsv,qf2; boolean auto; Tirette barreU,barreV,barreS; // ------------------------------------------------------- public void setup() { auto = false; metaBold = loadFont("Meta-Bold.vlw.gz"); futura = loadFont("Futura-Light.vlw.gz"); barreU=new Tirette(70,250,60,0.5f,2.5f,"angle de qU",235, 20,metaBold,this); barreV=new Tirette(70,300,60,0.5f,2.5f,"angle de qV",235, 20,metaBold,this); barreS=new Tirette(70,350,60,0.5f,2.5f,"angle de qS",235, 20,metaBold,this); size(750, 500); background(0); angleX = 0; rx = 0; angleY = 0; ry = 0; phi = 1.05f;barreU.setValeur(phi); //mesure en rd du1/2angle de la premiere rotation psi = 1.5f;barreV.setValeur(psi); //mesure en rd du 1/2angle de la deuxieme rotation theta = 1.25f;barreS.setValeur(theta); //mesure en rd du 1/2angle de la deuxieme rotation uu = new Vecteur(-3.0f, 2.0f, 5.5f).normalize(); vv = new Vecteur(-2.0f, 3.0f, 2.75f).normalize(); ss = new Vecteur(3.0f, 4.0f, 1.5f).normalize(); tempo = 0.3f; inct = 0.01f; } // ------------------------------------------------------- public void loop() { qu = new Quat(cos(phi), uu.mul(sin(phi))); qv = new Quat(cos(psi), uu.mul(sin(psi))); qs = new Quat(cos(theta), uu.mul(sin(theta))); if(mouseX>200 && mousePressed){ angleY = (mouseX -170- width * 0.5f) / 150.0f; angleX = - (mouseY - height * 0.5f) / 150.0f; } if (tempo > 1 || tempo < 0) { inct *= -1; } tempo += inct; if (auto) { temps += 0.02; if (temps > TWO_PI) temps = 0; vv.y =1.5f+ 2.0f*cos(3.0f* temps)*cos(temps); vv.z =1.0f+ 2.0f* cos(3.0f* temps)*sin(temps); vv.x = 1.0f - 1.3f * cos(3.0f * temps); } clear(); fill(120); rect(0,0,150,500); push(); afficherplans(); pop(); barreU.actualiser(); phi=barreU.getValeur(); barreV.actualiser(); psi=barreV.getValeur(); barreS.actualiser(); theta=barreS.getValeur(); } // ------------------------------------------------------- public void keyPressed() { if (key == 'a') { auto = !auto; }; if (!auto) { if (key == UP) { vv.x += 0.01; }; if (key == DOWN) { vv.x -= 0.01; }; if (key == RIGHT) { vv.z += 0.01; }; if (key == LEFT) { vv.z -= 0.01; }; } } // ------------------------------------------------------- void afficherL(String s, Vecteur v) { textFont(metaBold, 500); fill(255); push(); translate(v.x, v.y, v.z); text(s, 0, 0); pop(); } void afficherF(String s, Vecteur v) { textFont(futura, 400); fill(255,255,100); push(); translate(v.x, v.y, v.z); text(s, 0, 0); pop(); } // ------------------------------------------------------- void afficherplans() { vv.normalize(); qv = new Quat(cos(psi), vv.mul(sin(psi))); qvuc = Quat.mul(qv, qu); inter1 = new Vecteur(qvuc.x, qvuc.y, qvuc.z); qsvu = Quat.mul(qs, qvuc); inter2 = new Vecteur(qsvu.x, qsvu.y, qsvu.z); qsv = Quat.mul(qs, qv); inter3 = new Vecteur(qsv.x, qsv.y, qsv.z); qf2 = Quat.mul(qsv, qu); inter4 = new Vecteur(qf2.x, qf2.y, qf2.z); push(); translate(1400, 500, -9800); ry += (angleY - ry) / 10; rx += (angleX - rx) / 10; rotateY(ry + PI / 5); rotateX(rx + PI / 5); afficherPlan(uu, vv, 250, 50, 0); // afficherPlan(uu, inter1, 250, 50, 0); // afficherPlan(vv, inter1, 250, 50, 50); afficherPlan(ss, inter1, 150, 250, 0); afficherPlan(ss, inter2, 150, 250, 0); afficherPlan(inter1, inter2, 150, 250, 50); // afficherPlan(ss,vv, 0, 205, 250); // afficherPlan(inter3,vv, 0, 205, 250); // afficherPlan(inter3,ss, 50, 205, 250); // afficherPlan(inter3,uu, 30, 60, 255); // afficherPlan(inter4,uu, 30, 60, 255); // afficherPlan(inter4,inter3, 0, 0, 255); // Vecteur origine = coorabs(new Vecteur(0, 0, -400)); Vecteur uuu = coorabs(uu.mul(5000)); Vecteur vvv = coorabs(vv.mul(5000)); Vecteur sss = coorabs(ss.mul(5000)); Vecteur inter1abs = coorabs(inter1.mul(5000)); Vecteur inter2abs = coorabs(inter2.mul(5000)); Vecteur inter3abs = coorabs(inter3.mul(5000)); Vecteur inter4abs = coorabs(inter4.mul(5000)); Vecteur s1=coorabs(Vecteur.comb(2500,uu,2500,vv)); Vecteur s2=coorabs(Vecteur.comb(2500,uu,2500,inter1)); Vecteur s3=coorabs(Vecteur.comb(2500,vv,2500,inter1)); Vecteur s4=coorabs(Vecteur.comb(2500,inter1,2500,inter2)); Vecteur s5=coorabs(Vecteur.comb(2500,inter1,2500,ss)); Vecteur s6=coorabs(Vecteur.comb(2500,ss,2500,inter2)); Vecteur s7=coorabs(Vecteur.comb(2500,inter3,2500,vv)); Vecteur s8=coorabs(Vecteur.comb(2500,ss,2500,vv)); Vecteur s9=coorabs(Vecteur.comb(2500,ss,2500,inter3)); Vecteur s10=coorabs(Vecteur.comb(2500,inter4,2500,inter3)); Vecteur s11=coorabs(Vecteur.comb(2500,inter4,2500,uu)); Vecteur s12=coorabs(Vecteur.comb(2500,uu,2500,inter3)); pop(); afficherL("V", vvv); afficherL("U", uuu); afficherL("S", sss); afficherL("VoU", inter1abs); afficherL("O", origine); afficherL("SoVoU", inter2abs); afficherL("SoV", inter3abs); afficherL("SoVoU", inter4abs); afficherF("r1",s1); afficherF("r2",s2); afficherF("r3",s3); afficherF("r4",s4); afficherF("r5",s5); afficherF("r6",s6); afficherF("r7",s7); afficherF("r8",s8); afficherF("r9",s9); afficherF("r10",s10); afficherF("r11",s11); afficherF("r12",s12); } // ---------------------------------------------- void appliqueQuat(Quat q) { float[] a = q.getValue(); rotate(a[0], a[1], a[2], a[3]); } // ----------------------------------------------- Vecteur coorabs(Vecteur v) { float xa = objectX(v.x, v.y, v.z); float ya = objectY(v.x, v.y, v.z); float za = objectZ(v.x, v.y, v.z); return new Vecteur(xa, ya, za); } // ------------------------------------------------- void afficherAxe(Vecteur v, float d) { v.normalize(); line(0, 0, 0, v.x * d, v.y * d, v.z * d); } // -------------------------------------------------- void afficherPlan(Vecteur a,Vecteur b,float coul1,float coul2,float coul3) { float d = 5000; a.normalize(); b.normalize(); noStroke(); Vecteur ba=Vecteur.comb(1,a,-1,b).normalize(); Vecteur ea=Vecteur.comb(d,a,500,ba); Vecteur eb=Vecteur.comb(d, b,-500,ba); beginShape(TRIANGLES); fill(coul1, coul2, coul3); vertex(eb.x , eb.y , eb.z); vertex(ea.x, ea.y , ea.z ); fill(Math.round(coul1 / 3.7),Math.round(coul2 / 3.7),Math.round(coul3 / 3.7)); vertex(0,0,0); endShape(); afficherCercle(a,b,coul1,coul2,coul3); } //------------------------------------------------------- void afficherCercle(Vecteur q,Vecteur p,float coul1,float coul2,float coul3){ Vecteur c=q.cross(p); push(); stroke( coul1,coul2,coul3);noFill(); ellipseMode(CENTER_DIAMETER); translate(c.x,c.y,c.z); rotateZ(atan2(c.y,c.x)); rotateY(atan2(sqrt(c.x*c.x+c.y*c.y),c.z)); ellipse(0, 0, 10000, 10000); pop(); } //------------------------------------------------------- /* * * * * */ static class Quat { float w, x, y, z; Quat() { reset(); } Quat(float w, float x, float y, float z) { this.w = w; this.x = x; this.y = y; this.z = z; } Quat(float w, Vecteur v) { this.w = w; this.x = v.x; this.y = v.y; this.z = v.z; } Quat(Quat q) { set(q); } void reset() { w = 1.0f; x = 0.0f; y = 0.0f; z = 0.0f; } void set(float w, Vecteur v) { this.w = w; x = v.x; y = v.y; z = v.z; } void set(Quat q) { w = q.w; x = q.x; y = q.y; z = q.z; } void normalize() { float square = x * x + y * y + z * z + w * w; float dist = (square > 0.0f) ? (1.0f / (float) Math.sqrt(square)) : 1.0f; x *= dist; y *= dist; z *= dist; w *= dist; } static Quat mul(Quat q1, Quat q2) { Quat res = new Quat(); res.w = q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z; res.x = q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y; res.y = q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z; res.z = q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x; return res; } float getAngle(){ float[] tab=getValue(); float angle=(float)Math.acos(tab[0]); if(tab[1]<0)angle*=-1; return angle*180/(float)Math.PI; } float[] getValue() { normalize(); float[] res = new float[5]; float sa = (float) Math.sqrt(x * x + y * y + z * z); if (sa > 0.0000001) { res[0] = w; res[1] = sa; res[2] = x / sa; res[3] = y / sa; res[4] = z / sa; } else { res[0] = w / ((float) Math.abs(w)); res[1] = 0; res[2] = 0; res[3] = 0; res[4] = 0; } return res; } Quat conjugue() { return new Quat(w, -x, -y, -z); } } //****************************************************************** /* * * * * */ static class Vecteur { float x, y, z; public Vecteur() { this.x = 0.0f; this.y = 0.0f; this.z = 0.0f; } public Vecteur(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } void place(float xx, float yy, float zz) { this.x = xx; this.y = yy; this.z = zz; } Vecteur normalize() { float length = length(); x /= length; y /= length; z /= length; return this; } float length() { return (float) Math.sqrt(x * x + y * y + z * z); } 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; } static float dot(Vecteur v1, Vecteur v2) { return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; } float dot(Vecteur v1) { return v1.x * x + v1.y * y + v1.z * z; } Vecteur mul(float d) { Vecteur res = new Vecteur(); res.x = x * d; res.y = y * d; res.z = z * d; return res; } 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); } 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 class Tirette { int x,y,xpos,xbut,longueur,couleur1,couleur2; float valmin,valmax,coef,valeur; String titre; boolean survol,drag; BFont lafonte; BApplet apple; //********************************************************** public Tirette(int x,int y,int longueur,float valmin ,float valmax,String titre,int couleur1,int couleur2,BFont lafont,BApplet apple){ this.x=x; this.y=y; this.xpos=x; this.xbut=x; this.survol=false; this.drag=false; this.longueur=longueur; this.valmin=valmin; this.valmax=valmax; this.coef=(valmax-valmin)/(2*longueur); this.titre=titre; this.valeur=(valmin+valmax)/2; this.couleur1=couleur1; this.couleur2=couleur2; this.lafonte=lafont; this.apple=apple; } //****************************************************** public void actualiser(){ if(!apple.mousePressed && drag) drag=false; survol= (apple.mouseX>xpos-10)&&(apple.mouseXy-10)&&(apple.mouseY