# Determine Ray destination

## Recommended Posts

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

##### Share on other sites

Hiya @richardsmd, welcome to the forum.

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!

##### Share on other sites

I'm not sure what your definition of destination is, but this might help:

##### Share on other sites

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);
}

}
``````

Thank you all very much for your assistance!

##### Share on other sites

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

## 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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.