Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

setVisible

$
0
0

I have the following program creates cubes and changes them. I am trying to make the cubes invisible until they are activated in updatecells, but I want them part of my overall VBO that is created during setup to help performance. I have tried putting the "setVisible( false )" code in many places, but cannot seem to get it to work. I have tried making each side of the cubes invisible separately, and that did not work either. Any suggestions are welcome.

import processing.opengl.*;
import peasy.*;

PeasyCam cam;
PShape world;
float CS = .25;
int CPS = 10;
int totalcubes = CPS*CPS*CPS;
float offset = CPS/2;
color colors[]= {0x88FF0000,0x8800FF00,0x880000FF,0x88FFFF00,0x8800FFFF,0x88FF00FF};
int dice_orientations[][][]={{{1,6,2,4,5,3},{1,6,4,5,3,2},{1,6,5,3,2,4},{1,6,3,2,4,5}},
                             {{6,1,2,3,5,4},{6,1,3,5,4,2},{6,1,5,4,2,3},{1,6,4,2,3,5}},
                             {{3,4,5,6,2,1},{3,4,6,2,1,5},{3,4,2,1,5,6},{3,4,1,5,6,2}},
                             {{4,3,1,2,6,5},{4,3,2,6,5,1},{4,3,6,5,1,2},{4,3,5,1,2,6}},
                             {{2,5,4,6,3,1},{2,5,6,3,1,4},{2,5,3,1,4,6},{2,5,1,4,6,3}},
                             {{5,2,1,3,6,4},{5,2,3,6,4,1},{5,2,6,4,1,3},{5,2,4,1,3,6}}};
int rcolor;
void setup() {
  size(2100,2100, P3D);
  cam = new PeasyCam(this, 150*CPS);
  noStroke();

  print("Making World   ");
  world = createShape(GROUP);
  for (int i = 0; i < CPS; i++) {
    for (int j = 0; j < CPS; j++) {
      for (int k = 0; k < CPS; k++) {
        MyCube cube = new MyCube(i - offset, j - offset, k - offset);
        world.addChild(cube.output);
        }}print("-");}
  println("   done");} // end setup

 void draw() {
  background(127);
  scale(95);
  shape(world, 0, 0);
  updatecells();
} // end draw


 void updatecells(){
  PShape cube = world.getChild(int(random(totalcubes)));
  color sidecolor;
  int tempfront = int(random(6));
  int temptop = int(random(4));
  int tempside = 0;

  for (int side=0; side < 6; side++) {
    tempside=dice_orientations[tempfront][temptop][side];
    sidecolor=colors[tempside-1];
    for (int V=0; V < 4; V++) {
      cube.setFill(side*4+V ,sidecolor);
     } // end V
   } // end side
 } // end updatecells



// could just be a method, returning PShape
class MyCube {
  PShape output;

  MyCube(float x, float y, float z) { // <- new arguments
    int size = 1;
    output = createShape();
    output.translate(x, y, z); // <- new tanslate
    output.beginShape(QUADS);
    output.fill(colors[0]);
    output.vertex(-CS, CS, CS);output.vertex( CS, CS, CS);output.vertex( CS,-CS, CS);output.vertex(-CS,-CS, CS);
    output.fill(colors[1]);
    output.vertex( CS, CS, CS);output.vertex( CS, CS,-CS);output.vertex( CS,-CS,-CS);output.vertex( CS,-CS, CS);
    output.fill(colors[2]);
    output.vertex( CS, CS,-CS);output.vertex(-CS, CS,-CS);output.vertex(-CS,-CS,-CS);output.vertex( CS,-CS,-CS);
    output.fill(colors[3]);
    output.vertex(-CS, CS,-CS);output.vertex(-CS, CS, CS);output.vertex(-CS,-CS, CS);output.vertex(-CS,-CS,-CS);
    output.fill(colors[4]);
    output.vertex(-CS, CS,-CS);output.vertex( CS, CS,-CS);output.vertex( CS, CS, CS);output.vertex(-CS, CS, CS);
    output.fill(colors[5]);
    output.vertex(-CS,-CS,-CS);output.vertex( CS,-CS,-CS);output.vertex( CS,-CS, CS);output.vertex(-CS,-CS, CS);
    output.setVisible( false );
    output.endShape(CLOSE);
  } // end constructor
}// end MyCube

Viewing all articles
Browse latest Browse all 2896

Trending Articles