Hi there! I’ve been trying to code a torus and, while I have found valid examples, I still don’t understand why my code does not work. I’m sure it’s related to transformations and must’ve misunderstood something about them but after reading the reference and seeking up examples I’ve made no progress
I tried to position the vertices through transformations in a function but it appears as if they were not read and all the vertices ended up one on top of another.
Any help or suggestions are welcome!
Thanks!!
import peasy.*;
float r1, r2;
PeasyCam cam;
void setup() {
size(900, 900, P3D);
cam = new PeasyCam(this, 500);
}
void draw() {
background(57);
r1 = 200;
r2 = 100;
rotateY(frameCount*PI/370);
rosquilla(r1, r2);
}
void rosquilla(float r1, float r2) {
float sides = 20;
float inc1 = TWO_PI/sides;
float sides2 = 8;
float inc2 = TWO_PI/sides2;
beginShape(QUAD_STRIP);
//noFill();
stroke(255, 175, 100);
pushMatrix();
for (int i = 0; i < sides; i++) { // ihave some sort of problem with transformations
pushMatrix();
rotateY(inc1 * i);
translate(r1, 0, 0);
for (int j = 0; j < sides2; j++) {
vertex(r2 * cos(inc2 * j), r2 *sin(inc2 * j), 0 );
pushMatrix();
rotateY(inc1 * (i + 1));
vertex(r2 * cos(inc2 * j), r2 *sin(inc2 * j), 0);
popMatrix();
}
popMatrix();
}
popMatrix();
endShape();
}