Salut la compagnie!
Voila mon projet: je cherche à obtenir 4 vues de cet objet, avec 4 caméra bougeant simultanément si j'en fait bouger une.
En gros:
Une caméra devant l'objet, une derrière, une a gauche, une a droite. Et si je bouge une vue, les autres bougent en même temps.
Un exemple de ce que j'essais de produire :
import peasy.test.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; import peasy.test.*; import peasy.org.apache.commons.math.*; import peasy.*; import peasy.org.apache.commons.math.geometry.*; import peasy.*; int num = 500; float RADIUS = 300; float SCALE = 500.0; int globKonexID = 0; PeasyCam cam; Neuron n[]; void setup(){ size(1440,900,P3D); n = new Neuron[num]; cam = new PeasyCam(this, 800); cam.setMinimumDistance(300); cam.setMaximumDistance(3000); for(int i = 0;i<n.length;i++){ n[i] = new Neuron(i); } for(int i = 0;i<n.length;i++){ n[i].makeConnections(); } noSmooth(); stroke(1.0); for(int i = 0;i<n[0].k.length;i++) n[0].makeSignal(i); } void mousePressed(){ if(mouseButton==RIGHT){ for(int i = 0;i<n.length;i++){ n[i].x = random(-width/2,width/2); n[i].y = random(-width/2,width/2); n[i].z = random(-width/2,width/2); } for(int i = 0;i<n.length;i++) n[i].makeConnections(); for(int i = 0;i<n[0].sig.length;i++) n[0].makeSignal(i); } } void draw(){ background(0); for(int i = 0;i<n.length;i++){ n[i].draw(); } } ////////////////////////// >> class Neuron{ float x,y,z,radius,xx,yy,zz,val; int id; boolean imobile = false; Konexe k[] = new Konexe[0]; Signal sig[] = new Signal[0]; Neuron(int _id){ xx = x = random(-width/2,width/2); yy = y = random(-width/2,width/2); zz = z = random(-width/2,width/2); id= _id; radius = RADIUS; val = 0; if(id==1)imobile = true; } void makeConnections(){ k = new Konexe[0]; sig = new Signal[0]; for(int i = 0 ;i<n.length;i++){ if(i!=id && dist(x,y,z,n[i].x,n[i].y,n[i].z) < radius){ k = (Konexe[])expand(k,k.length+1); k[k.length-1] = new Konexe(id,i); sig = (Signal[])expand(sig,sig.length+1); sig[sig.length-1] = new Signal(k[sig.length-1]); } } } void makeSignal(int which){ int i = which; sig[i].x = xx; sig[i].y = yy; sig[i].z = zz; sig[i].running = true; } void drawConnections(){ for(int i = 0 ;i<k.length;i++){ line(xx,yy,zz,n[k[i].B].xx,n[k[i].B].yy,n[k[i].B].zz); } } void draw(){ xx += (x-xx) / 100.0; yy += (y-yy) / 100.0; zz += (z-zz) / 100.0; if(sig.length>0){ for(int i = 0;i<sig.length;i+=1){ if(sig[i].running){ if(sig[i].moving){ pushMatrix(); pushStyle(); //strokeWeight(3); stroke(255,20); noFill(); //line(sig[i].x,sig[i].y,sig[i].z,sig[i].lx,sig[i].ly,sig[i].lz); translate(sig[i].x,sig[i].y,sig[i].z); box(2); popStyle(); popMatrix(); } sig[i].step(); } } } stroke(lerpColor(#3300FF,#33CCFF,norm(val,10,200)),30); drawConnections(); } } ////////////////////////// >> class Konexe{ int A,B,id; float weight = 1.5; Konexe(int _A,int _B){ A = _A; B = _B; id = globKonexID++; weight = random(101,200)/SCALE; } } class Signal{ Konexe base; int cyc = 0; float x,y,z,lx,ly,lz; float speed = 10.1; boolean running = false; boolean visible = true; boolean moving = false; int deadnum = 2000; int deadcount = 0; Signal(Konexe _base){ deadnum = (int)random(2,40); base = _base; lx = x = n[base.A].x; ly = y = n[base.A].y; lz = z = n[base.A].z; speed *= base.weight; } void step(){ running = true; if(abs(lx-x)>.1||abs(ly-y)>.1||abs(lz-z)>.1) moving = true; else moving = false; lx = x; ly = y; lz = z; if(!n[base.A].imobile){ x += (n[base.B].xx-x) / speed;//(speed+(dist(n[base.A].x,n[base.A].y,n[base.B].x,n[base.B].y)+1)/100.0); y += (n[base.B].yy-y) / speed;//(speed+(dist(n[base.A].x,n[base.A].y,n[base.B].x,n[base.B].y)+1)/100.0); z += (n[base.B].zz-z) / speed; } n[base.A].val+=(0-n[base.A].val)/5000.0; if(dist(x,y,z,n[base.B].xx,n[base.B].yy,n[base.B].zz)<1.0){ if(deadcount<0){ deadcount = deadnum; //deadnum += (int)random(-1,1); //println("run "+base.A+" : "+base.B); running = false; for(int i = 0; i < n[base.B].k.length;i++){ if(!n[base.B].sig[i].running && base.A!=n[base.B].sig[i].base.B){ n[base.B].makeSignal(i); n[base.B].sig[i].base.weight += (base.weight-n[base.B].sig[i].base.weight)/((dist(x,y,z,n[base.A].xx,n[base.A].yy,n[base.A].zz)+1.0)/200.0); } } //base.weight = random(1001,3000) / 1000.0; if(n[base.A].id!=1){ n[base.A].xx+=((n[base.B].x-n[base.A].x)/1.1)*noise((frameCount+n[base.A].id)/18.0);; n[base.A].yy+=((n[base.B].y-n[base.A].y)/1.1)*noise((frameCount+n[base.A].id)/17.0); n[base.A].zz+=((n[base.B].z-n[base.A].z)/1.1)*noise((frameCount+n[base.A].id)/16.0); n[base.A].xx-=((n[base.B].x-n[base.A].x)/1.1)*noise((frameCount+n[base.B].id)/18.2);; n[base.A].yy-=((n[base.B].y-n[base.A].y)/1.1)*noise((frameCount+n[base.B].id)/17.2); n[base.A].zz-=((n[base.B].z-n[base.A].z)/1.1)*noise((frameCount+n[base.B].id)/16.2); } lx = n[base.A].x; ly = n[base.A].y; lz = n[base.A].z; n[base.A].val+=(255-n[base.A].val)/10.0; }else{ deadcount--; } } } }
Dernière modification par Malleat (2012-05-02 16:58:22)
Hors ligne
Hors ligne
tu auras plus de réponse dans le forum processing...
Hors ligne
Est ce que tu ne pourrais pas avoir 4 objets différents auxquels tu appliques des transformations ? Dans ce cas, la caméra ne bouge pas... Ça pose un problème pour la lumière...
Hors ligne
La solution serait de connecté 4 caméra a 4 texture différente, en p5 de base j'ignore si c'est faisable, en opengl sans aucun doute.
ça doit être faisable 4 objet avec 4 lumière, en faisant des PGraphics.
Dernière modification par cgiles (2012-05-14 13:16:51)
Hors ligne
import processing.opengl.*;
import javax.media.opengl.*;
GL gl;
float a = 0.0;
boolean bFlush = true;
public void setup() {
size(600, 600, OPENGL);
// noStroke();
colorMode(RGB,1);
frameRate(60);
}
public void draw() {
println(frameRate);
background(0);
// bottom Left port - FRONT View
gl = ((PGraphicsOpenGL)g).beginGL();
gl.glViewport (0, 0, 300, 300);
((PGraphicsOpenGL)g).endGL();
perspective(PI/6f, 1f, 10, 1000);
camera(0,0,600, 0,0,0, 0,1,0);
renderGeometry();
if (bFlush) {
gl.glFlush();
}
((PGraphicsOpenGL)g).endGL();
// bottom right viewport - BACK View
gl = ((PGraphicsOpenGL)g).beginGL();
gl.glViewport(300, 0, 300, 300);
((PGraphicsOpenGL)g).endGL();
perspective(PI/6f, 1f, 10, 1000);
camera(0,0,-600, 0,0,0, 0,1,0);
renderGeometry();
if (bFlush) {
gl.glFlush();
}
((PGraphicsOpenGL)g).endGL();
// top left port - LEFT Viewport
gl = ((PGraphicsOpenGL)g).beginGL();
gl.glViewport (0, 300, 300, 300);
((PGraphicsOpenGL)g).endGL();
perspective(PI/6f, 1f, 10, 1000);
camera(-600,0,0, 0,0,0, 0,1,0);
renderGeometry();
if (bFlush) {
gl.glFlush();
}
((PGraphicsOpenGL)g).endGL();
// top right port - RIGHT Viewport
gl = ((PGraphicsOpenGL)g).beginGL();
gl.glViewport(300, 300, 300, 300);
((PGraphicsOpenGL)g).endGL();
perspective(PI/6f, 1f, 10, 1000);
camera(600,0,0, 0,0,0, 0,1,0);
renderGeometry();
if (bFlush) {
gl.glFlush();
}
((PGraphicsOpenGL)g).endGL();
a += 0.005;
}
void renderGeometry() {
lights();
rotateX(a*1);
rotateY(a*1);
pushMatrix();
translate(50, 50);
scale(60);
beginShape(QUADS);
fill(0, 1, 1);
vertex(-1, 1, 1);
fill(1, 1, 1);
vertex( 1, 1, 1);
fill(1, 0, 1);
vertex( 1, -1, 1);
fill(0, 0, 1);
vertex(-1, -1, 1);
fill(1, 1, 1);
vertex( 1, 1, 1);
fill(1, 1, 0);
vertex( 1, 1, -1);
fill(1, 0, 0);
vertex( 1, -1, -1);
fill(1, 0, 1);
vertex( 1, -1, 1);
fill(1, 1, 0);
vertex( 1, 1, -1);
fill(0, 1, 0);
vertex(-1, 1, -1);
fill(0, 0, 0);
vertex(-1, -1, -1);
fill(1, 0, 0);
vertex( 1, -1, -1);
fill(0, 1, 0);
vertex(-1, 1, -1);
fill(0, 1, 1);
vertex(-1, 1, 1);
fill(0, 0, 1);
vertex(-1, -1, 1);
fill(0, 0, 0);
vertex(-1, -1, -1);
fill(0, 1, 0);
vertex(-1, 1, -1);
fill(1, 1, 0);
vertex( 1, 1, -1);
fill(1, 1, 1);
vertex( 1, 1, 1);
fill(0, 1, 1);
vertex(-1, 1, 1);
fill(0, 0, 0);
vertex(-1, -1, -1);
fill(1, 0, 0);
vertex( 1, -1, -1);
fill(1, 0, 1);
vertex( 1, -1, 1);
fill(0, 0, 1);
vertex(-1, -1, 1);
endShape();
popMatrix();
}
void keyPressed() {
if (key == 'f') {
bFlush = !bFlush;
}
}
Hors ligne
nice^^
Hors ligne
Merciiii
Mais le but final serait d'utiliser une des librairie afin d'ouvrir n'importe quelle 3D comme ça.
C'est vraiment pas possible d'avoir 4 caméras comme la vidéo? Sinon, l'hologramme ne marche pas...
Hors ligne
En fait, il faudrait plutôt 4 caméra fixe si c'est plus simple, et la possibilité de faire bouger l'objet, par exemple lui faire faire des rotations, ou des changements d'échelle (de la scène entière?).
Hors ligne
laisses moi deviner , c'est pour ton projet de fin d'étude ?
Hors ligne
Mémoire! J'apprends le java à coté histoire de faire un truc bien classe pour la toute fin qui sera en février! Mais pour le moment, j'essais d'avoir au moins quelque chose de viable pour la fin de la première phase ><
Hors ligne
Avec la librairie objLoader, tu charges un .obj et tu fais le rendu (model.draw(); ) de ton obj à la place du cube en vertex dans le void renderGeometry(){...}
Les 4 cameras sont déjà fixes ici, c'est bien le cube qui pivote sur les axes X et Y.
Dans gl.glViewport(x,y,width,height) tu choisis la position et la taille de ton "image" et ensuite faut jouer sur les perspective(); et camera();
Dernière modification par Makio135 (2012-05-15 12:45:58)
Hors ligne
Dans la vidéo, je ne pense pas que ce soit les caméras qui bougent mais l'objet.
Dans le code de makio, il y a quatre caméra, qui sont chacune a une face.
Pour faire bouger l'objet, tu dois jouer sur la rotation , pour l'agrandir ou le réduire, tu devrais jouer sur le zoom, ou l'échelle si ta librairie d'import 3d le permet . Mais tu ne devrais pas avoir de difficulté de remplacer le cube par un objet importé.
Dernière modification par cgiles (2012-05-15 13:52:44)
Hors ligne
cgiles a écrit:
Dans le code de marko, il y a quatre caméra, qui sont chacune a une face.
Marko?
@Malleat: il me semble que tu mets la charrue avant les bœufs...
Tu devrais fractionner ton problème en essayant de comprendre le code à chaque étape: comment on crée un objet 3d simple ou abstrait en processing pur (pas de librairie) / comment le déplacer, le faire pivoter, zoomer dessus, ... / comment on importe une 3D via une librairie / et enfin comment créer plusieurs vues (mon code).
Bidouiller à chaque fois le code les différentes valeurs pour voir ce qu'il se passe, ça aide à comprendre.
Hors ligne