-
Notifications
You must be signed in to change notification settings - Fork 1
/
addScreenPositionFunction.min.js
1 lines (1 loc) · 3.16 KB
/
addScreenPositionFunction.min.js
1
function addScreenPositionFunction(t){let e=t||this;let a=(n=e._renderer.drawingContext,r=/function (.{1,})\(/.exec(n.constructor.toString()),r&&r.length>1?r[1]:"").search("2D")>=0?0:1;var n,r;if(0==a&&(e._renderer.matrixStack=[new p5.Matrix]),e.draw instanceof Function){let t=e.draw;e.draw=function(...n){0==a&&(e._renderer.matrixStack=[new p5.Matrix]),t.apply(e,n)}}if(e.resetMatrix instanceof Function){let t=e.resetMatrix;e.resetMatrix=function(...n){0==a&&(e._renderer.matrixStack=[new p5.Matrix]),t.apply(e,n)}}if(e.translate instanceof Function){let t=e.translate;e.translate=function(...n){0==a&&i(e._renderer.matrixStack).translate(n),t.apply(e,n)}}if(e.rotate instanceof Function){let t=e.rotate;e.rotate=function(...n){if(0==a){let t=e._toRadians(n[0]);i(e._renderer.matrixStack).rotateZ(t)}t.apply(e,n)}}if(e.rotateX instanceof Function){let t=e.rotateX;e.rotateX=function(...n){if(0==a){let t=e._toRadians(n[0]);i(e._renderer.matrixStack).rotateX(t)}t.apply(e,n)}}if(e.rotateY instanceof Function){let t=e.rotateY;e.rotateY=function(...n){if(0==a){let t=e._toRadians(n[0]);i(e._renderer.matrixStack).rotateY(t)}t.apply(e,n)}}if(e.rotateZ instanceof Function){let t=e.rotateZ;e.rotateZ=function(...n){if(0==a){let t=e._toRadians(n[0]);i(e._renderer.matrixStack).rotateZ(t)}t.apply(e,n)}}if(e.scale instanceof Function){let t=e.scale;e.scale=function(...n){if(0==a){let t=i(e._renderer.matrixStack),r=n[0],o=n[1]||r,c=0==a?1:n[2];t.scale([r,o,c])}t.apply(e,n)}}if(e.shearX instanceof Function){let t=e.shearX;e.shearX=function(...n){if(0==a){let t=e._toRadians(n[0]),a=e._renderer.matrixStack,r=i(a),o=new p5.Matrix;o.mat4[4]=Math.tan(t),o.mult(r),a[a.length-1]=o}t.apply(e,n)}}if(e.shearY instanceof Function){let t=e.shearY;e.shearY=function(...n){if(0==a){let t=e._toRadians(n[0]),a=e._renderer.matrixStack,r=i(a),o=new p5.Matrix;o.mat4[1]=Math.tan(t),o.mult(r),a[a.length-1]=o}t.apply(e,n)}}if(e.applyMatrix instanceof Function){let t=e.applyMatrix;e.applyMatrix=function(...n){if(0==a){let t=e._renderer.matrixStack,a=i(t),r=new p5.Matrix;r.mat4[0]=n[0],r.mat4[1]=n[1],r.mat4[4]=n[2],r.mat4[5]=n[3],r.mat4[12]=n[4],r.mat4[13]=n[5],r.mult(a),t[t.length-1]=r}t.apply(e,n)}}if(e.push instanceof Function){let t=e.push;e.push=function(...n){if(0==a){let t=i(e._renderer.matrixStack);e._renderer.matrixStack.push(t.copy())}t.apply(e,n)}}if(e.pop instanceof Function){let t=e.pop;e.pop=function(...n){0==a&&e._renderer.matrixStack.pop(),t.apply(e,n)}}function i(t){return t[t.length-1]}function o(t,a){if(t instanceof p5.Matrix&&a instanceof p5.Vector){var n=e.createVector(),r=t.mat4;n.x=r[0]*a.x+r[4]*a.y+r[8]*a.z+r[12],n.y=r[1]*a.x+r[5]*a.y+r[9]*a.z+r[13],n.z=r[2]*a.x+r[6]*a.y+r[10]*a.z+r[14];var i=r[3]*a.x+r[7]*a.y+r[11]*a.z+r[15];return Math.abs(i)>Number.EPSILON&&n.mult(1/i),n}print("multMatrixVector : Invalid arguments")}e.screenPosition=function(t,n,r){if(t instanceof p5.Vector){let e=t;t=e.x,n=e.y,r=e.z}else if(t instanceof Array){let e=t;t=e[0],n=e[1],r=e[2]||0}if(r=r||0,0==a){return o(i(e._renderer.matrixStack),e.createVector(t,n,r))}{let a=e.createVector(t,n,r),i=o(e._renderer.uMVMatrix.copy().mult(e._renderer.uPMatrix),a),c=e.createVector();return c.x=.5*i.x*e.width,c.y=.5*-i.y*e.height,c.z=0,c}}}