richardsmd Posted January 24, 2017 Share Posted January 24, 2017 I've got a properly defined BABYLON.Ray with an origin, a rotation, and a length. How do I get the "destination" of the Ray? Thank you much! Mike Quote Link to comment Share on other sites More sharing options...
Wingnut Posted January 25, 2017 Share Posted January 25, 2017 Hiya @richardsmd, welcome to the forum. http://www.babylonjs-playground.com/#16CYXN#0 Sorry for the slow replies. I think line 22... might be of-interest to you. Hope this helps. Holler if you need more help. Babylon Playground searcher reports 946 hits... when searching for 'Ray'. Plenty of various examples to tour. Be well, party on! Quote Link to comment Share on other sites More sharing options...
adam Posted January 25, 2017 Share Posted January 25, 2017 I'm not sure what your definition of destination is, but this might help: http://www.babylonjs-playground.com/#ZHDBJ#36 Quote Link to comment Share on other sites More sharing options...
richardsmd Posted January 25, 2017 Author Share Posted January 25, 2017 I (perhaps incorrectly) conceptualize a ray as an origin point and a direction. Without a length the ray extends infinitely from it's origin, but a ray with a length has a constrained endpoint/destination. After I was clued into the existence of RayHelper I easily located the code: var endPoint = ray.origin.add(ray.direction.scale(ray.length)) Perhaps I should explain why I even want this... I'm trying to add additional movement controls to a freecamera. What I'd like to do is set scroll up/down to "jump" the camera some distance (say, 20 units) exactly along it's current path. Given the camera object, the easiest way I can think to do this is I was expecting to discover how to do this in Scene.pickWithRay. I followed the code as far as AbstractMesh.intersects, but now get the impression that I've incorrectly conceptualized how Ray's are used. @adam linked a playground demonstrating how to render a ray with a RayHelper. I found this in RayHelper.show which in conjunction with this playground (lines 38-42) that @Deltakosh provided in this post led to the following... /** Jump camera forward/backward in reaction to WheelEvent. * * @param {WheelEvent} e - the event. Must contain wheelDelta property. */ function onWheel(e) { let cam = scene.activeCamera; let invView = new Babylon.Matrix(); cam.getViewMatrix().invertToRef(invView); let direction = Babylon.Vector3.TransformNormal(Babylon.Vector3.Forward(), invView); direction.normalize(); // Go "backwards" on wheel down if (e.wheelDelta < 0) { direction.scaleInPlace(-1); } cam.position.addInPlace(direction.scale(20)); } canvas.addEventListener("mousewheel", onWheel); Thank you all very much for your assistance! Quote Link to comment Share on other sites More sharing options...
iiceman Posted January 25, 2017 Share Posted January 25, 2017 So you already figure it out, right? Or is still something that's not working? Here is your code in a playground for the sake of completeness (and because playgrounds are awesome): http://www.babylonjs-playground.com/#1FWN9P#0 Wingnut 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.