View Full Version : Obtaining intersection data using line/ray

Mukund

06-17-2011, 07:40 AM

Hello Everyone,

i came across a functionality in OpenSceneGraph, using which, i can find the intersection of a line with a rendered terrain(or any object in the way of the line's path), and with that approach i can find the heights of all points of the terrain.Basically the height of the terrain is where the line intersects the terrain.

i am curious as to how i can implement this on my own. Can anyone please suggest me how i can go about it?

i wish to do all the calculations on my own. Is there any way i can go about it?

Thanks.

carsten neumann

06-17-2011, 07:51 AM

...and with that approach i can find the heights of all points of the terrain.

You could also look at the vertex positions for the geometry that makes up the terrain - which seems simpler to do.

i am curious as to how i can implement this on my own. Can anyone please suggest me how i can go about it?

- transform the ray into the coordinate system of the object you want to intersect with.

- loop over all triangles in the object and intersect the ray with each, keeping track of the intersection point closest to the ray origin.

You can find information about how to do ray triangle intersections on the net or in books/articles about ray tracing.

Mukund

06-17-2011, 07:59 AM

Thanks for the response Carsten Neumann.

>>You could also look at the vertex positions for the geometry >>that makes up the terrain - which seems simpler to do.

Well it could be the case that i am loading a lot of models(obj,3ds etc). So, i don't think this approach is feasible.

- transform the ray into the coordinate system of the object you want to intersect with.

- loop over all triangles in the object and intersect the ray with each, keeping track of the intersection point closest to the ray origin.

So, what i can do is, shoot a ray, placing the object at a known position and find the intersections?

carsten neumann

06-17-2011, 08:47 AM

So, what i can do is, shoot a ray, placing the object at a known position and find the intersections?

Uhm, you kinda lost me, what are you actually trying to do (your original question suggested you wanted the height of some terrain at a given position)?

Nevertheless the above sounds a bit backwards to me, it's more like: shoot a ray, find the intersection and place the object at the intersection point -- that assumes your goal is to place an object in an existing scene.

Mukund

06-17-2011, 09:22 AM

Uhm, you kinda lost me, what are you actually trying to do (your original question suggested you wanted the height of some terrain at a given position)?

Nevertheless the above sounds a bit backwards to me, it's more like: shoot a ray, find the intersection and place the object at the intersection point -- that assumes your goal is to place an object in an existing scene.

im sorry, i was trying to explain the situation with the terrain example. It could be any object. i was just trying to know the Math behind these calculations. i found some links on Ray Tracing.

Thanks.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.