Skip to content

Commit fdcb9da

Browse files
committed
Fix the picker, which wasn’t picking up the right coordinates.
We’ll have another go at doing without jQuery later…
1 parent 8bc1917 commit fdcb9da

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

js/src/jupyter-threejs.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ define(["jupyter-js-widgets", "underscore", "three"],
77
require("./examples/js/controls/OrbitControls.js");
88
require("./examples/js/controls/MomentumCameraControls.js");
99
require("./examples/js/controls/TrackballControls.js");
10+
var $ = require("jquery");
11+
1012
var Detector = require("./examples/js/Detector.js");
1113

1214
var RendererView = widgets.DOMWidgetView.extend({
@@ -495,8 +497,10 @@ define(["jupyter-js-widgets", "underscore", "three"],
495497
this.model.on('change:root', this.change_root, this);
496498
this.change_root(this.model, this.model.get('root'));
497499
this.options.dom.addEventListener(this.model.get('event'), function(event) {
498-
var mouseX = ((event.pageX - this.offsetLeft) / that.options.dom.getBoundingClientRect().width) * 2 - 1;
499-
var mouseY = -((event.pageY - this.offsetTop) / that.options.dom.getBoundingClientRect().height) * 2 + 1;
500+
var offset = $(this).offset();
501+
var $el = $(that.options.dom);
502+
var mouseX = ((event.pageX - offset.left) / $el.width()) * 2 - 1;
503+
var mouseY = -((event.pageY - offset.top) / $el.height()) * 2 + 1;
500504
var vector = new THREE.Vector3(mouseX, mouseY, that.options.renderer.camera.obj.near);
501505

502506
vector.unproject(that.options.renderer.camera.obj);

0 commit comments

Comments
 (0)