Proper way to work with transformation matrices
in
Programming Questions
•
11 months ago
What I'm trying to do is to be able to get and set current transform matrix.
Obvious way to do this would be using getMatrix() and setMatrix() methods, but they do not work with all renderers.
In Processing 2.04 they only work with JAVA2D renderer; P2D says "setMatrix is not available with this renderer" and does nothing; P3D doesn't print error but nothing gets drawn. In 1.5.1 all renderers work except P2D.
Code that demonstartes the problem:
-
PMatrix m;
void setup() {
size(300, 300, P2D);
fill(64);
}
void draw() {
background(192);
m = getMatrix();
rotate(-PI / 4);
if(mousePressed) {
setMatrix(m);
}
rect(25, 150, 100, 100);
}
In Processing 2, it's also possible to make it work for P2D and P3D by accessing modelview matrix directly. Can it be considered reliable, or modelview is an implementation detail? Should I also copy/restore modelviewInv every time? And is that setMatrix()/getMatrix() behaviour bug or feature?
2