Tibs.
YaBB Newbies
Offline
Posts: 2
translate(); bug?
Feb 29th , 2008, 4:45pm
I've been learning processing bit by bit the last couple of weeks, and I've finally ran into a problem I can't seem to solve. The code is supposed to draw the cube by lines, and when it's done, just replace it with a box to save time and use fills. The drawing part works, but when it is replaced with a box, it places it on a different place then the original box. How come? The problem doesn't seem to be with the replaced boxes, since those are 'translated' as they should.. code: import processing.opengl.*; float eyeZ = 80; float eyeY; float eyeX; int cubesize; float increase; int cubetotal; int boxdone; float zdepth1 = 10; float xwidth1 = 10; float ywidth1 = 10; float zdepth2 = 10; float xwidth2 = 10; float ywidth2 = 10; float zdepth3 = 10; float xwidth3 = 10; float ywidth3 = 10; float zdepth4 = 10; float xwidth4 = 10; float ywidth4 = 10; void setup(){ size(640, 480, OPENGL); smooth(); noFill(); background(255); } void draw(){ background(255); camera(eyeX, eyeY, eyeZ, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); // box(10); eyeY = eyeY-0.1; eyeX = eyeX-0.1; drawCube(); translate(10, 0, 0); drawCube(); increase = increase+0.001; } void drawCube(){ strokeWeight(2); if(boxdone == 0){ if(xwidth1 > 0){ xwidth1=xwidth1-increase; }else if(xwidth2 > 0){ xwidth2=xwidth2-increase; zdepth4=zdepth4-increase; } if(ywidth1 > 0){ ywidth1=ywidth1-increase; }else if(ywidth2 > 0){ ywidth2=ywidth2-increase; zdepth3=zdepth3-increase; }else if(zdepth2 > 0){ zdepth2=zdepth2-increase; } if(zdepth1 > 0){ zdepth1=zdepth1-increase; }else if(xwidth3 > 0){ ywidth3=ywidth3-increase; xwidth3=xwidth3-increase; }else if(xwidth4 > 0){ ywidth4=ywidth4-increase; xwidth4=xwidth4-increase; }else{ boxdone=1; } //drawphase line(xwidth4,0,10,0); line(0,ywidth4,0,10); line(10,10,xwidth3,10); line(10,ywidth3,10,10); translate(0,0,10); line(xwidth2,0,10,0); line(0,ywidth2,0,10); line(10,10,xwidth1,10); line(10,ywidth1,10,10); translate(0,0,-10); rotateZ(radians(45)); line(0,0,zdepth2,0,0,10); rotateZ(radians(45)); line(10,-10,zdepth1,10,-10,10); rotateZ(radians(180)); translate(-10,0,0); rotateZ(radians(45)); line(0,0,zdepth3,0,0,10); rotateZ(radians(45)); line(10,-10,zdepth4,10,-10,10); //rotateZ(radians(-360)); }else if(boxdone == 1){ translate(5,5,5); strokeWeight(1.71); box(10); boxdone=2; cubetotal++; zdepth1 = 10; xwidth1 = 10; ywidth1 = 10; zdepth2 = 10; xwidth2 = 10; ywidth2 = 10; zdepth3 = 10; xwidth3 = 10; ywidth3 = 10; zdepth4 = 10; xwidth4 = 10; ywidth4 = 10; translate(-5,-5,-5); }else if(boxdone == 2){ //stroke(255,0,0); translate(5,5,5); strokeWeight(1.71); box(10); translate(-5,-5,-5); } }