topical media & game development

talk show tell print

graphic-processing-site-examples-3D-Transform-CubesWithinCube-Cube.pde / pde



  
  // Custom Cube Class
  
  class Cube{
    PVector[] vertices = new PVector[24];
    float w, h, d;
  
    // Default constructor
    Cube(){ }
  
    // Constructor 2
    Cube(float w, float h, float d) {
      this.w = w;
      this.h = h;
      this.d = d;
  
      // cube composed of 6 quads
      //front
      vertices[0] = new PVector(-w/2,-h/2,d/2);
      vertices[1] = new PVector(w/2,-h/2,d/2);
      vertices[2] = new PVector(w/2,h/2,d/2);
      vertices[3] = new PVector(-w/2,h/2,d/2);
      //left
      vertices[4] = new PVector(-w/2,-h/2,d/2);
      vertices[5] = new PVector(-w/2,-h/2,-d/2);
      vertices[6] = new PVector(-w/2,h/2,-d/2);
      vertices[7] = new PVector(-w/2,h/2,d/2);
      //right
      vertices[8] = new PVector(w/2,-h/2,d/2);
      vertices[9] = new PVector(w/2,-h/2,-d/2);
      vertices[10] = new PVector(w/2,h/2,-d/2);
      vertices[11] = new PVector(w/2,h/2,d/2);
      //back
      vertices[12] = new PVector(-w/2,-h/2,-d/2); 
      vertices[13] = new PVector(w/2,-h/2,-d/2);
      vertices[14] = new PVector(w/2,h/2,-d/2);
      vertices[15] = new PVector(-w/2,h/2,-d/2);
      //top
      vertices[16] = new PVector(-w/2,-h/2,d/2);
      vertices[17] = new PVector(-w/2,-h/2,-d/2);
      vertices[18] = new PVector(w/2,-h/2,-d/2);
      vertices[19] = new PVector(w/2,-h/2,d/2);
      //bottom
      vertices[20] = new PVector(-w/2,h/2,d/2);
      vertices[21] = new PVector(-w/2,h/2,-d/2);
      vertices[22] = new PVector(w/2,h/2,-d/2);
      vertices[23] = new PVector(w/2,h/2,d/2);
    }
    void create(){
      // Draw cube
      for (int i=0; i<6; i++){
        beginShape(QUADS);
        for (int j=0; j<4; j++){
          vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z);
        }
        endShape();
      }
    }
    void create(color[]quadBG){
      // Draw cube
      for (int i=0; i<6; i++){
        fill(quadBG[i]);
        beginShape(QUADS);
        for (int j=0; j<4; j++){
          vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z);
        }
        endShape();
      }
    }
  }
  
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.