That example probably isn't very good. The PMatrix classes seem to operate differently depending on how / where you are using them. I would also be interested in different matrix libraries if anyone can point them out.
Here is another example:
Quote:PMatrix3D one, two;
Timer timer = null;
boolean go = false;
void setup() {
size(400,400,P3D);
rectMode(CENTER);
one = new PMatrix3D();
getMatrix(one);
two = new PMatrix3D();
getMatrix(two);
}
void draw() {
background(196);
line(200,0,200,400);
line(0,200,400,200);
translate(200,200,0);
one = new PMatrix3D();
pushMatrix();
translate(5,5,0);
getMatrix(one);
popMatrix();
if(frameCount == 1) {
two = new PMatrix3D();
}
if(go) {
if(timer!=null && timer.time()) {
two.rotateZ(HALF_PI/30f);
} else {
//<------------------------------------
go = false;
timer = null;
}
}
one.preApply(two);
pushMatrix();
setMatrix(one);
rect(0,0,10,10);
popMatrix();
}
void mouseClicked() {
if(timer == null) {
timer = new Timer(30);
go = true;
} else {
return;
}
}
class Timer {
int stime = 0;
int time = 0;
int frames;
Timer(int f) {
stime = frameCount;
frames = f;
}
boolean time() {
time = frameCount - stime;
if(time == frames+1) {
return false;
}
return true;
}
}
Click and the rectangle rotates around its upper left corner. Its upper left corner then becomes its upper right in the transformed space so subsequent transformations basically rotate it around the center of the screen.
I'm looking for some way to reset the axes of the matrix called "one" (at the point indicated probably) so after the first click the other transformations will be exactly the same as the first. So the square rolls on the upper left corner each time.
There are probably other ways to do this. I just thought, naively, that it would be easier doing it with a matrix. I'm still wondering if its possible.