Salut, il s'agit d'une erreur que vous pourriez considérer comme débutant mais je ne sais pas comment régler le problème. J'ai un fond qui tourne en boucle dans draw et j'ai créer des boutons dans setup. Lorsque je lance le programme ils sont présent mais on ne peut pas les voir. Je voudrais faire comme le menu de minecraft si vous connaissez.
Merci beaucoup!
import controlP5.*; ControlP5 cp5; int myColor = color(250), c1,c2; float n,n1, depth = 400; menu couleur = new menu(); void setup(){ size(800, 600, P3D); noStroke(); cp5 = new ControlP5(this); // create a new button with name 'buttonA' cp5.addButton("Jouer") .setValue(0) .setPosition(100,120) .setSize(200,30) ; // and add another 2 buttons cp5.addButton("Multijoueur") .setValue(100) .setPosition(100,160) .setSize(200,30) ; cp5.addButton("Options") .setPosition(100,200) .setSize(200,30) .setValue(0) ; cp5.addButton("Quitter") .setPosition(100,240) .setSize(200,30) .setValue(0) .setImages(loadImage("boutonnoir.png"), loadImage("boutonnoir.png"),loadImage("boutonnoir2.png")) .updateSize() ; } void draw(){ background(15, 15, 15); background(myColor); myColor = lerpColor(c1,c2,n); n += (1-n)* 0.1; float cameraY = height/1; float cameraX = width/1; translate(width/2, height/2, -depth/2); rotateY(frameCount*PI/500); float fov = cameraX/float(width) * PI/2; float cameraZ = cameraY / tan(fov / 2.0); float aspect = float(width)/float(height); perspective(fov, aspect, cameraZ/2000.0, cameraZ*4000.0); translate(width/10, height/10, depth/2); for(int i=0; i<2; i++) { float r = random(100); directionalLight(2, 83, 115, // Color 1, 10, 0); // The x-, y-, z-axis direction' directionalLight(3, 115, 140, // Color 10, 10, 0); // The x-, y-, z-axis direction' } for(int i=0; i<10; i++) { float r = random(20); rotateX(frameCount*PI/1000); //alt effect //rotateY(frameCount*PI/1000); for (int y = -2; y < 2; y++) { for (int x = -2; x < 2; x++) { for (int z = -2; z < 2; z++) { pushMatrix(); translate(400*x, 300*y, 300*z); box(5, 5, 100); popMatrix(); pushMatrix(); translate(400*x, 300*y, 50*z); box(100, 5, 5); popMatrix(); pushMatrix(); translate(400*x, 10*y, 50*z); box(50, 5, 5); popMatrix(); pushMatrix(); rotateY(frameCount*PI/400); translate(100*x, 300*y, 300*z); box(60, 40, 20); popMatrix(); } } } } } public void controlEvent(ControlEvent theEvent) { println(theEvent.getController().getName()); n = 0; } // function colorA will receive changes from // controller with name colorA public void colorA(int theValue) { println("a button event from colorA: "+theValue); c2 = color(90,10,2); } // function colorB will receive changes from // controller with name colorB public void colorB(int theValue) { println("a button event from colorB: "+theValue); c1 = c2; c2 = color(150,150,0); } // function colorC will receive changes from // controller with name colorC public void colorC(int theValue) { println("a button event from colorC: "+theValue); c1 = c2; c2 = color(255,255,0); } public void play(int theValue) { println("a button event from buttonB: "+theValue); c1 = c2; c2 = color(0,0,0); }
Hors ligne
Dans un environnement 3D, il est nécessaire d'afficher manuellement les éléments d'interfaces :
http://www.sojamo.de/libraries/controlP … etAutoDraw(boolean)
Donc il faut mettre en dernier dans la méthode draw(), le bout de code suivant :
cp5.draw();
Hors ligne
Ah d'accord,merci beaucoup !
je l'ai mis à la fin de mon draw() mais ça ne s'affiche pas, même si je change le background.
Dernière modification par Miaou (2014-04-29 21:58:22)
Hors ligne
Comme il y a plein de rotations et de translations, il faut ajouter un pushMatrix() au début et popMatrix() à la fin.
La caméra tourne aussi et cela pose des problèmes pour les éléments de ControlP5.
import controlP5.*; ControlP5 cp5; int myColor = color(250), c1, c2; float n, n1, depth = 400; //menu couleur = new menu(); void setup() { size(800, 600, P3D); noStroke(); cp5 = new ControlP5(this); // create a new button with name 'buttonA' cp5.addButton("Jouer") .setValue(0) .setPosition(100, 120) .setSize(200, 30) ; // and add another 2 buttons cp5.addButton("Multijoueur") .setValue(100) .setPosition(100, 160) .setSize(200, 30) ; cp5.addButton("Options") .setPosition(100, 200) .setSize(200, 30) .setValue(0) ; cp5.addButton("Quitter") .setPosition(100, 240) .setSize(200, 30) .setValue(0) .setImages(loadImage("boutonnoir.png"), loadImage("boutonnoir.png"), loadImage("boutonnoir2.png")) .updateSize() ; } void draw() { pushMatrix(); background(15, 15, 15); background(myColor); myColor = lerpColor(c1, c2, n); n += (1-n)* 0.1; float cameraY = height/1; float cameraX = width/1; translate(width/2, height/2, -depth/2); rotateY(frameCount*PI/500); float fov = cameraX/float(width) * PI/2; float cameraZ = cameraY / tan(fov / 2.0); float aspect = float(width)/float(height); perspective(fov, aspect, cameraZ/2000.0, cameraZ*4000.0); translate(width/10, height/10, depth/2); for (int i=0; i<2; i++) { float r = random(100); directionalLight(2, 83, 115, // Color 1, 10, 0); // The x-, y-, z-axis direction' directionalLight(3, 115, 140, // Color 10, 10, 0); // The x-, y-, z-axis direction' } for (int i=0; i<10; i++) { float r = random(20); rotateX(frameCount*PI/1000); //alt effect //rotateY(frameCount*PI/1000); for (int y = -2; y < 2; y++) { for (int x = -2; x < 2; x++) { for (int z = -2; z < 2; z++) { pushMatrix(); translate(400*x, 300*y, 300*z); box(5, 5, 100); popMatrix(); pushMatrix(); translate(400*x, 300*y, 50*z); box(100, 5, 5); popMatrix(); pushMatrix(); translate(400*x, 10*y, 50*z); box(50, 5, 5); popMatrix(); pushMatrix(); rotateY(frameCount*PI/400); translate(100*x, 300*y, 300*z); box(60, 40, 20); popMatrix(); } } } } popMatrix(); translate(0, 0, 200); cp5.draw(); } public void controlEvent(ControlEvent theEvent) { println(theEvent.getController().getName()); n = 0; } // function colorA will receive changes from // controller with name colorA public void colorA(int theValue) { println("a button event from colorA: "+theValue); c2 = color(90, 10, 2); } // function colorB will receive changes from // controller with name colorB public void colorB(int theValue) { println("a button event from colorB: "+theValue); c1 = c2; c2 = color(150, 150, 0); } // function colorC will receive changes from // controller with name colorC public void colorC(int theValue) { println("a button event from colorC: "+theValue); c1 = c2; c2 = color(255, 255, 0); } public void play(int theValue) { println("a button event from buttonB: "+theValue); c1 = c2; c2 = color(0, 0, 0); }
Hors ligne
Suite aux différentes recherches voici ce à quoi j'ai abouti :
import controlP5.*; ControlP5 cp5; int myColor = color(250), c1, c2; float n, n1, depth = 400; //menu couleur = new menu(); void setup() { size(800, 600, P3D); noStroke(); cp5 = new ControlP5(this); // create a new button with name 'buttonA' cp5.addButton("Jouer") .setValue(0) .setPosition(100, 120) .setSize(200, 30) ; // and add another 2 buttons cp5.addButton("Multijoueur") .setValue(100) .setPosition(100, 160) .setSize(200, 30) ; cp5.addButton("Options") .setPosition(100, 200) .setSize(200, 30) .setValue(0) ; cp5.addButton("Quitter") .setPosition(100, 240) .setSize(200, 30) .setValue(0) .setImages(loadImage("boutonnoir.png"), loadImage("boutonnoir.png"), loadImage("boutonnoir2.png")) .updateSize() ; } void draw() { hint(ENABLE_DEPTH_TEST); pushMatrix(); background(15, 15, 15); background(myColor); myColor = lerpColor(c1, c2, n); n += (1-n)* 0.1; float cameraY = height/1; float cameraX = width/1; translate(width/2, height/2, -depth/2); rotateY(frameCount*PI/500); float fov = cameraX/float(width) * PI/2; float cameraZ = cameraY / tan(fov / 2.0); float aspect = float(width)/float(height); perspective(fov, aspect, cameraZ/2000.0, cameraZ*4000.0); translate(width/10, height/10, depth/2); for (int i=0; i<2; i++) { float r = random(100); directionalLight(2, 83, 115, // Color 1, 10, 0); // The x-, y-, z-axis direction' directionalLight(3, 115, 140, // Color 10, 10, 0); // The x-, y-, z-axis direction' } for (int i=0; i<10; i++) { float r = random(20); rotateX(frameCount*PI/1000); //alt effect //rotateY(frameCount*PI/1000); for (int y = -2; y < 2; y++) { for (int x = -2; x < 2; x++) { for (int z = -2; z < 2; z++) { pushMatrix(); translate(400*x, 300*y, 300*z); box(5, 5, 100); popMatrix(); pushMatrix(); translate(400*x, 300*y, 50*z); box(100, 5, 5); popMatrix(); pushMatrix(); translate(400*x, 10*y, 50*z); box(50, 5, 5); popMatrix(); pushMatrix(); rotateY(frameCount*PI/400); translate(100*x, 300*y, 300*z); box(60, 40, 20); popMatrix(); } } } } popMatrix(); hint(DISABLE_DEPTH_TEST); //camera(); noLights(); translate(-300, -240); scale(1.8); //cp5.draw(); } public void controlEvent(ControlEvent theEvent) { println(theEvent.getController().getName()); n = 0; } // function colorA will receive changes from // controller with name colorA public void colorA(int theValue) { println("a button event from colorA: "+theValue); c2 = color(90, 10, 2); } // function colorB will receive changes from // controller with name colorB public void colorB(int theValue) { println("a button event from colorB: "+theValue); c1 = c2; c2 = color(150, 150, 0); } // function colorC will receive changes from // controller with name colorC public void colorC(int theValue) { println("a button event from colorC: "+theValue); c1 = c2; c2 = color(255, 255, 0); } public void play(int theValue) { println("a button event from buttonB: "+theValue); c1 = c2; c2 = color(0, 0, 0); }
Je ne suis pas satisfait car il faut recaler les éléments de controlP5 avec des agrandissements et des translations.
La méthode de réinitialisation de la camera ne change rien.
sic !
Hors ligne
Merci Mushussu c'est bien mieux ainsi! Le texte est maintenant toujours devant le fond animé et c'est cela qu'il nous fallait ^^
Hors ligne
Pages: 1