Skip to content

Commit 763bde2

Browse files
authored
fixing dimenson in screenToWorld
1 parent 9393751 commit 763bde2

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

src/core/environment.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,25 +1314,24 @@ function environment(p5, fn, lifecycles){
13141314
*
13151315
*/
13161316
fn.screenToWorld = function(screenPosition) {
1317+
// remember how many components the caller actually provided to createVector
1318+
const origDimension = this.dimension;
1319+
13171320
if (typeof screenPosition === 'number') {
13181321
// We got passed numbers, convert to vector
13191322
screenPosition = this.createVector(...arguments);
13201323
}
1321-
1324+
13221325
const matrix = this._renderer.getWorldToScreenMatrix();
1323-
1324-
if (screenPosition.dimensions === 2) {
1326+
if (origDimension === 2) {
13251327
// Calculate a sensible Z value for the current camera projection that
13261328
// will result in 0 once converted to world coordinates
13271329
let z = matrix.mat4[14] / matrix.mat4[15];
13281330
screenPosition = this.createVector(screenPosition.x, screenPosition.y, z);
13291331
}
13301332

13311333
const matrixInverse = matrix.invert(matrix);
1332-
1333-
const worldPosition = matrixInverse
1334-
.multiplyAndNormalizePoint(screenPosition);
1335-
return worldPosition;
1334+
return matrixInverse.multiplyAndNormalizePoint(screenPosition);
13361335
};
13371336

13381337
/**

0 commit comments

Comments
 (0)