# Ignore changes to matrix

**URL:** <https://discourse.processing.org/t/ignore-changes-to-matrix/1917>\
**Category:** Coding Questions\
**Created:** [July 19, 2018, 4:44pm UTC](https://discourse.processing.org/t/ignore-changes-to-matrix/1917 "2018-07-19T16:44:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ffd8](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ffd8/32/815_2.png) [@ffd8](https://discourse.processing.org/u/ffd8)\
**Post date:** [July 19, 2018, 4:44pm UTC](https://discourse.processing.org/t/ignore-changes-to-matrix/1917/1 "2018-07-19T16:44:55Z")

</div>

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:

```auto
  translate(width/2, height/2);
  rotate(radians(90));
  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?

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [July 19, 2018, 5:25pm UTC](https://discourse.processing.org/t/ignore-changes-to-matrix/1917/2 "2018-07-19T17:25:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ffd8](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ffd8/32/815_2.png) [@ffd8](https://discourse.processing.org/u/ffd8)\
**Post date:** [July 19, 2018, 5:26pm UTC](https://discourse.processing.org/t/ignore-changes-to-matrix/1917/3 "2018-07-19T17:26:16Z")

</div>

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()`?

---

<div class="post-metadata">

**Author:** ![ffd8](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/ffd8/32/815_2.png) [@ffd8](https://discourse.processing.org/u/ffd8)\
**Post date:** [July 19, 2018, 5:59pm UTC](https://discourse.processing.org/t/ignore-changes-to-matrix/1917/4 "2018-07-19T17:59:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![behreajj](https://avatars.discourse-cdn.com/v4/letter/b/b5a626/32.png) [@behreajj](https://discourse.processing.org/u/behreajj)\
**Post date:** [July 19, 2018, 6:55pm UTC](https://discourse.processing.org/t/ignore-changes-to-matrix/1917/5 "2018-07-19T18:55:18Z")

</div>

What about using instances of the class [PMatrix2D](https://github.com/processing/processing/blob/master/core/src/processing/core/PMatrix2D.java) (or [PMatrix3D](https://github.com/processing/processing/blob/master/core/src/processing/core/PMatrix3D.java)) to store transformations? You can multiply them with each other using [apply](https://github.com/processing/processing/blob/5ccb32135b31cc105ab403f2e3d7a347d938923b/core/src/processing/core/PMatrix2D.java#L249) and transform vectors with [mult](https://github.com/processing/processing/blob/5ccb32135b31cc105ab403f2e3d7a347d938923b/core/src/processing/core/PMatrix2D.java#L369). In addition to the `PGraphics` functions you’ve mentioned, you can use [getMatrix](https://github.com/processing/processing/blob/5ccb32135b31cc105ab403f2e3d7a347d938923b/core/src/processing/core/PApplet.java#L13636) (there are three versions of this function) and [setMatrix](https://github.com/processing/processing/blob/5ccb32135b31cc105ab403f2e3d7a347d938923b/core/src/processing/core/PApplet.java#L13662).
