From 7cb77a957bb60e97f92069ea3edf59bac2d0782c Mon Sep 17 00:00:00 2001 From: Yehonatan Daniv Date: Wed, 18 Dec 2024 17:53:47 +0200 Subject: [PATCH] Fix mouse y invert (#61) * Fixed mouse utility to invert y coordinate internally * 0.14.6 --- CHANGELOG.md | 6 ++++++ dist/index.cjs | 7 ++++--- docs/index.html | 7 ++++--- index.umd.js | 7 ++++--- package-lock.json | 4 ++-- package.json | 2 +- src/utilities/mouse.js | 7 ++++--- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cef5b4a..3afa810 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +### 0.14.6 (2024-12-18) + +_Fixed:_ + +- Fixed `mouse` utility to invert `y` coordinate internally. + ### 0.14.5 (2024-12-18) _Fixed:_ diff --git a/dist/index.cjs b/dist/index.cjs index e1887d5..99c6b6c 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -48,6 +48,7 @@ function resolution({ /** * Exposes the `u_mouse` uniform for use inside fragment shaders. + * Note that internally the `y` coordinate is inverted to match the WebGL coordinate system. * * @function mouse * @param {Object} [params] @@ -74,17 +75,17 @@ function mouse({ }, get position() { const [x, y] = this.uniforms[0].data; - return { x, y }; + return { x, y: 1 - y }; }, set position({ x, y }) { if (typeof x !== 'undefined') this.uniforms[0].data[0] = x; - if (typeof y !== 'undefined') this.uniforms[0].data[1] = y; + if (typeof y !== 'undefined') this.uniforms[0].data[1] = 1 - y; }, uniforms: [ { name: 'u_mouse', type: 'f', - data: [initial.x || 0, initial.y || 0], + data: [initial.x || 0, 1 - initial.y || 0], }, ], }; diff --git a/docs/index.html b/docs/index.html index 952f9e2..138913e 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,7 +2,7 @@ - kampos 0.14.4 | Documentation + kampos 0.14.5 | Documentation @@ -15,7 +15,7 @@

kampos

-
0.14.4
+
0.14.5
-

Exposes the u_mouse uniform for use inside fragment shaders.

+

Exposes the u_mouse uniform for use inside fragment shaders. +Note that internally the y coordinate is inverted to match the WebGL coordinate system.

mouse(params: Object?): mouseUtility
diff --git a/index.umd.js b/index.umd.js index bda721f..bb0226f 100644 --- a/index.umd.js +++ b/index.umd.js @@ -52,6 +52,7 @@ /** * Exposes the `u_mouse` uniform for use inside fragment shaders. + * Note that internally the `y` coordinate is inverted to match the WebGL coordinate system. * * @function mouse * @param {Object} [params] @@ -78,17 +79,17 @@ }, get position() { const [x, y] = this.uniforms[0].data; - return { x, y }; + return { x, y: 1 - y }; }, set position({ x, y }) { if (typeof x !== 'undefined') this.uniforms[0].data[0] = x; - if (typeof y !== 'undefined') this.uniforms[0].data[1] = y; + if (typeof y !== 'undefined') this.uniforms[0].data[1] = 1 - y; }, uniforms: [ { name: 'u_mouse', type: 'f', - data: [initial.x || 0, initial.y || 0], + data: [initial.x || 0, 1 - initial.y || 0], }, ], }; diff --git a/package-lock.json b/package-lock.json index 77aea11..9dd6f8b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "kampos", - "version": "0.14.5", + "version": "0.14.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "kampos", - "version": "0.14.5", + "version": "0.14.6", "license": "MIT", "devDependencies": { "@babel/core": "^7.26.0", diff --git a/package.json b/package.json index 1bbd1a5..8789062 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kampos", - "version": "0.14.5", + "version": "0.14.6", "description": "Tiny and fast effects compositor on WebGL", "registry": "https://registry.npmjs.org/", "main": "dist/index.cjs", diff --git a/src/utilities/mouse.js b/src/utilities/mouse.js index 9271223..e43c216 100644 --- a/src/utilities/mouse.js +++ b/src/utilities/mouse.js @@ -1,5 +1,6 @@ /** * Exposes the `u_mouse` uniform for use inside fragment shaders. + * Note that internally the `y` coordinate is inverted to match the WebGL coordinate system. * * @function mouse * @param {Object} [params] @@ -26,17 +27,17 @@ function mouse({ }, get position() { const [x, y] = this.uniforms[0].data; - return { x, y }; + return { x, y: 1 - y }; }, set position({ x, y }) { if (typeof x !== 'undefined') this.uniforms[0].data[0] = x; - if (typeof y !== 'undefined') this.uniforms[0].data[1] = y; + if (typeof y !== 'undefined') this.uniforms[0].data[1] = 1 - y; }, uniforms: [ { name: 'u_mouse', type: 'f', - data: [initial.x || 0, initial.y || 0], + data: [initial.x || 0, 1 - initial.y || 0], }, ], };