Jump to content

Tracking the mouse


Andrey Zimin
 Share

Recommended Posts

Hello, friends! I'm tracking the mouse movement around the object. How do I get the mouse coordinates relative to this object rather than the screen? When I use BABYLON.PointerEventTypes.POINTERDOWN, then I can get it, and how to do it if you use BABYLON.PointerEventTypes.POINTERMOVE ?

scene.onPointerObservable.add((evt) => {
    logger.log('evt', evt)
}, BABYLON.PointerEventTypes.POINTERMOVE)
Link to comment
Share on other sites

If you mean relative to the object, as in the canvas, then I think it's event.offsetX and event.offsetY.
Those are x,y coordinates from the top left corner and I think they are from : https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX
I haven't tried on a mobile (non-mouse) device, where you may have better luck with code like this:
 

canvas.addEventListener("pointermove", function(evt) {
  // x,y from scene object, not event.
  pickTouchResult = scene.pick(scene.pointerX, scene.pointerY);       
});

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...