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

PShape within a Class

$
0
0

I am trying to create a lot of cubes. If I just put createShape inside my Setup, then I get 8000 references to the same cube, so I want to make 8000 children cubes that I can modify the translation and rotation of each one. I am missing something with the Class setup as I am getting a Type MisMatch.

I would appreciate any insight into what I might be doing wrong. Thanks for the help.

import processing.opengl.*;
import peasy.*;
PeasyCam cam;
PShape world;
float CS = .25;
int CPS = 20;
int TotalCubes=CPS*CPS*CPS;
float offset = CPS/2;
int CC = 0;  //CubeCount
PShape tempcube;


void setup()  {
  size(2100, 2100, P3D);
  cam = new PeasyCam(this, 15000);
  noStroke();

 println("Making World");
  world=createShape(GROUP);
  for (int i = 0; i < TotalCubes; i++) {
  tempcube = new MyCube();
    world.addChild(tempcube);
          println(i);          }

println("Translating cubes");
  for (int i = 0; i < CPS; i++) {
      for (int j = 0; j < CPS; j++) {
          for (int k = 0; k < CPS; k++) {
          PShape tempcube = world.getChild(CC);
          tempcube.translate(i-offset,j-offset,k-offset);
          println(CC++, tempcube);     }}}
 } // end setup

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

class MyCube {
PShape output;

MyCube() {
  int size = 1;
  println("Making CUBE");
  PShape output = createShape();
    output.beginShape(QUADS);
    output.fill(0x44FF0000); output.vertex(-CS,  CS,  CS);output.vertex( CS,  CS,  CS);output.vertex( CS, -CS,  CS);output.vertex(-CS, -CS,  CS);
    output.fill(0x4400FF00); output.vertex( CS,  CS,  CS);output.vertex( CS,  CS, -CS);output.vertex( CS, -CS, -CS);output.vertex( CS, -CS,  CS);
    output.fill(0x440000FF); output.vertex( CS,  CS, -CS);output.vertex(-CS,  CS, -CS);output.vertex(-CS, -CS, -CS);output.vertex( CS, -CS, -CS);
    output.fill(0x44FFFF00); output.vertex(-CS,  CS, -CS);output.vertex(-CS,  CS,  CS);output.vertex(-CS, -CS,  CS);output.vertex(-CS, -CS, -CS);
    output.fill(0x4400FFFF); output.vertex(-CS,  CS, -CS);output.vertex( CS,  CS, -CS);output.vertex( CS,  CS,  CS);output.vertex(-CS,  CS,  CS);
    output.fill(0x44FF00FF); output.vertex(-CS, -CS, -CS);output.vertex( CS, -CS, -CS);output.vertex( CS, -CS,  CS);output.vertex(-CS, -CS,  CS);
    output.endShape(CLOSE);
    return output;
  } // end constructor
}// end MyCube

Viewing all articles
Browse latest Browse all 2896

Trending Articles