-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix mobile touch coordinates #4397
fix mobile touch coordinates #4397
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yikes good catch. I had assumed the reports we were getting about this were just about our touch controls in general being pretty floaty and unreliable (they need to be reworked) but this fixes a clear regression from adding the toolbar/sidebar. Made some minor suggestions you can apply if you like, but I can also just handle them when merging.
@@ -41,10 +41,11 @@ function shouldMoveCursor(touch, raycaster) { | |||
return true; | |||
} | |||
const rawIntersections = []; | |||
const canvas = document.querySelector(".a-canvas").getBoundingClientRect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only gets called in touchStart anyway so its not a huge deal, but querySelectors can be really slow so we try to avoid them when we can. Also the use of left
and top
on the next lines threw me because of the variable name, didn't notice the getBoundingClientRect()
at first
const canvas = document.querySelector(".a-canvas").getBoundingClientRect(); | |
const canvasRect = AFRAME.scense[0].getBoundingClientRect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed some changes:
We actually have a ref to canvas in this.canvas
, and I store canvas rect in this.canvasRect
and update it on resize using ResizeObserver
.
Since shouldMoveCursor
is outside of the class and does not see this.canvasRect
, I pass rect to the function as well.
raycaster.setFromCamera( | ||
{ | ||
x: (touch.clientX / window.innerWidth) * 2 - 1, | ||
y: -(touch.clientY / window.innerHeight) * 2 + 1 | ||
x: ((touch.clientX - canvas.left) / canvas.width) * 2 - 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x: ((touch.clientX - canvas.left) / canvas.width) * 2 - 1, | |
x: ((touch.clientX - canvasRect.left) / canvasRect.width) * 2 - 1, |
x: (touch.clientX / window.innerWidth) * 2 - 1, | ||
y: -(touch.clientY / window.innerHeight) * 2 + 1 | ||
x: ((touch.clientX - canvas.left) / canvas.width) * 2 - 1, | ||
y: -((touch.clientY - canvas.top) / canvas.height) * 2 + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
y: -((touch.clientY - canvas.top) / canvas.height) * 2 + 1 | |
y: -((touch.clientY - canvasRect.top) / canvasRect.height) * 2 + 1 |
(touch.clientX / this.canvas.clientWidth) * 2 - 1, | ||
-(touch.clientY / this.canvas.clientHeight) * 2 + 1 | ||
((touch.clientX - this.canvasRect.left) / this.canvasRect.width) * 2 - 1, | ||
-((touch.clientY - this.canvasRect.top) / this.canvasRect.height) * 2 + 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated calculation here too
@netpro2k @yakyouk we also have a fix for this, since the main issue was that We have this in production on https://vreign.space if you'd like to test. Dom, let me know if you'd like to see this in its own PR or combined yakyouk's work here |
Yep I think a separate PR would be nice, since this is already ready to merge. |
After verifying some mobile issues I noticed that waypoints and links to other rooms or websites don’t work on mobile devices if the “Create and move objects” setting from room settings is disabled, the issues are not reproducible for the creator of the room but all the other users are affected. |
Fixes buttons partially clickable or not clickable on mobile
#4075
#4297
#4394
Touch coordinates calculation in
shouldMoveCursor
was usingwindow.innerWidth
andwindow.innerHeight
, but the a-frame canvas is not always filling the window, e.g. with the new UI's toolbar.Changed
window.innerWidth
andwindow.innerHeight
toa-canvas
element's width and height.In case the canvas is further embedded in a UI in the future, the code also subtracts the canvas' left and top offsets from
touch.clientX
andtouch.clientY
.Notes:
singleActionButton
buttons don't work for users who do not have the right to move objects.┆Issue is synchronized with this Jira Task