kazabandi
YaBB Newbies
Offline
Posts: 6
Re: Program of a model 3D of train
Reply #3 - Dec 26th , 2008, 11:45am
I finished the design part of the train, now I want to use the protcole OSC as a remote control, I want to have a small example using the OSC and apply it to my example. Here is my code: int sval,sval1, sval2,sval3,test, cnd=0, cnd1=0, cnd2=0, cnd3=0,cnd4=0,cnd5=0; float x; void setup() { size(1250, 600, P3D); noStroke(); } void draw(){ lights(); background(22,111,303); perspective(); if (keyPressed){ if (key=='q') {cnd2=1;cnd3=0;} if (key=='s') {cnd2=0;cnd3=1;} if (key == 'd') {cnd2=0;cnd3=0;} } if (cnd2==1 && cnd3==0) sval2+=1; rotateX(sval2*0.003); if (cnd2==0 && cnd3==1) sval3+=1; rotateX(-sval3*0.003); plan(); circuit(); if (keyPressed) { if (key == 'a') cnd=0; if (key == 'z' && cnd1!=1 ) {cnd=1;cnd1=0; } if (key == 'a' ) {cnd1=0;cnd4=0;cnd5=0;} if (key == 'e' && cnd!=1 ) {cnd1=1;cnd=0; } if (key == 'r' ) {cnd4=1;cnd5=0;} if (key == 't' ) {cnd5=1;cnd4=0;} } if ((cnd==1 && cnd1==0)|(cnd==1 && cnd1==0 && cnd5==1)) sval+=1; if (cnd==1 && cnd1==0 && cnd4==1) sval+=2; rotate(sval*0.01); if ((cnd1==1 && cnd==0)|(cnd1==1 && cnd==0 && cnd5==1)) sval1+=1; if (cnd1==1 && cnd==0 && cnd4==1) sval1+=2; rotate(-sval1*0.01); trainpartie1(); trainpartie2(); trainpartie3(); roue(); } void plan(){ pushMatrix(); noStroke(); rotateX(PI/4); translate(630,0,-198); fill(11,330,44); box(850,850,20); translate(-330,370,60); rotateX(PI/2); fill(#8B4513); cylinder(10,100,300); translate(0,40,0); fill(11,130,44); sphere(40); translate(640,0,0); sphere(40); translate(0,-40,0); fill(#8B4513); cylinder(10,100,300); translate(0,0,680); cylinder(10,100,300); translate(0,40,0); fill(11,130,44); sphere(40); translate(-640,0,0); sphere(40); translate(0,-40,0); fill(#8B4513); cylinder(10,100,300); popMatrix(); } void circuit(){ translate(670,280,15); rotateX(PI/4); translate(-40,-180,0); noFill(); stroke(0); ellipse(0, 0, 760, 760); ellipse(0, 0, 740, 740); ellipse(0, 0, 710, 710); ellipse(0, 0, 690, 690); for (int i = 0; i < 63; i++) { rotate( 0.05); fill(0); rect(0,355, 5, 15); rotateZ(PI); rect(0,355, 5, 15); } } void trainpartie1(){ pushMatrix(); noStroke(); fill(#FF0000); translate(0,360,45); box(50); popMatrix(); rotate(0.2); pushMatrix(); noStroke(); fill(#FF4500); translate(0,360,45); box(50); popMatrix(); rotate(0.2); pushMatrix(); noStroke(); fill(#1E90FF); translate(0,360,45); box(50); popMatrix(); rotate(0.2); pushMatrix(); noStroke(); fill(#FFFF00); translate(0,360,45); box(50); popMatrix(); rotate(0.2); pushMatrix(); noStroke(); fill(#4B0082); translate(0,360,45); box(50); popMatrix(); } void trainpartie2(){ rotate(-1); for (int i = 0; i < 4; i++) { rotate(0.2); pushMatrix(); noStroke(); fill(#000000); translate(-40,360,45); box(40,20,30); popMatrix(); } } void trainpartie3(){ rotate(0.2); pushMatrix(); noStroke(); fill(#FFA500); translate(0,360,85); box(25,25,30); popMatrix(); rotate(-0.8); pushMatrix(); noStroke(); fill(#FFA500); translate(0,360,85); box(25,25,30); popMatrix(); } void roue(){ rotate(-0.2); test+=1; for (int i = 0; i < 5; i++) { rotate(0.2); pushMatrix(); fill(#C0C0C0); translate(0,350,10); rotateY(sval*0.1); rotateY(-sval1*0.1); cylinder(10,10,15); translate(0,25,0); cylinder(10,10,15); popMatrix(); } } void cylinder(float w, float h, int sides) { float angle; float[] x = new float[sides+1]; float[] z = new float[sides+1]; //get the x and z position on a circle for all the sides for(int i=0; i < x.length; i++){ angle = TWO_PI / (sides) * i; x[i] = sin(angle) * w; z[i] = cos(angle) * w; } //draw the top of the cylinder beginShape(TRIANGLE_FAN); vertex(0, -h/2, 0); for(int i=0; i < x.length; i++){ vertex(x[i], -h/2, z[i]); } endShape(); //draw the center of the cylinder beginShape(QUAD_STRIP); for(int i=0; i < x.length; i++){ vertex(x[i], -h/2, z[i]); vertex(x[i], h/2, z[i]); } endShape(); //draw the bottom of the cylinder beginShape(TRIANGLE_FAN); vertex(0, h/2, 0); for(int i=0; i < x.length; i++){ vertex(x[i], h/2, z[i]); } endShape(); } void perspective() { lights(); float cameraY = height/2.0; float fov = mouseX/float(width) * PI/2; float cameraZ = cameraY / tan(fov / 2.0); float aspect = float(width)/float(height); perspective(fov, aspect, cameraZ/10.0, cameraZ*10.0); }