Hello everyone!
I have a quite weird resetMatrix bug on PShape. It works fine in the default renderer, but in P2D it seems to reset only the translation and not the rotation. So what I am seeing is a spinning quad, instead of a fixed one. If you are testing the code below, are you seeing the same difference?
Processing reference mentions that resetMatrix() is similar to OpenGL’s glLoadIdentity(), so is there an equivalent way to do this?
PShape s;
void setup(){
size(300, 300, P2D); // works fine with default renderer
s = createShape(QUAD, -75, -75, 75, -75, 75, 75, -75, 75);
}
void draw(){
background(0);
s.resetMatrix();
s.rotate(0.01); // rotate is not reset, so it keeps adding up
s.translate(30,10); // translate is reset properly
shape(s, 150, 150);
}
OK. Out of interest does this work with Processing 3.4? I know there was some changes to try and make matrix operations on shapes more efficient. What you’re doing actually performs worse than just drawing the shapes directly unfortunately.
Actually I tried making about 10000 of those quad PShapes without the shape group and I got worse performances, frameRate dropped by half.
I haven’t tried reverting to 3.4, I am using 3.5.2. I would try it but my code needs to run on machines that do not belong to me but to a museum, the guy that runs the IT department barely lets me install external libraries
Well, you could use beginShape(QUADS) and calls to vertex(..).
The problem is that resetting matrices on a PShape causes performance issues which negates the benefit of the retained shape. This issue, and some changes that I wonder might be causing a difference between 3.4 and 3.5, are covered at https://github.com/processing/processing/issues/5685 and have been discussed in a few threads here.
Interesting, and unexpected! So I was going to suggest you test the Demos/Performance/DynamicParticles(Immediate|Retained) examples. On 3.4 the performance of the retained example is dramatically worse. But I just noticed that on 3.5 it isn’t.
So, then I tested your original code. On 3.4 it’s correct, on 3.5 it continually rotates. So it’s definitely a regression caused by the performance improvements in PShape matrix handling.