Ignore changes to matrix

Is there a clever way to ignore/reset any changes to the matrix that happen outside of a push/popMatrix? Say I draw some objects normally using push/popMatrix(), then I’m calculating various things and have some debug views that are loaded as PGraphic layers… now I want to rotate the entire canvas 90° to match a 90° rotated screen. BTW, this would be executed by a library, so I’m trying to have a function simply add the following code to the top of the draw:

  translate(width/2, height/2);
  translate(-width/2, -height/2);

However that then throws off the position of the debug views later in the code. Of course I could wrap big push/popMatrix() around everything prior to the debug views, but there must be a better way. I was trying to find something that could tell the images to ignore any previous changes to the matrix… i tried resetMatrix() – but that didn’t do what I expected… I also tried storing the current matrix using getMatrix() within a variable and reloading it with applyMatrix() – but that too showed everything far smaller than expected. Looking to place one line of code before those debug images that undoes any translate/rotate/scale changes. Anyone know the proper way to do this?

Wrapping it in one big pushMatrix()/popMatrix() arround everything is the better/proper way.

Mostly solved the problem by changing the sketch size based on rotation and swapping some X/Y coordinates within library… nevertheless, still very curious if there’s an easy solution for ignoring/reseting these transformation changes. If not, could be a useful feature to consider, perhaps defaultMatrix()?

Yeah, imagined that to be the case… but still hopeful some feature exists or could exist to do this.

What about using instances of the class PMatrix2D (or PMatrix3D) to store transformations? You can multiply them with each other using apply and transform vectors with mult. In addition to the PGraphics functions you’ve mentioned, you can use getMatrix (there are three versions of this function) and setMatrix.

1 Like