Powder
YaBB Newbies
Offline
Posts: 9
[solved] Weird lines appearing.. please help!
Mar 3rd , 2009, 12:53am
Hi! I'm new to Processing and tried to make a sketch with a rotating cube. It works but there are strange lines appearing, all going towards one point... I don't understand how I can get rid of them! Would be nice if you can have a look! Greetings Powder int WIDTH, HEIGHT, ANZ_POINTS_1DIM, ANZ_POINTS_GES, DEPTH, ANZ_LINES, anz_lines_straight; double DELTA, ROT_DELTA, ROT_DELTA_DELTA, rot; Point pnts[][][]; Line lines[]; Line linesStraight[]; void setup() { frame.removeNotify(); frame.setUndecorated(true); frame.addNotify(); WIDTH = screen.width; HEIGHT = screen.height; size(WIDTH, HEIGHT, P3D); background(0); stroke(255); smooth(); // Set up variables ANZ_POINTS_1DIM = 4; ANZ_LINES = 100; DELTA = WIDTH/ANZ_POINTS_1DIM; //Aenderung ANZ_POINTS_GES = ANZ_POINTS_1DIM*ANZ_POINTS_1DIM*ANZ_POINTS_1DIM; anz_lines_straight = ANZ_POINTS_GES*2; //Stimmt nicht, nur Testwert DEPTH = 100; ROT_DELTA = PI/128.0; ROT_DELTA_DELTA = 0.1; rot = 0; pnts = new Point[ANZ_POINTS_1DIM][ANZ_POINTS_1DIM][ANZ_POINTS_1DIM]; lines = new Line[ANZ_LINES]; // Fill Array for(int i=0; i<ANZ_POINTS_1DIM; i++) { for(int j=0; j<ANZ_POINTS_1DIM; j++) { for(int k=0; k<ANZ_POINTS_1DIM; k++) { pnts[i][j][k] = new Point(i*DELTA-WIDTH/2, j*DELTA-HEIGHT/2, k*DELTA-DEPTH/2); } } } //Create Straight Lines createStraightLines(); } void draw() { background(0); smooth(); translate(WIDTH/2, HEIGHT/2, DEPTH/2); rotateY((float)rot); rotateZ((float)rot*0.5); drawAllPnts(); drawStraightLines(); rot += ROT_DELTA; } void drawAllPnts() { for(int i=0; i<ANZ_POINTS_1DIM; i++) { for(int j=0; j<ANZ_POINTS_1DIM; j++) { for(int k=0; k<ANZ_POINTS_1DIM; k++) { pnts[i][j][k].drawPnt(); } } } } void createStraightLines() { int curLine = 0; for(int i=0; i<ANZ_POINTS_1DIM; i++) { for(int j=0; j<ANZ_POINTS_1DIM; j++) { for(int k=0; k<ANZ_POINTS_1DIM; k++) { checkArraySize(curLine); if( pointExistsInArray( i+1, j, k ) ) { Point p1 = new Point( (float)pnts[i][j][k].x, (float)pnts[i][j][k].y, (float)pnts[i][j][k].z); Point p2 = new Point( (float)pnts[i+1][j][k].x, (float)pnts[i+1][j][k].y, (float)pnts[i+1][j][k].z); lines[curLine] = new Line(p1, p2); anz_lines_straight = curLine+1; curLine++; } if( pointExistsInArray( i, j+1, k ) ) { lines[curLine] = new Line(new Point( (float)pnts[i][j][k].x, (float)pnts[i][j][k].y, (float)pnts[i][j][k].z ), new Point( (float)pnts[i][j+1][k].x, (float)pnts[i][j+1][k].y, (float)pnts[i][j+1][k].z )); anz_lines_straight = curLine+1; curLine++; } if( pointExistsInArray( i, j, k+1 ) ) { lines[curLine] = new Line(new Point( (float)pnts[i][j][k].x, (float)pnts[i][j][k].y, (float)pnts[i][j][k].z ), new Point( (float)pnts[i][j][k+1].x, (float)pnts[i][j][k+1].y, (float)pnts[i][j][k+1].z )); anz_lines_straight = curLine+1; curLine++; } } } } } // Returns new size of array int checkArraySize(int pos) { if(pos >= (lines.length-1)) //Double size of Array lines = (Line[])expand(lines); return lines.length; } void drawStraightLines() { stroke( (float)(abs( sin(radians(frameCount)) ) * 225) + 30, 0, 0 ); for(int i=0; i<anz_lines_straight; i++) { lines[i].drawLine(); } } boolean pointExistsInArray(int i, int j, int k) { if(i<ANZ_POINTS_1DIM && j<ANZ_POINTS_1DIM && k<ANZ_POINTS_1DIM) return true; return false; } class Point { double x, y, z; Point() { this.x = 0.0; this.y = 0.0; this.z = 0.0; } Point(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } void drawPnt() { point((float)this.x, (float)this.y, (float)this.z); } } // Class Line stores 2 3D Points class Line { Point p1, p2; Line(Point p1, Point p2) { this.p1 = p1; this.p2 = p2; } void drawLine() { line((float)p1.x, (float)p1.y, (float)p1.z, (float)p2.x, (float)p2.y, (float)p2.z); } }