Skip to content

Commit

Permalink
Add pixelRatio option to scene.pick
Browse files Browse the repository at this point in the history
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
            }
          });
        }
  • Loading branch information
philogb committed Mar 11, 2015
1 parent 3e1da0b commit 6dbfe65
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/scene.js
Expand Up @@ -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
Expand All @@ -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),
Expand Down

0 comments on commit 6dbfe65

Please sign in to comment.