Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DomEvent _onMouseEvent/_onMouseMove error when Scroll #15

Open
bloublou opened this issue Feb 6, 2012 · 4 comments
Open

DomEvent _onMouseEvent/_onMouseMove error when Scroll #15

bloublou opened this issue Feb 6, 2012 · 4 comments

Comments

@bloublou
Copy link

bloublou commented Feb 6, 2012

Hello,

First thanks for your lib.

About the issue :
When no scroll is set no problem, all works fine and mouse event fired on correct object.
But when canvas container is on a page, and page is scrolling a bug appears : Mouse position does not calculate correctly and a bad or no object is selected :

original code : OK in case domElement == window
var mouseX = +(domEvent.clientX / window.innerWidth ) * 2 - 1;
var mouseY = -(domEvent.clientY / window.innerHeight) * 2 + 1;

but KO if domElement != window
one possible solution for _onMouseEvent/_onMouseMove :

var mouseX = +((domEvent.clientX - this.domElement.offset().left + $(window).scrollLeft()) / this.domElement.width()) * 2 - 1;
var mouseY = -((domEvent.clientY - this.domElement.offset().top + $(window).scrollTop()) / this.domElement.height()) * 2 + 1;

Now ScrollLeft/Top are taken into consideration with domElement position.

PoP

@jeromeetienne
Copy link
Owner

thanks for the report.

I just noticed your solution imply depending on jquery. i would prefere to adding this dependancies to this bug. one without jquery would be better if possible

@jeromeetienne
Copy link
Owner

is it ok to replace it with https://developer.mozilla.org/en/DOM/element.scrollLeft ?

im not much of a frontend personn

@bloublou
Copy link
Author

bloublou commented Feb 7, 2012

It's fine, i used jquery because it avoid some trouble ( http:https://help.dottoro.com/ljcjgrml.php )

Same remarks with Threex.WindowResize, it takes window as default, should be possible to add a domElement ?
ex : THREEx.WindowResize = function (renderer, camera, domElement)
with : var domElement = domElement || window;

and then use it on callback function to set camera aspect & renderer size .

thx,
PoP

@jeromeetienne
Copy link
Owner

i tried to port it for 20 min with little success. could you do a pull request without jquery dependancy ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants