Sequence of rotation

It does if you are not using translations between the rotations. If not, no. You can try this out with a physical object in your hand to confirm – rotate a stick of butter 90 x, then 90 y, or 90 y then 90 x, and it ends up in the same orientation. If you translate, however,

(See expanded examples below) IN GENERAL everything is order-dependent.

You may want to make sure that you have completely worked out the 2D case, then add another dimension of rotation to tilt the axes.

For example, here is a very very simple toy model which uses pushes and pops, implemented in the 2D case.

float spin;

void setup() {
  size(400, 400);
  rectMode(CENTER);
  ellipseMode(CENTER);
}
void draw() {
  background(0);
  spin = (spin + 0.012);

  translate(width/2, height/2);

  // planet
  translate(0, 0);
  rotate(spin);
  rect(0, 0, 50, 50);

  // moon A
  pushMatrix();
    rotate(spin + PI/3);
    translate(100, 0);
    rect(0, 0, 25, 25);

    // moon A sattelite 1
    pushMatrix();
      rotate(spin/2 + PI);
      translate(40, 0);
      rect(0, 0, 12, 12);
    popMatrix();

    // moon A sattelite 2
    pushMatrix();
      rotate(spin + PI/3);
      translate(50, 0);
      rect(0, 0, 10, 10);
    popMatrix();
  
  popMatrix();

  // moon B
  pushMatrix();
    rotate(spin/2 + PI/5);
    translate(140, 0);
    rect(0, 0, 20, 20);
  popMatrix();

}

08%20PM

Notice how each starting angle for a child is relative, rather than absolute.

If you want to get into more detail about debugging your code, you may want to share example code here and describe how specifically you can tell it “looks wrong”, and what part of the code you think is doing that.

1 Like