Quad_Strip: Okay, but how to do a line break in a bigger grid with Quad_Strip?

Hello all,

the reference has Quad_Strip, but only for one line of quads.

How can I make a bigger grid of QUAD_STRIP?

Actually, the main problem is the line break at the end of one line in the grid. I don’t want the right side to be connected with the left side of the next line in the grid.

Part of a MUCH bigger project, but here is an example.
As you can see, the values are in MyResults, which is a 2D array (grid) of PVector.

I struggle with the vertexPV() command .

Or do I have to say endshape() after each line in the grid which would be rather uncool?

Thank you!!!

void ShowLookupAsGrid() {
  // nice
  colorMode(RGB, 400);
  noStroke();
  if ((MaxindexI <= 0) && (MaxindexJ <= 0)) { 
    ShowSpecialMessage("LookUp-Table not defined.");
  } else {
    beginShape(QUAD_STRIP); 
    noStroke();

    for (int j = 0; j < MaxindexJ; j = j+1) {
      for (int i = 0; i < MaxindexI; i = i+1) {

        fill (2+abs(MyResults[i][j].x), 2+abs(MyResults[i][j].y), 2+abs(MyResults[i][j].z));

        if (keyPressed) {
          vertexPV(MyResults[i][j]);      
          vertexPV(MyResults[i][j+1]);
        } else {
          boxPV(MyResults[i][j]);
        }
      } // j
    } //i
    endShape(CLOSE);
  } // else
} // ShowGraph2

void vertexPV(PVector pv) {
  vertex(pv.x, pv.y, pv.z);
}

void pointPV(PVector pv) {
  point(pv.x, pv.y, pv.z);
}

void boxPV(PVector pv) {
  pushMatrix();
  translate(pv.x, pv.y, pv.z);
  box(2); 
  popMatrix();
}

void spherePV(PVector pv) {
  pushMatrix();
  translate(pv.x, pv.y, pv.z);
  sphere(2); 
  popMatrix();
}

As you can see it looks awful, because the lines are connected:

compared to what it’s meant to look like (here I just use box() command)

Thank you all!

Warm regards,

Chrisir

1 Like

Hi @Chrisir ,

I would just use QUADS.

int resolution = 32;
PVector[] points = new PVector[resolution * resolution];
color[] colors = new color[resolution * resolution];
float scale = 250.0;

void setup() {
  size(720, 405, P3D);
  int len = points.length;
  for (int i = 0; i < len; ++i) {
    points[i] = new PVector();
  }
}

void draw() {
  surface.setTitle(nfs(frameRate, 1, 1));

  background(#202020);
  perspective(PI / 3.0, -width / (float)height, 0.001, 1000.0);
  camera(
    height, -height, height,
    0.0, 0.0, 0.0,
    0.0, 0.0, -1.0);
  lights();

  strokeWeight(1.0);
  stroke(#ff0000);
  line(0.0, 0.0, 0.0, 100.0, 0.0, 0.0);
  stroke(#00ff00);
  line(0.0, 0.0, 0.0, 0.0, 100.0, 0.0);
  stroke(#0000ff);
  line(0.0, 0.0, 0.0, 0.0, 0.0, 100.0);

  // Calc points.
  float toFac = 1.0 / (resolution - 1.0);
  int len = points.length;
  for (int k = 0; k < len; ++k) {
    int i = k / resolution;
    int j = k % resolution;

    float iFac = i * toFac;
    float jFac = j * toFac;

    float iSigned = iFac + iFac - 1.0;
    float jSigned = jFac + jFac - 1.0;
    float fxy = iSigned * iSigned * jSigned;

    float x = iSigned * scale;
    float y = jSigned * scale;
    float z = fxy * scale;

    int red = (int)(0.5 + 255.0 * iFac);
    int green = (int)(0.5 + 255.0 * jFac);
    int blue = (int)(0.5 + 255.0 * (fxy * 0.5 + 0.5));

    colors[k] = 0xff000000 | (red << 0x10) | (green << 0x08) | blue;
    points[k].set(x, y, z);
  }

  // Draw.
  if (mousePressed) {
    strokeWeight(1.0);
    stroke(#ffffff);
  } else {
    noStroke();
  }

  rotateZ(frameCount * 0.01);
  beginShape(QUADS);
  for (int i = 0; i < resolution - 1; ++i) {
    int noff0 = i * resolution;
    int noff1 = noff0 + resolution;
    for (int j = 0; j < resolution - 1; ++j) {
      int v00 = noff0 + j;
      int v10 = v00 + 1;
      int v01 = noff1 + j;
      int v11 = v01 + 1;

      PVector av = points[v00];
      PVector bv = points[v10];
      PVector cv = points[v11];
      PVector dv = points[v01];

      color ac = colors[v00];
      color bc = colors[v10];
      color cc = colors[v11];
      color dc = colors[v01];

      fill(ac);
      vertex(av.x, av.y, av.z);
      fill(bc);
      vertex(bv.x, bv.y, bv.z);
      fill(cc);
      vertex(cv.x, cv.y, cv.z);
      fill(dc);
      vertex(dv.x, dv.y, dv.z);
    }
  }
  endShape(CLOSE);
}

That way you can control how you access and assign color to the four corners of each square.

Best,
Jeremy

4 Likes

Yeah, thanks! I was hoping to use QuadStrip because then you will have only half the vertexes

But anyway, great sketch!

I was working further on this!

Thank you,

Chrisir

1 Like

it is magic :star_struck:

1 Like

Thanks again!

This resulted in: 3D: Some stuff Trigonometry

1 Like