We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello all,
a question regarding the Matrix: after translate / rotate in P3D: can we save the Matrix other than with pushMatrix()
?
You know we can change the rotation matrix by using rotate()
and translate()
in processing.
One wish would be that it would be possible to store the current matrix like Matrix m = getMatrix();
and then say setMatrix(m);
.
How is that possible please?
Thank you!
Best, Chrisir ;-)
Answers
As you may already know, we can print the current matrix via printMatrix():
https://Processing.org/reference/printMatrix_.html
Processing's web reference contains merely a fraction of its API: 8-|
https://Processing.org/reference/
For the complete Processing's API, we need to look up its JavaDocs: ~O)
Or study directly at its source repo: *-:)
Inside
class
PMatrix, we can find its getter & setter as methods get() & set(): O:-)Hoho...!!!
Sorry, I fail to adopt that into processing code
PMatrix is the name of the class but what is the name of the used matrix?
I try to store the current matrix into a hashMap:
(I marked the line where it fails)
thank you!
You're gonna need to pass an instance of PMatrix to undocumented methods getMatrix() & setMatrix():
getMatrix():
setMatrix():
Brilliant!
Thank you SO much, GoToLoop!
That worked.
Here is what I did.
That's the version for P3D. For 2D probably use PMatrix2D.
keywords: getMatrix setMatrix pushMatrix with name popMatrix with String
@Chrisir -- does your example saving code work for stacks that are nested more than one transform deep?
When I last played with getMatrix/setMatrix I thought getMatrix() was returning the last transformation, not the cumulative transformation. So, if the stack was:
...then getMatrix() would return a PMatrix/PMatrix3D object for
translate(0,50)
, rather than one representing all the steps on the stack.Or maybe I need to look at this again....
In my tests they delivered the entire matrix (cumulative)
But I have to admit I wasn't aware of your question at the time
The commands like translate / rotate are not on a stack btw
They just change the matrix
Only pushMatrix and popmatrix are using a stack
It might be relevant to pass a PMatrix with value null as parameter to getMatrix as I did
Yes -- sorry, I should have been much more clear. I meant working with cumulative stacks (several pushMatrix calls) specifically. So:
...being able to retrieve a PMatrix that represents the cumulative transformation of all stack frames, as opposed to the cumulative changes in one frame.
I tried it only with my turtle script
Haven't tried this
not sure what you mean...
pushMatrix()+ translate