mwpowellhtx Posted May 9, 2016 Share Posted May 9, 2016 Hello, I want to convert the coordinates from a mouse click to canvas coordinates. The coordinates generated by jQuery.PEP "pointerdown" event are apparently "world" (browser?) coordinates, they are not canvas coordinates. I am also using the "hit" testing, which is fine for "selecting" meshes. But now I want to engage the canvas for "missed" hits, and respond to those clicks as well. Where might there be a "simple" translation I can use that doesn't involve a "positive" hit? Thank you... Michael Powell Quote Link to comment Share on other sites More sharing options...
mwpowellhtx Posted May 9, 2016 Author Share Posted May 9, 2016 Clarification: studying the numbers, I'm not sure that the coordinates are "world", but they appear to be at least "canvas". All I know is, they are unreasonable, and definitely not "scene", per se. So I need to convert to scene local from the given scale, whatever that is. Thanks! Quote Link to comment Share on other sites More sharing options...
Boz Posted May 9, 2016 Share Posted May 9, 2016 You can catch the 2D position of a click by using (event.clientX, event.clientY). After that, you have to subtract the canvas position (obtained via getBoundingClientRect()). http://www.babylonjs-playground.com/index.html#17QBL9#1 Quote Link to comment Share on other sites More sharing options...
mwpowellhtx Posted May 9, 2016 Author Share Posted May 9, 2016 Thanks for the feedback. Interesting! I started looking at whether I could coordinate different "kinds" of meshes in my scene in order to gauge fit-for-purpose click hits, which now that I consider it, I believe I could do so, and just key on naming conventions, etc. I appreciate the feedback though. Helps to sharpen the idea. Quote Link to comment Share on other sites More sharing options...
dbawel Posted May 10, 2016 Share Posted May 10, 2016 @mwpowellhtx - The following link I believe, should provide you with the info to answer your question: https://doc.babylonjs.com/tutorials/Picking_Collisions it's a very simple process, and I might copy and paste from this link as an example - but better for you to view the post yourself. DB Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.