Type mismatch: cannot convert from float to int

Other than point and line, triangle doesn’t know a 3D version as you attempted.

Here is a pyramid though (base with 3 corners):

see : Find centre of pyramid and rotate from there, not the apex - #3 by Chrisir

And with a Pyramid class

  • its base with 4 corners (iirc) EDITED
  • The position you translate the pyramid to is exactly in the 3D center of the pyramid (like with box and sphere in P3D)
// Pyramid class

Pyramid pyramid;  

void setup() {
  size(768, 768, P3D);
  pyramid = new Pyramid( 200, height-221, -100 );
}

void draw() {
  background(0);
  lights(); 
  pyramid.display();
}

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

class Pyramid {

  float x, y, z; 
  PVector[] basePts = new PVector[4];

  //constr
  Pyramid( float x_, float y_, float z_) {
    x=x_;
    y=y_;
    z=z_;

    for (int i = 0; i < 4; i++ ) {
      float ang = TWO_PI * i / 4;
      basePts[i] = new PVector(
        cos(ang) * 90, 
        90/2.0, 
        sin(ang) * 90  );
      println(basePts[i]);
    } // for
  } // constr

  void display() {
    translate(x, y, z);
    // rotateX(radians(frameCount/8 % 360));
    // rotateY(radians(frameCount/2 % 360));

    fill(255);
    strokeWeight(3);
    stroke(123);

    //sides
    beginShape(TRIANGLES);
    for (int i = 0; i < 4; i++ ) {
      int i2 = (i+1) % 4;
      vertex(basePts[i].x, basePts[i].y, basePts[i].z);
      vertex(basePts[i2].x, basePts[i2].y, basePts[i2].z);
      vertex(0, -90/2.0, 0 );
    }
    endShape();//sides

    // show base
    fill(255, 0, 9); 
    beginShape(); //base
    for (int i = 0; i < 4; i++ ) {
      vertex(basePts[i].x, basePts[i].y, basePts[i].z);
    }
    endShape(CLOSE);
  } //method
  //
} // class
//
2 Likes