Im trying to center this cluster of cubes, to be able to rotate them on the vertical axis, currently it rotate by using the corner as axis, i tried a lot instruments, translate, ortho, rotate, i really need a hand to figure out how get it clean centered, to be able to rotate it.
May ask if can you teach me how to set the right position by using this example? Basically to learn i try to reproduce this famous sketch :https://www.instagram.com/p/BfGNVtSh48f/?utm_source=ig_embed&utm_campaign=embed_video_watch_again
CubeClass[][][] cube = new CubeClass[8][8][8];
float d = 8;
float howMany = 0;
void setup(){
size(400, 400, P3D);
frameRate(60);
pixelDensity(displayDensity());
for (int x = 0; x < 8; x=x+1){
for (int y = 0; y < 8; y=y+1){
for (int z = 0; z < 8; z=z+1){
cube[x][y][z] = new CubeClass(x*16,y*16,z*16, parseBoolean(int(random(0,1.3))));
}}}
}
void draw(){
background(100);
noStroke();
howMany = howMany+ 0.01;
ortho(-width/2, width/2, -height/2, height/2); // Same as ortho()
translate(width/2 -16, height/2 -16, 0);
rotateX(-PI/6);
rotateY(PI/3 + howMany);
for (int x = 0; x < 8; x=x+1){
for (int y = 0; y < 8; y=y+1){
for (int z = 0; z < 8; z=z+1){
cube[x][y][z].update();
}}}
}
class CubeClass {
float ypos, xpos, zpos;
boolean oN;
CubeClass (float x, float y, float z, boolean on) {
ypos = y;
xpos = x;
zpos = z;
oN = on;
}
void update() {
if(oN){
pushMatrix();
translate(xpos,ypos,zpos);
beginShape(QUADS);
fill(255,0,0);
vertex(-d, -d, d);
vertex( d, -d, d);
vertex( d, d, d);
vertex(-d, d, d);
endShape();
// Back
beginShape(QUADS);
fill(255,255,0);
vertex( d, -d, -d);
vertex(-d, -d, -d);
vertex(-d, d, -d);
vertex( d, d, -d);
endShape();
// Bottom
beginShape(QUADS);
fill( 255,0,255);
vertex(-d, d, d);
vertex( d, d, d);
vertex( d, d, -d);
vertex(-d, d, -d);
endShape();
// Top
beginShape(QUADS);
fill(0,255,0);
vertex(-d, -d, -d);
vertex( d, -d, -d);
vertex( d, -d, d);
vertex(-d, -d, d);
endShape();
// Right
beginShape(QUADS);
fill(0,0,255);
vertex( d, -d, d);
vertex( d, -d, -d);
vertex( d, d, -d);
vertex( d, d, d);
endShape();
// Left
beginShape(QUADS);
fill(0,255,255);
vertex(-d, -d, -d);
vertex(-d, -d, d);
vertex(-d, d, d);
vertex(-d, d, -d);
endShape();
popMatrix();
}
} }