The best example I can think of for what I mean is coding something similar to a ferris wheel. Say we have:
function draw() {
background(20);
push();
rotateZ(frameCount * 0.01);
fill(255, 0, 0);
box(300, 5, 5);
pop();
push();
rotateZ(frameCount * -0.01);
fill(0, 0, 255);
sphere(20, 20);
pop();
}
Is there a way to “pin” the sphere to one end of the long “stick” box, so that its rotations etc all happen relative to the end of the box? Basically can you create groups of shapes where if I transform the parent, all children will stay in their same position relative to the parent shape, and can also have their own transformations.
Is this achievable?
EDIT: It seems this is done by nesting with push() and pop(), here’s the working code:
function draw() {
background(20);
fill(200);
push();
translate(0, 50, 0);
rotateY(-frameCount * .01);
push();
translate(75, 0, 0);
box(150, 5, 5);
push();
translate(75, 0, 0);
rotateX(frameCount * .01);
rotateY(frameCount * .01);
rotateZ(frameCount * .01);
box(30, 30);
pop();
pop();
pop();
}