diff --git a/examples/MultiView/MultiView.js b/examples/MultiView/MultiView.js index 817fd9b..0222a91 100644 --- a/examples/MultiView/MultiView.js +++ b/examples/MultiView/MultiView.js @@ -20,8 +20,7 @@ var NX = 3; var NY = 2; -var cameras = []; - +var cameras; function setup() { createCanvas(windowWidth, windowHeight, WEBGL); @@ -32,6 +31,7 @@ function setup() { console.log(Dw.EasyCam.INFO); + cameras = []; cameras.length = NX * NY; for(var i = 0; i < cameras.length; i++){ diff --git a/p5.easycam.js b/p5.easycam.js index 4c4b4b4..b7af94f 100644 --- a/p5.easycam.js +++ b/p5.easycam.js @@ -18,17 +18,19 @@ */ +// Dw namespace, .... new Dw.EasyCam(renderer, args); +var Dw = {}; + + - -(function () { - +(function(ext) { // p5.EasyCam library info const INFO = { LIBRARY : "p5.EasyCam", - VERSION : "1.0.1", + VERSION : "1.0.2", AUTHOR : "Thomas Diewald", SOURCE : "https://github.com/diwi/p5.EasyCam", @@ -1206,26 +1208,15 @@ var glInfo = function(){ - - - -// adding class and objects to the p5 namespace -// Note: Not sure if this is the preferred way ... - EasyCam.INFO = INFO; // make static Object.freeze(INFO); // and constant -// Dw namespace -Dw = -{ - EasyCam : EasyCam, - DampedAction : DampedAction, - Interpolation : Interpolation, - Rotation : Rotation, - Vec3 : Vec3, - Scalar : Scalar, -} - +ext.EasyCam = EasyCam; +ext.DampedAction = DampedAction; +ext.Interpolation = Interpolation; +ext.Rotation = Rotation; +ext.Vec3 = Vec3; +ext.Scalar = Scalar; //////////////////////////////////////////////////////////////////////////////// @@ -1264,7 +1255,7 @@ if(p5){ args = arguments[1]; // could still be undefined, which is fine } - return new Dw.EasyCam(renderer, args); + return new ext.EasyCam(renderer, args); } } @@ -1316,14 +1307,9 @@ if(p5){ +})(Dw); -})(); - - - -// Dw namespace, .... new Dw.EasyCam(renderer, args); -var Dw; diff --git a/p5.easycam.min.js b/p5.easycam.min.js index 783e18c..2999f81 100644 --- a/p5.easycam.min.js +++ b/p5.easycam.min.js @@ -1 +1 @@ -(function(){const c={LIBRARY:"p5.EasyCam",VERSION:"1.0.1",AUTHOR:"Thomas Diewald",SOURCE:"https://github.com/diwi/p5.EasyCam",toString:function(){return this.LIBRARY+" v"+this.VERSION+" by "+this.AUTHOR+" ("+this.SOURCE+")"}};var e=class{constructor(m,n){if(!(m instanceof p5.RendererGL))return void console.log("renderer needs to be an instance of p5.RendererGL");n=n||{},n.distance===void 0&&(n.distance=500),n.center===void 0&&(n.center=[0,0,0]),n.rotation===void 0&&(n.rotation=i.identity()),n.viewport===void 0&&(n.viewport=[0,0,m.width,m.height]),this.INFO=c,this.setCanvas(m);var o=this;this.cam=o,this.LOOK=[0,0,1],this.UP=[0,1,0],this.AXIS=new function(){this.YAW=1,this.PITCH=2,this.ROLL=4,this.ALL=this.YAW|this.PITCH|this.ROLL},this.SHIFT_CONSTRAINT=0,this.FIXED_CONSTRAINT=0,this.DRAG_CONSTRAINT=0,this.scale_rotation=1e-3,this.scale_pan=2e-4,this.scale_zoom=1e-3,this.scale_zoomwheel=20,this.default_interpolation_time=300,this.distance_min_limit=0.01,this.distance_min=1,this.distance_max=Number.MAX_VALUE,this.state={distance:n.distance,center:n.center.slice(),rotation:n.rotation.slice(),copy:function(p){return p=p||{},p.distance=this.distance,p.center=this.center.slice(),p.rotation=this.rotation.slice(),p}},this.state_reset=this.state.copy(),this.state_pushed=this.state.copy(),this.viewport=n.viewport.slice(),this.mouse={cam:o,curr:[0,0],prev:[0,0],dist:[0,0],mwheel:0,isPressed:!1,shiftKeyDown:!1,mouseDragLeft:o.mouseDragRotate,mouseDragCenter:o.mouseDragPan,mouseDragRight:o.mouseDragZoom,mouseWheelAction:o.mouseWheelZoom,insideViewport:function(p,q){var r=o.viewport[0],u=r+o.viewport[2],v=o.viewport[1],A=v+o.viewport[3];return p>r&&pv&&qMath.abs(q)?o.AXIS.YAW:o.AXIS.PITCH),o.DRAG_CONSTRAINT=o.AXIS.ALL,o.FIXED_CONSTRAINT&&(o.DRAG_CONSTRAINT=o.FIXED_CONSTRAINT),o.SHIFT_CONSTRAINT&&(o.DRAG_CONSTRAINT=o.SHIFT_CONSTRAINT)},pressed:function(p){var q=p.x,r=p.y;this.insideViewport(q,r)&&(this.curr[0]=this.prev[0]=q,this.curr[1]=this.prev[1]=r,this.dist[0]=0,this.dist[1]=0,this.isPressed=!0,o.SHIFT_CONSTRAINT=0)},update:function(){this.isPressed&&(this.prev[0]=this.curr[0],this.prev[1]=this.curr[1],this.curr[0]=o.P5.mouseX,this.curr[1]=o.P5.mouseY,this.dist[0]=-(this.curr[0]-this.prev[0]),this.dist[1]=-(this.curr[1]-this.prev[1]),this.updateDragConstraint(),o.P5.mouseButton===o.P5.LEFT&&this.mouseDragLeft&&this.mouseDragLeft(),o.P5.mouseButton===o.P5.CENTER&&this.mouseDragCenter&&this.mouseDragCenter(),o.P5.mouseButton===o.P5.RIGHT&&this.mouseDragRight&&this.mouseDragRight())},released:function(){this.isPressed=!1,o.SHIFT_CONSTRAINT=0},clicked:function(p){var q=p.x,r=p.y;if(this.insideViewport(q,r)){this.time=this.time||0;var u=p.timeStamp-this.time;this.time=p.timeStamp,un.distance_max&&(o=n.distance_max,n.dampedZoom.stop()),n.state.distance=o}panX(m){var n=this.cam.state;if(m){var o=i.applyToVec3(n.rotation,[m,0,0]);k.add(n.center,o,n.center)}}panY(m){var n=this.cam.state;if(m){var o=i.applyToVec3(n.rotation,[0,m,0]);k.add(n.center,o,n.center)}}pan(m){this.cam.panX(m),this.cam.panY(m)}rotateX(m){this.cam.rotate([1,0,0],m)}rotateY(m){this.cam.rotate([0,1,0],m)}rotateZ(m){this.cam.rotate([0,0,1],m)}rotate(m,n){var o=this.cam.state;if(n){var p=i.create({axis:m,angle:n});i.applyToRotation(o.rotation,p,o.rotation)}}setInterpolatedDistance(m,n,o){this.cam.state.distance=j.mix(m,n,j.smoothstep(o))}setInterpolatedCenter(m,n,o){this.cam.state.center=k.mix(m,n,j.smoothstep(o))}setInterpolatedRotation(m,n,o){this.cam.state.rotation=i.slerp(m,n,o)}setDistanceMin(m){this.distance_min=Math.max(m,this.distance_min_limit),this.zoom(0)}setDistanceMax(m){this.distance_max=m,this.zoom(0)}setDistance(m,n){this.timedzoom.start(this.state.distance,m,n,[this.dampedZoom])}getDistance(){return this.state.distance}setCenter(m,n){this.timedPan.start(this.state.center,m,n,[this.dampedPanX,this.dampedPanY])}getCenter(){return this.state.center}setRotation(m,n){this.timedRot.start(this.state.rotation,m,n,[this.dampedRotX,this.dampedRotY,this.dampedRotZ])}getRotation(){return this.state.rotation}getPosition(m){var n=this.cam,o=n.state;return m=k.assert(m),i.applyToVec3(o.rotation,n.LOOK,m),k.mult(m,o.distance,m),k.add(m,o.center,m),m}getUpVector(m){var n=this.cam,o=n.state;return m=k.assert(m),i.applyToVec3(o.rotation,n.UP,m),m}getState(){return this.state.copy()}setState(m,n){m&&(this.setDistance(m.distance,n),this.setCenter(m.center,n),this.setRotation(m.rotation,n))}pushState(){return this.state_pushed=this.getState()}popState(m){this.setState(this.state_pushed,m)}pushResetState(){return this.state_reset=this.getState()}reset(m){this.setState(this.state_reset,m)}setRotationScale(m){this.scale_rotation=m}setPanScale(m){this.scale_pan=m}setZoomScale(m){this.scale_zoom=m}getRotationScale(){return this.scale_rotation}getPanScale(){return this.scale_pan}getZoomScale(){return this.scale_zoom}getWheelScale(){return this.scale_zoomwheel}setWheelScale(m){this.scale_zoomwheel=m}setDamping(m){this.dampedZoom.damping=m,this.dampedPanX.damping=m,this.dampedPanY.damping=m,this.dampedRotX.damping=m,this.dampedRotY.damping=m,this.dampedRotZ.damping=m}setDefaultInterpolationTime(m){this.default_interpolation_time=m}getDefaultInterpolationTime(){return this.default_interpolation_time}setRotationConstraint(m,n,o){var p=this.cam;p.FIXED_CONSTRAINT=0,p.FIXED_CONSTRAINT|=m?p.AXIS.YAW:0,p.FIXED_CONSTRAINT|=n?p.AXIS.PITCH:0,p.FIXED_CONSTRAINT|=o?p.AXIS.ROLL:0}beginHUD(m,n,o){var p=this.cam;if(m=m||p.renderer,!!m){m.push();var q=m.drawingContext,n=void 0===n?m.width:n,o=void 0===o?m.height:o,r=Number.MAX_VALUE;q.flush(),q.disable(q.DEPTH_TEST),this.pushed_uMVMatrix=m.uMVMatrix.copy(),this.pushed_uPMatrix=m.uPMatrix.copy(),m.resetMatrix(),m.ortho(0,n,-o,0,-r,+r)}}endHUD(m){var n=this.cam;if(m=m||n.renderer,!!m){var o=m.drawingContext;o.flush(),m.uMVMatrix.set(this.pushed_uMVMatrix),m.uPMatrix.set(this.pushed_uPMatrix),o.enable(o.DEPTH_TEST),m.pop()}}},f=class{constructor(m,n){this.cam=m,this.value=0,this.damping=0.85,this.action=n}addForce(m){this.value+=m}update(){var m=1e-6E&&(A=-A,B=-B,C=-C,D=-D,E=-E);var H,I,F=Math.acos(E),G=Math.sqrt(1-E*E);return 1e-3q){var r=this.cross(m,n);return 0<=p?Math.asin(this.mag(r)/o):Math.PI-Math.asin(this.mag(r)/o)}return Math.acos(p/o)},mix(m,n,o,p){return p=this.assert(p),p[0]=j.mix(m[0],n[0],o),p[1]=j.mix(m[1],n[1],o),p[2]=j.mix(m[2],n[2],o),p}};e.INFO=c,Object.freeze(c),Dw={EasyCam:e,DampedAction:f,Interpolation:g,Rotation:i,Vec3:k,Scalar:j},p5&&(!p5.prototype.hasOwnProperty("glInfo")&&(p5.prototype.glInfo=function(){return this._renderer.glInfo.apply(this._renderer,arguments)},p5.RendererGL.prototype.glInfo=function(){var m=this.drawingContext,n={};n.gl=this.drawingContext;var o=m.getExtension("WEBGL_debug_renderer_info");return o&&(n.gpu_renderer=m.getParameter(o.UNMASKED_RENDERER_WEBGL),n.gpu_vendor=m.getParameter(o.UNMASKED_VENDOR_WEBGL)),n.wgl_renderer=m.getParameter(m.RENDERER),n.wgl_version=m.getParameter(m.VERSION),n.wgl_glsl=m.getParameter(m.SHADING_LANGUAGE_VERSION),n.wgl_vendor=m.getParameter(m.VENDOR),n}),!p5.prototype.hasOwnProperty("createEasyCam")&&(p5.prototype.createEasyCam=function(){var m=this._renderer,n=arguments[0];return arguments[0]instanceof p5.RendererGL&&(m=arguments[0],n=arguments[1]),new Dw.EasyCam(m,n)}),p5.prototype.ortho=function(){return this._renderer.ortho.apply(this._renderer,arguments),this},p5.RendererGL.prototype.ortho=function(m,n,o,p,q,r){m===void 0&&(m=-this.width/2),n===void 0&&(n=+this.width/2),o===void 0&&(o=-this.height/2),p===void 0&&(p=+this.height/2),q===void 0&&(q=0),r===void 0&&(r=Math.max(this.width,this.height));var u=n-m,v=p-o,A=r-q,E=-(n+m)/u,F=-(p+o)/v,G=-(r+q)/A;this.uPMatrix=p5.Matrix.identity(),this.uPMatrix.set(2/u,0,0,0,0,-(2/v),0,0,0,0,-2/A,0,E,F,G,1),this._curCamera="custom"})})();var Dw; \ No newline at end of file +var Dw={};(function(c){const e={LIBRARY:"p5.EasyCam",VERSION:"1.0.2",AUTHOR:"Thomas Diewald",SOURCE:"https://github.com/diwi/p5.EasyCam",toString:function(){return this.LIBRARY+" v"+this.VERSION+" by "+this.AUTHOR+" ("+this.SOURCE+")"}};var f=class{constructor(n,o){if(!(n instanceof p5.RendererGL))return void console.log("renderer needs to be an instance of p5.RendererGL");o=o||{},o.distance===void 0&&(o.distance=500),o.center===void 0&&(o.center=[0,0,0]),o.rotation===void 0&&(o.rotation=j.identity()),o.viewport===void 0&&(o.viewport=[0,0,n.width,n.height]),this.INFO=e,this.setCanvas(n);var p=this;this.cam=p,this.LOOK=[0,0,1],this.UP=[0,1,0],this.AXIS=new function(){this.YAW=1,this.PITCH=2,this.ROLL=4,this.ALL=this.YAW|this.PITCH|this.ROLL},this.SHIFT_CONSTRAINT=0,this.FIXED_CONSTRAINT=0,this.DRAG_CONSTRAINT=0,this.scale_rotation=1e-3,this.scale_pan=2e-4,this.scale_zoom=1e-3,this.scale_zoomwheel=20,this.default_interpolation_time=300,this.distance_min_limit=0.01,this.distance_min=1,this.distance_max=Number.MAX_VALUE,this.state={distance:o.distance,center:o.center.slice(),rotation:o.rotation.slice(),copy:function(q){return q=q||{},q.distance=this.distance,q.center=this.center.slice(),q.rotation=this.rotation.slice(),q}},this.state_reset=this.state.copy(),this.state_pushed=this.state.copy(),this.viewport=o.viewport.slice(),this.mouse={cam:p,curr:[0,0],prev:[0,0],dist:[0,0],mwheel:0,isPressed:!1,shiftKeyDown:!1,mouseDragLeft:p.mouseDragRotate,mouseDragCenter:p.mouseDragPan,mouseDragRight:p.mouseDragZoom,mouseWheelAction:p.mouseWheelZoom,insideViewport:function(q,r){var u=p.viewport[0],v=u+p.viewport[2],A=p.viewport[1],B=A+p.viewport[3];return q>u&&qA&&rMath.abs(r)?p.AXIS.YAW:p.AXIS.PITCH),p.DRAG_CONSTRAINT=p.AXIS.ALL,p.FIXED_CONSTRAINT&&(p.DRAG_CONSTRAINT=p.FIXED_CONSTRAINT),p.SHIFT_CONSTRAINT&&(p.DRAG_CONSTRAINT=p.SHIFT_CONSTRAINT)},pressed:function(q){var r=q.x,u=q.y;this.insideViewport(r,u)&&(this.curr[0]=this.prev[0]=r,this.curr[1]=this.prev[1]=u,this.dist[0]=0,this.dist[1]=0,this.isPressed=!0,p.SHIFT_CONSTRAINT=0)},update:function(){this.isPressed&&(this.prev[0]=this.curr[0],this.prev[1]=this.curr[1],this.curr[0]=p.P5.mouseX,this.curr[1]=p.P5.mouseY,this.dist[0]=-(this.curr[0]-this.prev[0]),this.dist[1]=-(this.curr[1]-this.prev[1]),this.updateDragConstraint(),p.P5.mouseButton===p.P5.LEFT&&this.mouseDragLeft&&this.mouseDragLeft(),p.P5.mouseButton===p.P5.CENTER&&this.mouseDragCenter&&this.mouseDragCenter(),p.P5.mouseButton===p.P5.RIGHT&&this.mouseDragRight&&this.mouseDragRight())},released:function(){this.isPressed=!1,p.SHIFT_CONSTRAINT=0},clicked:function(q){var r=q.x,u=q.y;if(this.insideViewport(r,u)){this.time=this.time||0;var v=q.timeStamp-this.time;this.time=q.timeStamp,vo.distance_max&&(p=o.distance_max,o.dampedZoom.stop()),o.state.distance=p}panX(n){var o=this.cam.state;if(n){var p=j.applyToVec3(o.rotation,[n,0,0]);l.add(o.center,p,o.center)}}panY(n){var o=this.cam.state;if(n){var p=j.applyToVec3(o.rotation,[0,n,0]);l.add(o.center,p,o.center)}}pan(n){this.cam.panX(n),this.cam.panY(n)}rotateX(n){this.cam.rotate([1,0,0],n)}rotateY(n){this.cam.rotate([0,1,0],n)}rotateZ(n){this.cam.rotate([0,0,1],n)}rotate(n,o){var p=this.cam.state;if(o){var q=j.create({axis:n,angle:o});j.applyToRotation(p.rotation,q,p.rotation)}}setInterpolatedDistance(n,o,p){this.cam.state.distance=k.mix(n,o,k.smoothstep(p))}setInterpolatedCenter(n,o,p){this.cam.state.center=l.mix(n,o,k.smoothstep(p))}setInterpolatedRotation(n,o,p){this.cam.state.rotation=j.slerp(n,o,p)}setDistanceMin(n){this.distance_min=Math.max(n,this.distance_min_limit),this.zoom(0)}setDistanceMax(n){this.distance_max=n,this.zoom(0)}setDistance(n,o){this.timedzoom.start(this.state.distance,n,o,[this.dampedZoom])}getDistance(){return this.state.distance}setCenter(n,o){this.timedPan.start(this.state.center,n,o,[this.dampedPanX,this.dampedPanY])}getCenter(){return this.state.center}setRotation(n,o){this.timedRot.start(this.state.rotation,n,o,[this.dampedRotX,this.dampedRotY,this.dampedRotZ])}getRotation(){return this.state.rotation}getPosition(n){var o=this.cam,p=o.state;return n=l.assert(n),j.applyToVec3(p.rotation,o.LOOK,n),l.mult(n,p.distance,n),l.add(n,p.center,n),n}getUpVector(n){var o=this.cam,p=o.state;return n=l.assert(n),j.applyToVec3(p.rotation,o.UP,n),n}getState(){return this.state.copy()}setState(n,o){n&&(this.setDistance(n.distance,o),this.setCenter(n.center,o),this.setRotation(n.rotation,o))}pushState(){return this.state_pushed=this.getState()}popState(n){this.setState(this.state_pushed,n)}pushResetState(){return this.state_reset=this.getState()}reset(n){this.setState(this.state_reset,n)}setRotationScale(n){this.scale_rotation=n}setPanScale(n){this.scale_pan=n}setZoomScale(n){this.scale_zoom=n}getRotationScale(){return this.scale_rotation}getPanScale(){return this.scale_pan}getZoomScale(){return this.scale_zoom}getWheelScale(){return this.scale_zoomwheel}setWheelScale(n){this.scale_zoomwheel=n}setDamping(n){this.dampedZoom.damping=n,this.dampedPanX.damping=n,this.dampedPanY.damping=n,this.dampedRotX.damping=n,this.dampedRotY.damping=n,this.dampedRotZ.damping=n}setDefaultInterpolationTime(n){this.default_interpolation_time=n}getDefaultInterpolationTime(){return this.default_interpolation_time}setRotationConstraint(n,o,p){var q=this.cam;q.FIXED_CONSTRAINT=0,q.FIXED_CONSTRAINT|=n?q.AXIS.YAW:0,q.FIXED_CONSTRAINT|=o?q.AXIS.PITCH:0,q.FIXED_CONSTRAINT|=p?q.AXIS.ROLL:0}beginHUD(n,o,p){var q=this.cam;if(n=n||q.renderer,!!n){n.push();var r=n.drawingContext,o=void 0===o?n.width:o,p=void 0===p?n.height:p,u=Number.MAX_VALUE;r.flush(),r.disable(r.DEPTH_TEST),this.pushed_uMVMatrix=n.uMVMatrix.copy(),this.pushed_uPMatrix=n.uPMatrix.copy(),n.resetMatrix(),n.ortho(0,o,-p,0,-u,+u)}}endHUD(n){var o=this.cam;if(n=n||o.renderer,!!n){var p=n.drawingContext;p.flush(),n.uMVMatrix.set(this.pushed_uMVMatrix),n.uPMatrix.set(this.pushed_uPMatrix),p.enable(p.DEPTH_TEST),n.pop()}}},g=class{constructor(n,o){this.cam=n,this.value=0,this.damping=0.85,this.action=o}addForce(n){this.value+=n}update(){var n=1e-6F&&(B=-B,C=-C,D=-D,E=-E,F=-F);var I,J,G=Math.acos(F),H=Math.sqrt(1-F*F);return 1e-3r){var u=this.cross(n,o);return 0<=q?Math.asin(this.mag(u)/p):Math.PI-Math.asin(this.mag(u)/p)}return Math.acos(q/p)},mix(n,o,p,q){return q=this.assert(q),q[0]=k.mix(n[0],o[0],p),q[1]=k.mix(n[1],o[1],p),q[2]=k.mix(n[2],o[2],p),q}};f.INFO=e,Object.freeze(e),c.EasyCam=f,c.DampedAction=g,c.Interpolation=i,c.Rotation=j,c.Vec3=l,c.Scalar=k,p5&&(!p5.prototype.hasOwnProperty("glInfo")&&(p5.prototype.glInfo=function(){return this._renderer.glInfo.apply(this._renderer,arguments)},p5.RendererGL.prototype.glInfo=function(){var n=this.drawingContext,o={};o.gl=this.drawingContext;var p=n.getExtension("WEBGL_debug_renderer_info");return p&&(o.gpu_renderer=n.getParameter(p.UNMASKED_RENDERER_WEBGL),o.gpu_vendor=n.getParameter(p.UNMASKED_VENDOR_WEBGL)),o.wgl_renderer=n.getParameter(n.RENDERER),o.wgl_version=n.getParameter(n.VERSION),o.wgl_glsl=n.getParameter(n.SHADING_LANGUAGE_VERSION),o.wgl_vendor=n.getParameter(n.VENDOR),o}),!p5.prototype.hasOwnProperty("createEasyCam")&&(p5.prototype.createEasyCam=function(){var n=this._renderer,o=arguments[0];return arguments[0]instanceof p5.RendererGL&&(n=arguments[0],o=arguments[1]),new c.EasyCam(n,o)}),p5.prototype.ortho=function(){return this._renderer.ortho.apply(this._renderer,arguments),this},p5.RendererGL.prototype.ortho=function(n,o,p,q,r,u){n===void 0&&(n=-this.width/2),o===void 0&&(o=+this.width/2),p===void 0&&(p=-this.height/2),q===void 0&&(q=+this.height/2),r===void 0&&(r=0),u===void 0&&(u=Math.max(this.width,this.height));var v=o-n,A=q-p,B=u-r,F=-(o+n)/v,G=-(q+p)/A,H=-(u+r)/B;this.uPMatrix=p5.Matrix.identity(),this.uPMatrix.set(2/v,0,0,0,0,-(2/A),0,0,0,0,-2/B,0,F,G,H,1),this._curCamera="custom"})})(Dw); \ No newline at end of file