1

One can translate by x and y distances in processing relative to the frame of reference with the translate() function.

Is there a function that one can use to translate to an absolute coordinate in world space? For instance, can one translate to the coordinate (20, 30) relative to the window regardless of where your frame of reference has previously translated to?

dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206

1 Answers1

0

When you use translate for the first time in your code, you're actually translating the whole coordinate system. If you want to draw an object at a position/transformation independently (without) affecting following transformations, you should isolate that within pushMatrix()/popMatrix() calls.

here's a v. basic example:

pushMatrix();
translate(50,50);
rect(0,0,50,50);
popMatrix();

translate(20,20);
rect(0,0,20,20);

The big square(50x50) is drawn first at position 50,50, but the translation is isolated between pushMatrix()/popMatrix() calls, so when we call translate(20,20) a translation will be performed from 0,0, not from 50,50 which means we get a small box drawn at 20,20, not 70,70.

George Profenza
  • 50,687
  • 19
  • 144
  • 218