PShape and applyMatrix(...)
in
Programming Questions
•
3 months ago
Is it wrong of me to expect the following code to do the same thing with resetBoth set to true or false?
(processing 2.0.1)
(processing 2.0.1)
PShape test; PMatrix3D pm; boolean resetBoth = false; boolean shapeForVerts = true; void setup() { size(400,400,P3D); frameRate(1); ortho(); test = createShape(BOX, 100,100,100); noStroke(); pm = doTx(test); if(shapeForVerts) shape(test); } void mouseClicked() { if(resetBoth) pm.reset(); pm.apply(doTx(test)); if(shapeForVerts) shape(test); } PMatrix3D doTx(PShape in) { if(resetBoth) in.resetMatrix(); PVector tx = new PVector( random(-25,25),random(-25,25),random(-25,25)); PVector rx = new PVector( random(-1,1),random(-1,1),random(-1,1)); PMatrix3D ret = new PMatrix3D(); tx.mult(-1); ret.translate(tx.x, tx.y, tx.z); ret.rotateX(rx.x); ret.rotateY(rx.y); ret.rotateZ(rx.z); tx.mult(-1); ret.translate(tx.x, tx.y, tx.z); in.applyMatrix(ret); return ret; } void draw() { background(204); translate(width*.5, height*.5); // shape(test); hint(DISABLE_DEPTH_TEST); fill(255,0,0); pushMatrix(); applyMatrix(pm); pushStyle(); stroke(0); fill(255); box(100,100,100); popStyle(); for(int a=0; a<8; a++) { pushMatrix(); PVector cur = test.getVertex(a); translate(cur.x, cur.y, cur.z); sphere(10); popMatrix(); } popMatrix(); PVector pv = test.getVertex(0).get(); pm.mult(pv, pv); fill(0,0,255); pushMatrix(); translate(pv.x, pv.y, pv.z); sphere(5); popMatrix(); hint(ENABLE_DEPTH_TEST); }
1