camera-2d-simple
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -0,1 +1,5 @@ | ||
**v2.0.1** | ||
- Micro change in how glMatrix is imported | ||
**v2.0.0** | ||
@@ -2,0 +6,0 @@ |
@@ -1,3 +0,2 @@ | ||
import { create, getTranslation, invert, getScaling, fromTranslation, multiply, fromScaling, fromRotation } from 'gl-matrix/mat4'; | ||
import { transformMat4 } from 'gl-matrix/vec4'; | ||
import { mat4, vec4 } from 'gl-matrix'; | ||
@@ -16,14 +15,14 @@ const VIEW_CENTER = [0, 0, 0, 1]; | ||
let view = create(); | ||
let view = mat4.create(); | ||
const getRotation = () => Math.acos(view[0]); | ||
const getScaling$1 = () => getScaling(scratch0, view)[0]; | ||
const getScaling = () => mat4.getScaling(scratch0, view)[0]; | ||
const getDistance = () => 1 / getScaling$1(); | ||
const getDistance = () => 1 / getScaling(); | ||
const getTranslation$1 = () => getTranslation(scratch0, view).slice(0, 2); | ||
const getTranslation = () => mat4.getTranslation(scratch0, view).slice(0, 2); | ||
const getTarget = () => | ||
transformMat4(scratch0, VIEW_CENTER, invert(scratch2, view)); | ||
vec4.transformMat4(scratch0, VIEW_CENTER, mat4.invert(scratch2, view)); | ||
@@ -34,3 +33,3 @@ const getView = () => view; | ||
// Reset the view | ||
view = create(); | ||
view = mat4.create(); | ||
@@ -47,7 +46,7 @@ translate([-x, -y]); | ||
const t = fromTranslation(scratch1, scratch0); | ||
const t = mat4.fromTranslation(scratch1, scratch0); | ||
// Translate about the viewport center | ||
// This is identical to `i * t * i * view` where `i` is the identity matrix | ||
multiply(view, t, view); | ||
mat4.multiply(view, t, view); | ||
}; | ||
@@ -62,16 +61,16 @@ | ||
const s = fromScaling(scratch1, scratch0); | ||
const s = mat4.fromScaling(scratch1, scratch0); | ||
const scaleCenter = mousePos ? [...mousePos, 0] : VIEW_CENTER; | ||
const a = fromTranslation(scratch0, scaleCenter); | ||
const a = mat4.fromTranslation(scratch0, scaleCenter); | ||
// Translate about the scale center | ||
// I.e., the mouse position or the view center | ||
multiply( | ||
mat4.multiply( | ||
view, | ||
a, | ||
multiply( | ||
mat4.multiply( | ||
view, | ||
s, | ||
multiply(view, invert(scratch2, a), view) | ||
mat4.multiply(view, mat4.invert(scratch2, a), view) | ||
) | ||
@@ -82,8 +81,8 @@ ); | ||
const rotate = rad => { | ||
const r = create(); | ||
fromRotation(r, rad, [0, 0, 1]); | ||
const r = mat4.create(); | ||
mat4.fromRotation(r, rad, [0, 0, 1]); | ||
// Rotate about the viewport center | ||
// This is identical to `i * r * i * view` where `i` is the identity matrix | ||
multiply(view, r, view); | ||
mat4.multiply(view, r, view); | ||
}; | ||
@@ -105,3 +104,3 @@ | ||
get translation() { | ||
return getTranslation$1(); | ||
return getTranslation(); | ||
}, | ||
@@ -112,3 +111,3 @@ get target() { | ||
get scaling() { | ||
return getScaling$1(); | ||
return getScaling(); | ||
}, | ||
@@ -115,0 +114,0 @@ get distance() { |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('gl-matrix/mat4'), require('gl-matrix/vec4')) : | ||
typeof define === 'function' && define.amd ? define(['gl-matrix/mat4', 'gl-matrix/vec4'], factory) : | ||
(global = global || self, global.createCamera2d = factory(global.glMatrix.mat4, global.glMatrix.vec4)); | ||
}(this, (function (mat4, vec4) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('gl-matrix')) : | ||
typeof define === 'function' && define.amd ? define(['gl-matrix'], factory) : | ||
(global = global || self, global.createCamera2d = factory(global.glMatrix)); | ||
}(this, (function (glMatrix) { 'use strict'; | ||
@@ -23,13 +23,13 @@ var VIEW_CENTER = [0, 0, 0, 1]; | ||
var view = mat4.create(); | ||
var view = glMatrix.mat4.create(); | ||
var getRotation = function () { return Math.acos(view[0]); }; | ||
var getScaling = function () { return mat4.getScaling(scratch0, view)[0]; }; | ||
var getScaling = function () { return glMatrix.mat4.getScaling(scratch0, view)[0]; }; | ||
var getDistance = function () { return 1 / getScaling(); }; | ||
var getTranslation = function () { return mat4.getTranslation(scratch0, view).slice(0, 2); }; | ||
var getTranslation = function () { return glMatrix.mat4.getTranslation(scratch0, view).slice(0, 2); }; | ||
var getTarget = function () { return vec4.transformMat4(scratch0, VIEW_CENTER, mat4.invert(scratch2, view)); }; | ||
var getTarget = function () { return glMatrix.vec4.transformMat4(scratch0, VIEW_CENTER, glMatrix.mat4.invert(scratch2, view)); }; | ||
@@ -46,3 +46,3 @@ var getView = function () { return view; }; | ||
// Reset the view | ||
view = mat4.create(); | ||
view = glMatrix.mat4.create(); | ||
@@ -63,7 +63,7 @@ translate([-x, -y]); | ||
var t = mat4.fromTranslation(scratch1, scratch0); | ||
var t = glMatrix.mat4.fromTranslation(scratch1, scratch0); | ||
// Translate about the viewport center | ||
// This is identical to `i * t * i * view` where `i` is the identity matrix | ||
mat4.multiply(view, t, view); | ||
glMatrix.mat4.multiply(view, t, view); | ||
}; | ||
@@ -78,16 +78,16 @@ | ||
var s = mat4.fromScaling(scratch1, scratch0); | ||
var s = glMatrix.mat4.fromScaling(scratch1, scratch0); | ||
var scaleCenter = mousePos ? mousePos.concat( [0]) : VIEW_CENTER; | ||
var a = mat4.fromTranslation(scratch0, scaleCenter); | ||
var a = glMatrix.mat4.fromTranslation(scratch0, scaleCenter); | ||
// Translate about the scale center | ||
// I.e., the mouse position or the view center | ||
mat4.multiply( | ||
glMatrix.mat4.multiply( | ||
view, | ||
a, | ||
mat4.multiply( | ||
glMatrix.mat4.multiply( | ||
view, | ||
s, | ||
mat4.multiply(view, mat4.invert(scratch2, a), view) | ||
glMatrix.mat4.multiply(view, glMatrix.mat4.invert(scratch2, a), view) | ||
) | ||
@@ -98,8 +98,8 @@ ); | ||
var rotate = function (rad) { | ||
var r = mat4.create(); | ||
mat4.fromRotation(r, rad, [0, 0, 1]); | ||
var r = glMatrix.mat4.create(); | ||
glMatrix.mat4.fromRotation(r, rad, [0, 0, 1]); | ||
// Rotate about the viewport center | ||
// This is identical to `i * r * i * view` where `i` is the identity matrix | ||
mat4.multiply(view, r, view); | ||
glMatrix.mat4.multiply(view, r, view); | ||
}; | ||
@@ -106,0 +106,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("gl-matrix/mat4"),require("gl-matrix/vec4")):"function"==typeof define&&define.amd?define(["gl-matrix/mat4","gl-matrix/vec4"],r):(t=t||self).createCamera2d=r(t.glMatrix.mat4,t.glMatrix.vec4)}(this,(function(t,r){"use strict";var e=[0,0,0,1];return function(n,a,i){void 0===n&&(n=[0,0]),void 0===a&&(a=1),void 0===i&&(i=0);var o=new Float32Array(16),l=new Float32Array(16),u=new Float32Array(16),c=t.create(),v=function(){return t.getScaling(o,c)[0]},f=function(r,e,n){void 0===r&&(r=[]);var a=r[0];void 0===a&&(a=0);var i=r[1];void 0===i&&(i=0),void 0===e&&(e=1),void 0===n&&(n=0),c=t.create(),m([-a,-i]),g(n),d(1/e)},m=function(r){void 0===r&&(r=[]);var e=r[0];void 0===e&&(e=0);var n=r[1];void 0===n&&(n=0),o[0]=e,o[1]=n,o[2]=0;var a=t.fromTranslation(l,o);t.multiply(c,a,c)},d=function(r,n){if(!(r<=0)){o[0]=r,o[1]=r,o[2]=1;var a=t.fromScaling(l,o),i=n?n.concat([0]):e,v=t.fromTranslation(o,i);t.multiply(c,v,t.multiply(c,a,t.multiply(c,t.invert(u,v),c)))}},g=function(r){var e=t.create();t.fromRotation(e,r,[0,0,1]),t.multiply(c,e,c)};return f(n,a,i),{get translation(){return t.getTranslation(o,c).slice(0,2)},get target(){return r.transformMat4(o,e,t.invert(u,c))},get scaling(){return v()},get distance(){return 1/v()},get rotation(){return Math.acos(c[0])},get view(){return c},lookAt:f,translate:m,pan:m,rotate:g,scale:d,zoom:d,reset:function(){f(n,a,i)},set:function(t){!t||t.length<16||(c=t)}}}})); | ||
!function(t,a){"object"==typeof exports&&"undefined"!=typeof module?module.exports=a(require("gl-matrix")):"function"==typeof define&&define.amd?define(["gl-matrix"],a):(t=t||self).createCamera2d=a(t.glMatrix)}(this,(function(t){"use strict";var a=[0,0,0,1];return function(e,r,n){void 0===e&&(e=[0,0]),void 0===r&&(r=1),void 0===n&&(n=0);var o=new Float32Array(16),i=new Float32Array(16),m=new Float32Array(16),l=t.mat4.create(),u=function(){return t.mat4.getScaling(o,l)[0]},c=function(a,e,r){void 0===a&&(a=[]);var n=a[0];void 0===n&&(n=0);var o=a[1];void 0===o&&(o=0),void 0===e&&(e=1),void 0===r&&(r=0),l=t.mat4.create(),f([-n,-o]),d(r),v(1/e)},f=function(a){void 0===a&&(a=[]);var e=a[0];void 0===e&&(e=0);var r=a[1];void 0===r&&(r=0),o[0]=e,o[1]=r,o[2]=0;var n=t.mat4.fromTranslation(i,o);t.mat4.multiply(l,n,l)},v=function(e,r){if(!(e<=0)){o[0]=e,o[1]=e,o[2]=1;var n=t.mat4.fromScaling(i,o),u=r?r.concat([0]):a,c=t.mat4.fromTranslation(o,u);t.mat4.multiply(l,c,t.mat4.multiply(l,n,t.mat4.multiply(l,t.mat4.invert(m,c),l)))}},d=function(a){var e=t.mat4.create();t.mat4.fromRotation(e,a,[0,0,1]),t.mat4.multiply(l,e,l)};return c(e,r,n),{get translation(){return t.mat4.getTranslation(o,l).slice(0,2)},get target(){return t.vec4.transformMat4(o,a,t.mat4.invert(m,l))},get scaling(){return u()},get distance(){return 1/u()},get rotation(){return Math.acos(l[0])},get view(){return l},lookAt:c,translate:f,pan:f,rotate:d,scale:v,zoom:v,reset:function(){c(e,r,n)},set:function(t){!t||t.length<16||(l=t)}}}})); |
{ | ||
"name": "camera-2d-simple", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "2D camera for WebGL", | ||
@@ -34,4 +34,5 @@ "author": "Fritz Lekschas", | ||
"rollup": "^1.31.0", | ||
"rollup-plugin-buble": "^0.19.8", | ||
"rollup-plugin-filesize": "^6.2.1", | ||
"rollup-plugin-terser": "^5.2.0", | ||
"rollup-plugin-visualizer": "^3.3.1", | ||
"tap-spec": "^5.0.0", | ||
@@ -38,0 +39,0 @@ "tape": "^4.13.0" |
@@ -14,4 +14,4 @@ # 2D Camera | ||
- [canvas-camera-2d](https://github.com/flekschas/canvas-camera-2d) for attaching the camera to a canvas object | ||
- [webgl-scatterplot](https://github.com/flekschas/webgl-scatterplot) for an application | ||
- [dom-2d-camera](https://github.com/flekschas/dom-2d-camera) for attaching the camera to a DOM object | ||
- [regl-scatterplot](https://github.com/flekschas/regl-scatterplot) for an application | ||
@@ -18,0 +18,0 @@ ## Install |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
14795
0
13
223