Can you please tell me what I am doing wrong?

Hi there!
I’m a real real beginner student…
I’ve got a problem while doing my homework.
the task is to

  1. make 3D QUAD that can be textured in ‘class’ using
    beginShape(QUADS), endShape(), vertex(x,y,z,tx,ty), texture().

  2. make step 1 with ‘class array’ and use ‘for(){ }’ to create 3 object

  3. prepare the texture image with ‘PImage’,
    and the image file name using ‘String’ that’s going to be used inside ‘loadImage(" ")’

  4. randomly bring the img file name from the ‘String
    and use it as a texture image of each 3 class objects that’s been made in step 2.

the problem is that I have a feeling that I’m doing this in a completely… wrong way…
I’ve been working on this for like… a week and still got no clue…
It’s an uncompleted version, but still could you please tell me
what parts should I fix in here?

<PImage img;
String pic= {“pk.png”, “bl.png”, “yl.png”};

void setup(){
size(800, 500, P3D);
background(0);
noStroke();

fl tx= new fl[3];
for(int i=0; i<tx.length; i++) {
img= loadImage(random(pic.length));
}

textureMode(NORMAL);
camera(70.0, 35.0, 120.0, 50.0, 50.0, 0.0,
0.0, 1.0, 0.0);
}

void draw(){
for(int i=0; i<tx.length; i++) {
TexturedQuad(tx);
}
}

class fl {

void TextureQuad(PImage img){
beginShape(QUADS);
texture(img);
vertex(-1, -1, 1, 0, 0);
vertex( 1, -1, 1, 1, 0);
vertex( 1, 1, 1, 1, 1);
vertex(-1, 1, 1, 0, 1);
endShape();

beginShape(QUADS);
texture(img);
vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1,  1, 1, 1);
vertex(-1, -1,  1, 0, 1);
endShape();

beginShape(QUADS);
texture(img);
vertex( 1, -1,  1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1,  1, -1, 1, 1);
vertex( 1,  1,  1, 0, 1);
endShape();

}>

here is a version that at least does SOMETHING

BUT as you said, the principle of a class is not applied correctly.

  • inside a class should be only ONE shape. Remember that the class is the cookie maker and the objects the cookies. When you have an array of the class, each slot in the array is one object. The class is the same for all of the 3. But each object has another position.
  • by using an array of 3 shapes of the class you draw it in 3 different positions
  • use x,y in the class as variables
  • you form is over 0,0; so you need pushMatrix and translate and scale and popMatrix
    your class doesn’t have a constructor or variables (x,y). Please read: Objects / Processing.org

Old Version

here is a version that at least does SOMETHING

// ‘class array’ 
QUAD3D[] tx = new QUAD3D[3];

String[] pic = {
  "pk.png", 
  "bl.png", 
  "yl.png"
};

PImage[] img = new PImage[3];

void setup() {
  size(800, 500, P3D);
  background(0);
  noStroke();

  for (int i=0; i<tx.length; i++) {
    img[i] = loadImage (pic[int(random(pic.length))]);
    tx[i] = new QUAD3D();
  }

  for (int i=0; i<tx.length; i++) {
    println(img[i].height);
  }

  textureMode(NORMAL);
  camera(70.0, 35.0, 120.0, 
    50.0, 50.0, 0.0, 
    0.0, 1.0, 0.0);
}

void draw() {

  scale (16); 

  for (int i=0; i<tx.length; i++) {
    tx[i].TextureQuad(img[i]);
  }
}

//==============================================================

class QUAD3D {

  void TextureQuad(PImage img) {

    beginShape(QUADS);
    texture(img);
    vertex(-1, -1, 1, 0, 0);
    vertex( 1, -1, 1, 1, 0);
    vertex( 1, 1, 1, 1, 1);
    vertex(-1, 1, 1, 0, 1);
    endShape();

    beginShape(QUADS);
    texture(img);
    vertex(-1, -1, -1, 0, 0);
    vertex( 1, -1, -1, 1, 0);
    vertex( 1, -1, 1, 1, 1);
    vertex(-1, -1, 1, 0, 1);
    endShape();

    beginShape(QUADS);
    texture(img);
    vertex( 1, -1, 1, 0, 0);
    vertex( 1, -1, -1, 1, 0);
    vertex( 1, 1, -1, 1, 1);
    vertex( 1, 1, 1, 0, 1);
    endShape();
  }
}//class
//

1 Like

Thank you so much for your help!
I read your explanation and tried it couple more times, and finally made it!
Thanks!!

1 Like

Really?

There is so much to do.

Can I see your entire code please?

1 Like