mohamm
YaBB Newbies
Offline
Posts: 5
Re: arrayIndexOutOfBandsException only with P3D
Reply #1 - Oct 1st , 2009, 7:23am
soory i do a mistake, here the code : import processing.opengl.*; float xmag, ymag = 0; float newXmag, newYmag = 0; float xoff = 0.0; float xincrement = 0.01; //float vBackground = 0; //float n = 0.0; MyCube[]cube; int numCube = 20; int sCube = 15; //MyMotorNoise Noise; void setup() { size(640, 360, OPENGL); noStroke(); //colorMode(RGB, 1); smooth(); //noStroke(); //Noise = new MyMotorNoise(); cube = new MyCube[numCube*numCube]; int k = 0; for(int i = 0; i<numCube; i++){ for(int j = 0; j<numCube; j++){ cube[k] = new MyCube(i*sCube, j*sCube); k++; }} } void draw() { background(0); //println("o"); //pushMatrix(); //vBackground = n; translate(width/2, height/2, -30); newXmag = mouseX/float(width) * TWO_PI; newYmag = mouseY/float(height) * TWO_PI; float diff = xmag-newXmag; if (abs(diff) > 0.01) { xmag -= diff/4.0; } diff = ymag-newYmag; if (abs(diff) > 0.01) { ymag -= diff/4.0; } rotateX(-ymag); rotateY(-xmag); for(int k = 0; k<cube.length; k++){ cube[k].display(); } //println(cube[10].x); // println(cube[15].x); } class MyCube { int x, y, z; float n =0.0; MyCube(int xInp, int yInp){ x = xInp; y = yInp; } void display(){ // Get a noise value based on xoff and scale it according to the window's width //println(x); float n = noise(xoff); // With each cycle, increment xoff xoff += xincrement; //n = nInp; scale(sCube); //fill(255); noFill(); stroke(255); pushMatrix(); //println(x); translate(x, y, 0); beginShape(QUADS); vertex(-1+n, 1+n, 1+n); vertex( 1+n, 1+n, 1+n); vertex( 1+n, -1+n, 1+n); vertex(-1+n, -1+n, 1+n); vertex( 1-n, 1-n, 1-n); vertex( 1-n, 1-n, -1-n); vertex( 1-n, -1-n, -1-n); vertex( 1-n, -1-n, 1-n); vertex( 1+n, 1+n, -1+n); vertex(-1+n, 1+n, -1+n); vertex(-1+n, -1+n, -1+n); vertex( 1+n, -1+n, -1+n); vertex(-1, 1, -1); vertex(-1, 1, 1); vertex(-1, -1, 1); vertex(-1, -1, -1); vertex(-1, 1, -1); vertex( 1, 1, -1); vertex( 1, 1, 1); vertex(-1, 1, 1); vertex(-1, -1, -1); vertex( 1, -1, -1); vertex( 1, -1, 1); vertex(-1, -1, 1); endShape(); popMatrix(); } }