Powder
YaBB Newbies
Offline
Posts: 9
Re: Speed Optimization Question
Reply #1 - Mar 6th , 2009, 12:53am
//PART TWO-------------------------------- void createRects() { int curRect = 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++) { checkArraySizeRects(curRect); //x-y-Rect if( pointExistsInArray( i+1, j, k ) && pointExistsInArray( i, j+1, k ) && pointExistsInArray( i+1, j+1, k ) ) { Point p1 = new Point(pnts[i][j][k].x, pnts[i][j][k].y, pnts[i][j][k].z); Point p2 = new Point(pnts[i+1][j][k].x, pnts[i+1][j][k].y, pnts[i+1][j][k].z); Point p3 = new Point(pnts[i+1][j+1][k].x, pnts[i+1][j+1][k].y, pnts[i+1][j+1][k].z); Point p4 = new Point(pnts[i][j+1][k].x, pnts[i][j+1][k].y, pnts[i][j+1][k].z); color col = color(0, random(10, 255), 0); //color col = color(random(10, 255), random(10, 255), random(10, 255)); rects[curRect] = new Rect3D(p1, p2, p3, p4, col); anz_rects = curRect+1; curRect++; } //y-z-Rect if( pointExistsInArray( i, j, k+1 ) && pointExistsInArray( i, j+1, k ) && pointExistsInArray( i, j+1, k+1 ) ) { Point p1 = new Point(pnts[i][j][k].x, pnts[i][j][k].y, pnts[i][j][k].z); Point p2 = new Point(pnts[i][j][k+1].x, pnts[i][j][k+1].y, pnts[i][j][k+1].z); Point p3 = new Point(pnts[i][j+1][k+1].x, pnts[i][j+1][k+1].y, pnts[i][j+1][k+1].z); Point p4 = new Point(pnts[i][j+1][k].x, pnts[i][j+1][k].y, pnts[i][j+1][k].z); //color col = color(random(10, 255), random(10, 255), random(10, 255)); color col = color(random(10, 255), 0, 0); rects[curRect] = new Rect3D(p1, p2, p3, p4, col); anz_rects = curRect+1; curRect++; } //x-z-Rect if( pointExistsInArray( i+1, j, k ) && pointExistsInArray( i, j, k+1 ) && pointExistsInArray( i+1, j, k+1 ) ) { Point p1 = new Point(pnts[i][j][k].x, pnts[i][j][k].y, pnts[i][j][k].z); Point p2 = new Point(pnts[i][j][k+1].x, pnts[i][j][k+1].y, pnts[i][j][k+1].z); Point p3 = new Point(pnts[i+1][j][k+1].x, pnts[i+1][j][k+1].y, pnts[i+1][j][k+1].z); Point p4 = new Point(pnts[i+1][j][k].x, pnts[i+1][j][k].y, pnts[i+1][j][k].z); //color col = color(random(10, 255), random(10, 255), random(10, 255)); color col = color(0, 0, random(10, 255)); rects[curRect] = new Rect3D(p1, p2, p3, p4, col); anz_rects = curRect+1; curRect++; } } } } } int checkArraySizeRects(int pos) { if(pos >= (rects.length-1)) //Double size of Array rects = (Rect3D[])expand(rects); return rects.length; } 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 Rect3D { Point p1, p2, p3, p4; color col; Rect3D(Point p1, Point p2, Point p3, Point p4, color col) { this.p1 = p1; this.p2 = p2; this.p3 = p3; this.p4 = p4; this.col = col; } void drawRect3D() { buffer.fill(col, alphaVal); buffer.beginShape(); buffer.vertex(p1.x, p1.y, p1.z); buffer.vertex(p2.x, p2.y, p2.z); buffer.vertex(p3.x, p3.y, p3.z); buffer.vertex(p4.x, p4.y, p4.z); buffer.endShape(CLOSE); } } class Point { float x, y, z; Point() { this.x = 0.0; this.y = 0.0; this.z = 0.0; } Point(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } void drawPnt() { point(this.x, this.y, this.z); } }