very good,
now i would recommend
not construct the shape at runtime ( inside draw ),
and play with stroke for visibility ( pls, change back )
add instead for test/inspect not use the auto rotate,
here i try my PTZ
// https://discourse.processing.org/t/semicircle-drawing-producing-artifacts/8444
PShape myshape;
void setup() {
size(600, 600, P3D);
make_myshape(100, 30, 30);
info_print();
}
void draw() {
background(0, 0, 80);
PTZ();
}
void make_myshape(float radius, float slicesA, float slicesB) {
float a, b, x, y, z, da, db;
da = TWO_PI / slicesA;
db = HALF_PI / slicesB;
myshape = createShape();
myshape.beginShape(QUAD_STRIP);
myshape.fill(0, 255, 0, 127);
// myshape.noStroke();
myshape.stroke(0, 255, 0, 127); // test visibility
for (b=0; b < HALF_PI-db; b += db) {
for (a=0; a < TWO_PI; a += da) {
x = cos(a) * cos(b) * radius;
y = sin(a) * cos(b) * radius;
z = sin(b) * radius;
myshape.vertex(x, y, z);
x = cos(a) * cos(b+db) * radius;
y = sin(a) * cos(b+db) * radius;
z = sin(b+db) * radius;
myshape.vertex(x, y, z);
}
}
myshape.endShape();
}
//______________________________________
void draw_object() { //_________________called by / from inside PTZ
shape(myshape, 0, 0);
}
//_____________________________________ PTZ tab
int mode = 0;
float Zmag = 2;
int Zaxis=-10;
float Xmag, Ymag = 0;
float newXmag, newYmag = 0;
int newZmag = 0;
int zoomf = 3;
float newxpos, newypos = 0; // for PAN
float xposd, yposd = 0; // for PAN
//_________________________________________________________________ ROTATE / TILDE and MOVE / PAN
void mousePressed() {
if (mouseButton == LEFT) {
mode=1;
} // ORBIT
else if (mouseButton == RIGHT) {
mode=2;
} // PAN
// else if (mouseButton == CENTER) { mode=3; } // zoom mouse wheel works same , presssed or not
}
//_________________________________________________________________ mouse PT end
void mouseReleased() {
mode = 0;
}
//_________________________________________________________________ mouseWheel ZOOM
void mouseWheel(MouseEvent event) {
int newZmag = event.getCount(); // +- 1
//if (Zmag > 10) { Zmag += newZmag * 5; } else { Zmag += newZmag; }// from 1 to 11 go in step 1 else in step 5
Zmag += newZmag*0.3;
//println("Zmag: "+nf(Zmag, 1, 2));
}
void keyPressed() {
if ( keyCode == UP ) Ymag -= 0.1 ;
if ( keyCode == DOWN ) Ymag += 0.1 ;
if ( keyCode == RIGHT) Xmag -= 0.1 ;
if ( keyCode == LEFT ) Xmag += 0.1 ;
if ( keyCode == 16 ) Zmag -= 0.5 ;
if ( keyCode == 11 ) Zmag += 0.5 ;
//println("key: "+key); println("keyCode: "+keyCode);
}
//_________________________________________________________________ Pan Tilde Zoom
void PTZ() {
pushMatrix();
translate(width/2, height/2, Zaxis);
// get new mouse operation
if ( mode == 2 ) { // PAN ( right mouse button pressed)
xposd = (mouseX-float(width/2));
yposd = (mouseY-float(height/2));
}
newxpos = xposd;// xposd=0;
newypos = yposd;// yposd = 0;
translate(newxpos, newypos, 0); // move object
if ( mode == 1 ) { // ORBIT ( left mouse button pressed)
newXmag = mouseX/float(width) * TWO_PI;
newYmag = mouseY/float(height) * TWO_PI;
float diff = Xmag-newXmag;
if (abs(diff) > 0.01) Xmag -= diff/4.0;
diff = Ymag-newYmag;
if (abs(diff) > 0.01) Ymag -= diff/4.0;
}
rotateX(-Ymag);
rotateY(-Xmag);
scale(Zmag);
draw_object(); // THE OBJECT see main tab
popMatrix();
}
//_______________________________________________ SETUP PRINT INFO
void info_print() {
println("PTZ info:");
println("key UP DOWN RIGHT LEFT -> rotate // key PAGE UP DOWN -> zoom");
println("mouse LEFT press drag up down right left -> rotate // mouse RIGHT press -> move // mouse WHEEL turn -> zoom");
}