diff --git a/p5.easycam.min.js b/p5.easycam.min.js index 68212f1..dee1fe9 100644 --- a/p5.easycam.min.js +++ b/p5.easycam.min.js @@ -1 +1 @@ -'use strict';var Dw=function(a){const b={LIBRARY:"p5.EasyCam",VERSION:"1.0.10",AUTHOR:"p5.EasyCam authors",SOURCE:"https://github.com/freshfork/p5.EasyCam",toString:function(){return this.LIBRARY+" v"+this.VERSION+" by "+this.AUTHOR+" ("+this.SOURCE+")"}};class c{constructor(a,c){if(!(a instanceof p5.RendererGL))return void console.log("renderer needs to be an instance of p5.RendererGL");c=c||{},void 0===c.distance&&(c.distance=500),void 0===c.center&&(c.center=[0,0,0]),void 0===c.rotation&&(c.rotation=f.identity()),void 0===c.viewport&&(c.viewport=[0,0,a.width,a.height]),this.INFO=b,this.setCanvas(a);var g=this;this.cam=g,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=.001,this.scale_pan=2e-4,this.scale_zoom=.001,this.scale_zoomwheel=20,this.distance_min_limit=.01,this.distance_min=1,this.distance_max=Number.MAX_VALUE,this.state={distance:c.distance,center:c.center.slice(),rotation:c.rotation.slice(),copy:function(a){return a=a||{},a.distance=this.distance,a.center=this.center.slice(),a.rotation=this.rotation.slice(),a}},this.state_reset=this.state.copy(),this.state_pushed=this.state.copy(),this.viewport=c.viewport.slice(),this.mouse={cam:g,curr:[0,0,0],prev:[0,0,0],dist:[0,0,0],mwheel:0,isPressed:!1,istouchdown:!1,ismousedown:!1,BUTTON:{LMB:1,MMB:2,RMB:4},button:0,mouseDragLeft:g.mouseDragRotate.bind(g),mouseDragCenter:g.mouseDragPan.bind(g),mouseDragRight:g.mouseDragZoom.bind(g),mouseWheelAction:g.mouseWheelZoom.bind(g),touchmoveSingle:g.mouseDragRotate.bind(g),touchmoveMulti:function(){g.mouseDragPan(),g.mouseDragZoom()},insideViewport:function(a,b){var c=g.viewport[0],d=c+g.viewport[2],e=g.viewport[1],f=e+g.viewport[3];return a>c&&ae&&bMath.abs(b)?g.AXIS.YAW:g.AXIS.PITCH),g.DRAG_CONSTRAINT=g.AXIS.ALL,g.FIXED_CONSTRAINT&&(g.DRAG_CONSTRAINT=g.FIXED_CONSTRAINT),g.SHIFT_CONSTRAINT&&(g.DRAG_CONSTRAINT=g.SHIFT_CONSTRAINT)},updateInput:function(a,b,c){var d=g.mouse,e=g.P5.pixelDensity();d.prev[0]=d.curr[0],d.prev[1]=d.curr[1],d.prev[2]=d.curr[2],d.curr[0]=a,d.curr[1]=b,d.curr[2]=c,d.dist[0]=-(d.curr[0]-d.prev[0])/e,d.dist[1]=-(d.curr[1]-d.prev[1])/e,d.dist[2]=-(d.curr[2]-d.prev[2])/e},mousedown:function(a){var b=g.mouse;0===a.button&&(b.button|=b.BUTTON.LMB),1===a.button&&(b.button|=b.BUTTON.MMB),2===a.button&&(b.button|=b.BUTTON.RMB),b.insideViewport(a.x,a.y)&&(b.updateInput(a.x,a.y,a.y),b.ismousedown=0b.distance_max&&(c=b.distance_max,b.dampedZoom.stop()),b.state.distance=c}panX(a){var b=this.cam.state;if(a){var c=f.applyToVec3(b.rotation,[a,0,0]);h.add(b.center,c,b.center)}}panY(a){var b=this.cam.state;if(a){var c=f.applyToVec3(b.rotation,[0,a,0]);h.add(b.center,c,b.center)}}pan(a,b){this.cam.panX(a),this.cam.panY(a)}rotateX(a){this.cam.rotate([1,0,0],a)}rotateY(a){this.cam.rotate([0,1,0],a)}rotateZ(a){this.cam.rotate([0,0,1],a)}rotate(a,b){var c=this.cam.state;if(b){var d=f.create({axis:a,angle:b});f.applyToRotation(c.rotation,d,c.rotation)}}setInterpolatedDistance(a,b,c){this.cam.state.distance=g.mix(a,b,g.smoothstep(c))}setInterpolatedCenter(a,b,c){this.cam.state.center=h.mix(a,b,g.smoothstep(c))}setInterpolatedRotation(a,b,c){this.cam.state.rotation=f.slerp(a,b,c)}setDistanceMin(a){this.distance_min=Math.max(a,this.distance_min_limit),this.zoom(0)}setDistanceMax(a){this.distance_max=a,this.zoom(0)}setDistance(a,b){this.timedzoom.start(this.state.distance,a,b,[this.dampedZoom])}getDistance(){return this.state.distance}setCenter(a,b){this.timedPan.start(this.state.center,a,b,[this.dampedPanX,this.dampedPanY])}getCenter(){return this.state.center}setRotation(a,b){this.timedRot.start(this.state.rotation,a,b,[this.dampedRotX,this.dampedRotY,this.dampedRotZ])}getRotation(){return this.state.rotation}getPosition(a){var b=this.cam,c=b.state;return a=h.assert(a),f.applyToVec3(c.rotation,b.LOOK,a),h.mult(a,c.distance,a),h.add(a,c.center,a),a}getUpVector(a){var b=this.cam,c=b.state;return a=h.assert(a),f.applyToVec3(c.rotation,b.UP,a),a}getState(){return this.state.copy()}setState(a,b){a&&(this.setDistance(a.distance,b),this.setCenter(a.center,b),this.setRotation(a.rotation,b))}pushState(){return this.state_pushed=this.getState()}popState(a){this.setState(this.state_pushed,a)}pushResetState(){return this.state_reset=this.getState()}reset(a){this.setState(this.state_reset,a)}setRotationScale(a){this.scale_rotation=a}setPanScale(a){this.scale_pan=a}setZoomScale(a){this.scale_zoom=a}setWheelScale(a){this.scale_zoomwheel=a}getRotationScale(){return this.scale_rotation}getPanScale(){return this.scale_pan}getZoomScale(){return this.scale_zoom}getWheelScale(){return this.scale_zoomwheel}setDamping(a){this.dampedZoom.damping=a,this.dampedPanX.damping=a,this.dampedPanY.damping=a,this.dampedRotX.damping=a,this.dampedRotY.damping=a,this.dampedRotZ.damping=a}setDefaultInterpolationTime(a){this.timedRot.default_duration=a,this.timedPan.default_duration=a,this.timedzoom.default_duration=a}setRotationConstraint(a,b,c){var d=this.cam;d.FIXED_CONSTRAINT=0,d.FIXED_CONSTRAINT|=a?d.AXIS.YAW:0,d.FIXED_CONSTRAINT|=b?d.AXIS.PITCH:0,d.FIXED_CONSTRAINT|=c?d.AXIS.ROLL:0}beginHUD(a,b,c){var e=this.cam;if(a=a||e.renderer,!!a){this.pushed_rendererState=a.push();var f=a.drawingContext,b=void 0===b?a.width:b,c=void 0===c?a.height:c,g=Number.MAX_VALUE;f.flush(),f.disable(f.DEPTH_TEST),this.pushed_uMVMatrix=a.uMVMatrix.copy(),this.pushed_uPMatrix=a.uPMatrix.copy(),a.resetMatrix(),a._curCamera.ortho(0,b,-c,0,-g,+g)}}endHUD(a){var b=this.cam;if(a=a||b.renderer,!!a){var c=a.drawingContext;c.flush(),a.uMVMatrix.set(this.pushed_uMVMatrix),a.uPMatrix.set(this.pushed_uPMatrix),c.enable(c.DEPTH_TEST),a.pop(this.pushed_rendererState)}}}class d{constructor(a){this.value=0,this.damping=.85,this.action=a}addForce(a){this.value+=a}update(){var a=1e-6n&&(j=-j,k=-k,l=-l,m=-m,n=-n);var o,p,q=Math.acos(n),r=Math.sqrt(1-n*n);return .001e){var f=this.cross(a,b);return 0<=d?Math.asin(this.mag(f)/c):Math.PI-Math.asin(this.mag(f)/c)}return Math.acos(d/c)},mix(c,a,b,d){return d=this.assert(d),d[0]=g.mix(c[0],a[0],b),d[1]=g.mix(c[1],a[1],b),d[2]=g.mix(c[2],a[2],b),d}};return c.INFO=b,Object.freeze(b),a=void 0===a?{}:a,a.EasyCam=c,a.DampedAction=d,a.Interpolation=e,a.Rotation=f,a.Vec3=h,a.Scalar=g,a}(Dw);p5&&(p5.prototype.createEasyCam=function(){var a=this._renderer,b=arguments[0];return arguments[0]instanceof p5.RendererGL&&(a=arguments[0],b=arguments[1]),new Dw.EasyCam(a,b)}); \ No newline at end of file +'use strict';var Dw=function(a){const b={LIBRARY:"p5.EasyCam",VERSION:"1.2.0",AUTHOR:"p5.EasyCam authors",SOURCE:"https://github.com/freshfork/p5.EasyCam",toString:function(){return this.LIBRARY+" v"+this.VERSION+" by "+this.AUTHOR+" ("+this.SOURCE+")"}};class c{constructor(a,c){if(!(a instanceof p5.RendererGL))return void console.log("renderer needs to be an instance of p5.RendererGL");var g=a.elt.getBoundingClientRect();c=c||{},void 0===c.distance&&(c.distance=500),void 0===c.center&&(c.center=[0,0,0]),void 0===c.rotation&&(c.rotation=f.identity()),void 0===c.viewport&&(c.viewport=[0,0,a.width,a.height]),void 0===c.offset&&(c.offset=[g.x+window.scrollX,g.y+window.scrollY]),this.INFO=b,this.setCanvas(a);var h=this;this.cam=h,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=.001,this.scale_pan=2e-4,this.scale_zoom=.001,this.scale_zoomwheel=20,this.distance_min_limit=.01,this.distance_min=1,this.distance_max=Number.MAX_VALUE,this.state={distance:c.distance,center:c.center.slice(),rotation:c.rotation.slice(),copy:function(a){return a=a||{},a.distance=this.distance,a.center=this.center.slice(),a.rotation=this.rotation.slice(),a}},this.state_reset=this.state.copy(),this.state_pushed=this.state.copy(),this.viewport=c.viewport.slice(),this.offset=c.offset.slice(),window.addEventListener("resize",function(){let b=a.elt.getBoundingClientRect();h.offset=[b.x+window.scrollX,b.y+window.scrollY]}),this.mouse={cam:h,curr:[0,0,0],prev:[0,0,0],dist:[0,0,0],mwheel:0,isPressed:!1,istouchdown:!1,ismousedown:!1,BUTTON:{LMB:1,MMB:2,RMB:4},button:0,mouseDragLeft:h.mouseDragRotate.bind(h),mouseDragCenter:h.mouseDragPan.bind(h),mouseDragRight:h.mouseDragZoom.bind(h),mouseWheelAction:h.mouseWheelZoom.bind(h),touchmoveSingle:h.mouseDragRotate.bind(h),touchmoveMulti:function(){h.mouseDragPan(),h.mouseDragZoom()},insideViewport:function(a,b){var c=h.viewport[0],d=c+h.viewport[2],e=h.viewport[1],f=e+h.viewport[3];return a>c&&ae&&bMath.abs(b)?h.AXIS.YAW:h.AXIS.PITCH),h.DRAG_CONSTRAINT=h.AXIS.ALL,h.FIXED_CONSTRAINT&&(h.DRAG_CONSTRAINT=h.FIXED_CONSTRAINT),h.SHIFT_CONSTRAINT&&(h.DRAG_CONSTRAINT=h.SHIFT_CONSTRAINT)},updateInput:function(a,b,c){var d=h.mouse,e=h.P5.pixelDensity();d.prev[0]=d.curr[0],d.prev[1]=d.curr[1],d.prev[2]=d.curr[2],d.curr[0]=a,d.curr[1]=b,d.curr[2]=c,d.dist[0]=-(d.curr[0]-d.prev[0])/e,d.dist[1]=-(d.curr[1]-d.prev[1])/e,d.dist[2]=-(d.curr[2]-d.prev[2])/e},mousedown:function(a){var b=h.mouse,c=h.offset[0]-window.scrollX,d=h.offset[1]-window.scrollY;0===a.button&&(b.button|=b.BUTTON.LMB),1===a.button&&(b.button|=b.BUTTON.MMB),2===a.button&&(b.button|=b.BUTTON.RMB),b.insideViewport(a.x-c,a.y-d)&&(b.updateInput(a.x-c,a.y-d,a.y-d),b.ismousedown=0b.distance_max&&(c=b.distance_max,b.dampedZoom.stop()),b.state.distance=c}panX(a){var b=this.cam.state;if(a){var c=f.applyToVec3(b.rotation,[a,0,0]);h.add(b.center,c,b.center)}}panY(a){var b=this.cam.state;if(a){var c=f.applyToVec3(b.rotation,[0,a,0]);h.add(b.center,c,b.center)}}pan(a){this.cam.panX(a),this.cam.panY(a)}rotateX(a){this.cam.rotate([1,0,0],a)}rotateY(a){this.cam.rotate([0,1,0],a)}rotateZ(a){this.cam.rotate([0,0,1],a)}rotate(a,b){var c=this.cam.state;if(b){var d=f.create({axis:a,angle:b});f.applyToRotation(c.rotation,d,c.rotation)}}setInterpolatedDistance(a,b,c){this.cam.state.distance=g.mix(a,b,g.smoothstep(c))}setInterpolatedCenter(a,b,c){this.cam.state.center=h.mix(a,b,g.smoothstep(c))}setInterpolatedRotation(a,b,c){this.cam.state.rotation=f.slerp(a,b,c)}setDistanceMin(a){this.distance_min=Math.max(a,this.distance_min_limit),this.zoom(0)}setDistanceMax(a){this.distance_max=a,this.zoom(0)}setDistance(a,b){this.timedzoom.start(this.state.distance,a,b,[this.dampedZoom])}getDistance(){return this.state.distance}setCenter(a,b){this.timedPan.start(this.state.center,a,b,[this.dampedPanX,this.dampedPanY])}getCenter(){return this.state.center}setRotation(a,b){this.timedRot.start(this.state.rotation,a,b,[this.dampedRotX,this.dampedRotY,this.dampedRotZ])}getRotation(){return this.state.rotation}getPosition(a){var b=this.cam,c=b.state;return a=h.assert(a),f.applyToVec3(c.rotation,b.LOOK,a),h.mult(a,c.distance,a),h.add(a,c.center,a),a}getUpVector(a){var b=this.cam,c=b.state;return a=h.assert(a),f.applyToVec3(c.rotation,b.UP,a),a}getState(){return this.state.copy()}setState(a,b){a&&(this.setDistance(a.distance,b),this.setCenter(a.center,b),this.setRotation(a.rotation,b))}pushState(){return this.state_pushed=this.getState()}popState(a){this.setState(this.state_pushed,a)}pushResetState(){return this.state_reset=this.getState()}reset(a){this.setState(this.state_reset,a)}setRotationScale(a){this.scale_rotation=a}setPanScale(a){this.scale_pan=a}setZoomScale(a){this.scale_zoom=a}setWheelScale(a){this.scale_zoomwheel=a}getRotationScale(){return this.scale_rotation}getPanScale(){return this.scale_pan}getZoomScale(){return this.scale_zoom}getWheelScale(){return this.scale_zoomwheel}setDamping(a){this.dampedZoom.damping=a,this.dampedPanX.damping=a,this.dampedPanY.damping=a,this.dampedRotX.damping=a,this.dampedRotY.damping=a,this.dampedRotZ.damping=a}setDefaultInterpolationTime(a){this.timedRot.default_duration=a,this.timedPan.default_duration=a,this.timedzoom.default_duration=a}setRotationConstraint(a,b,c){var d=this.cam;d.FIXED_CONSTRAINT=0,d.FIXED_CONSTRAINT|=a?d.AXIS.YAW:0,d.FIXED_CONSTRAINT|=b?d.AXIS.PITCH:0,d.FIXED_CONSTRAINT|=c?d.AXIS.ROLL:0}beginHUD(a,b,c){var e=this.cam;if(a=a||e.renderer,!!a){this.pushed_rendererState=a.push();var f=a.drawingContext,b=void 0===b?a.width:b,c=void 0===c?a.height:c,g=Number.MAX_VALUE;f.flush(),f.disable(f.DEPTH_TEST),this.pushed_uMVMatrix=a.uMVMatrix.copy(),this.pushed_uPMatrix=a.uPMatrix.copy(),a.resetMatrix(),a._curCamera.ortho(0,b,-c,0,-g,+g)}}endHUD(a){var b=this.cam;if(a=a||b.renderer,!!a){var c=a.drawingContext;c.flush(),a.uMVMatrix.set(this.pushed_uMVMatrix),a.uPMatrix.set(this.pushed_uPMatrix),c.enable(c.DEPTH_TEST),a.pop(this.pushed_rendererState)}}}class d{constructor(a){this.value=0,this.damping=.85,this.action=a}addForce(a){this.value+=a}update(){var a=1e-6n&&(j=-j,k=-k,l=-l,m=-m,n=-n);var o,p,q=Math.acos(n),r=Math.sqrt(1-n*n);return .001e){var f=this.cross(a,b);return 0<=d?Math.asin(this.mag(f)/c):Math.PI-Math.asin(this.mag(f)/c)}return Math.acos(d/c)},mix(c,a,b,d){return d=this.assert(d),d[0]=g.mix(c[0],a[0],b),d[1]=g.mix(c[1],a[1],b),d[2]=g.mix(c[2],a[2],b),d}};return c.INFO=b,Object.freeze(b),a=void 0===a?{}:a,a.EasyCam=c,a.DampedAction=d,a.Interpolation=e,a.Rotation=f,a.Vec3=h,a.Scalar=g,a}(Dw);p5&&(p5.prototype.createEasyCam=function(){var a=this._renderer,b=arguments[0];return arguments[0]instanceof p5.RendererGL&&(a=arguments[0],b=arguments[1]),new Dw.EasyCam(a,b)}); \ No newline at end of file