From 6dbfe655f1e23c54ec4b655e71c711ea9f252b28 Mon Sep 17 00:00:00 2001 From: nicolas garcia belmonte Date: Wed, 11 Mar 2015 09:57:17 -0700 Subject: [PATCH] Add pixelRatio option to scene.pick Usage: if (e.x < thumbViewportWidth / pixelRatio && e.y > window.innerHeight - thumbViewportHeight / pixelRatio && scenePicking) { scenePicking.pick(e.x, e.y - (window.innerHeight - thumbViewportHeight / pixelRatio), { pixelRatio: pixelRatio, viewport: { x: thumbViewportX, y: thumbViewportY, width: thumbViewportWidth, height: thumbViewportHeight } }); } --- src/scene.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/scene.js b/src/scene.js index ed7ed202..a130a7de 100644 --- a/src/scene.js +++ b/src/scene.js @@ -289,8 +289,6 @@ this.pickingProgram = program; }, - //returns an element at the given position - //returns an element at the given position pick: function(x, y, opt) { opt = opt || {}; //setup the picking program if this is @@ -311,13 +309,14 @@ memoFog = config.effects.fog, canvas = gl.canvas, viewport = opt.viewport || {}, - width = viewport.width || canvas.offsetWidth || canvas.width, - height = viewport.height || canvas.offsetHeight || canvas.height, + pixelRatio = opt.pixelRatio || 1, + width = (viewport.width || canvas.offsetWidth || canvas.width), + height = (viewport.height || canvas.offsetHeight || canvas.height), floor = Math.floor, resWidth = 5, resHeight = 1, - xp = x - (viewport.x || 0), - yp = y - (viewport.y || 0), + xp = (x * pixelRatio - (viewport.x || 0)), + yp = (y * pixelRatio - (viewport.y || 0)), ndcx = xp * 2 / width - 1, ndcy = 1 - yp * 2 / height, target = this.unproject([ndcx, ndcy, 1.0], camera),