ozRocker Posted March 24, 2018 Share Posted March 24, 2018 Has anyone figured out how to still move the camera if the mouse pointer goes outside of the canvas? I'm working with a canvas that is only a small part of the screen but I don't want to restrict dragging to just the canvas area. It feels funny when you go outside the canvas then it stops moving Quote Link to comment Share on other sites More sharing options...
JohnK Posted March 24, 2018 Share Posted March 24, 2018 Will need a lot of work but an example anyway https://www.babylonjs-playground.com/#8JTMDX MarianG 1 Quote Link to comment Share on other sites More sharing options...
ozRocker Posted March 24, 2018 Author Share Posted March 24, 2018 53 minutes ago, JohnK said: Will need a lot of work but an example anyway https://www.babylonjs-playground.com/#8JTMDX Thank you! That actually helped. I used the directionX/Y, diff code from that to come up with my solution. My canvas is sitting in an iFrame, so I used this code: $(parent).on("pointermove", function(e) { if (mouseDown) { evt = e.originalEvent; var directionX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || 0; var directionY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || 0; diff = {x:-directionX /100, y:directionY /100} } }) $(parent).on("pointerup", function(e) { mouseDown = false; triggerMouseEvent (canvas, "pointerup"); }) $(canvas).on("pointerdown", function(e) { mouseDown = true; }) $(canvas).on("pointerup", function(e) { mouseDown = false; }) then in the render loop engine.runRenderLoop(function() { camera.alpha += diff.x; camera.beta -= diff.y; diff.x *= 0.9; diff.y *= 0.9; scene.render(); }); Works nice and smooth regardless of the size of the iFrame JohnK 1 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.