I’ve got this PShape Group composed of four sided polygons which have been arranged in a circle and I’m trying to access their coordinates so I can check if the mouse is over each one individually. The problem is that each polygon shows the same coordinates for its vertices.
How can I get the coordinates of each polygon’s vertices “as displayed” when they have been translated in this way when the Group is created?
Edit: I’m not asking for advice about how to check for mouse over, just how to obtain the correct locations of the shape vertices after translation.
the println() statement in setup() outputs:
wheelGroup child: 0 Vertex: 0 [ 230.0, 0.0, 0.0 ]
wheelGroup child: 0 Vertex: 1 [ 199.18584, 115.0, 0.0 ]
wheelGroup child: 0 Vertex: 2 [ 112.5833, 65.0, 0.0 ]
wheelGroup child: 0 Vertex: 3 [ 130.0, 0.0, 0.0 ]
wheelGroup child: 1 Vertex: 0 [ 230.0, 0.0, 0.0 ]
wheelGroup child: 1 Vertex: 1 [ 199.18584, 115.0, 0.0 ]
wheelGroup child: 1 Vertex: 2 [ 112.5833, 65.0, 0.0 ]
wheelGroup child: 1 Vertex: 3 [ 130.0, 0.0, 0.0 ]
… etc.
Wheel wheel;
float speed;
color[] RYB = { #FE2712, #FC600A, #FB9902, #FCCC1A,
#FEFE33, #B2D732, #66B032, #347C98,
#0247FE, #4424D6, #8601AF, #C21460 };
void setup() {
size(800, 480);
wheel = new Wheel(new PVector(width/2, height/2), 460, 260, 12);
speed = 200;
for (int s = 0; s < wheel.wheelGroup.getChildCount(); s++) {
for (int n = 0; n < wheel.segments[s].getVertexCount(); n++) {
println("wheelGroup child:", s, "Vertex:", n, wheel.segments[s].getVertex(n));
}
}
}
void draw() {
background(50);
wheel.display();
}
class Wheel {
PShape wheelGroup;
PShape[] segments;
PVector location;
float oD, iD, angle;
int nSides;
Wheel(PVector location, float oD, float iD, int nSides) {
segments = new PShape[nSides];
wheelGroup = createShape(GROUP);
this.location = location;
angle = TWO_PI / nSides;
this.oD = oD;
this.iD = iD;
this.nSides = nSides;
createWheel();
}
void display() {
pushMatrix();
translate(location.x, location.y);
//rotate(frameCount / speed);
shape(wheelGroup);
popMatrix();
}
void createWheel() {
for (int n = 0; n < nSides; n++) {
segments[n] = createSegment(n);
segments[n].rotate(TWO_PI / nSides * n);
wheelGroup.addChild(segments[n]);
}
}
PShape createSegment(int n) {
PShape segment;
segment = createShape();
segment.beginShape();
for (float a = 0; a <= angle; a += angle) {
float outx = 0 + cos(a) * oD/2;
float outy = 0 + sin(a) * oD/2;
segment.vertex(outx, outy);
}
for (float b = angle; b >= 0; b -= angle) {
float inx = 0 + cos(b) * iD/2;
float iny = 0 + sin(b) * iD/2;
segment.vertex(inx, iny);
}
segment.endShape(CLOSE);
segment.setStroke(RYB[n]);
segment.setFill(RYB[n]);
return segment;
}
}