Jump to content
  • Advertisement
Sign in to follow this  
Ludi83

Sending a Ray

This topic is 5096 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i want to send a ray from any position straight vertical to the ground to get the height information of the ground. It needn't to be fast, because i only want to use it for precalculating the height-informations. Are there any posibilites to do somethink like that? greetings

Share this post


Link to post
Share on other sites
Advertisement
u could do a ray->mesh intersection test which handles any data sort, though if youre using a heightmap u can do a faster ways,
heres one
u know the x,z points of height u wanna find
look into heightmap for the 3(tri) or 4(quad) points surrounding it, give each a weighting eg 0.333 or 0.25 (so it adds up to 1), now find out how close to each of these points your point is, use that to scale to that particular height, add the contribution for all 3/4 points and u have the final height of any point within the others,
check out barycentri coordinates

Share this post


Link to post
Share on other sites
P (your point)
|
| (vector/ray)
|
\/
----- (ground)

Get a maths book. "And then.."
- Linear function equation in 3d space
- Plane equation in 3d
Mix those two, you will obtain the place where the ray hit. Now we have 'hitpoint' and 'your point' . Now you just only need to figure out the magnitude of the vector , which shouldnt be hard :)

Unless your 'ground' is not a plane but is a mesh made of triangles and so on, then you could just read the vertexs` Z position or something (provided that the lowest vertex in mesh is at Z=0 in your 3d space).

I may be wrong though :)

Share this post


Link to post
Share on other sites
for heightmaps, based on regular heightfields, you can use bilinear interpolation to get the height you want.

For general purpose stuff, you need a fast ray-triangle intersection code. see here... You don't need to understand it fully, unless you like maths and you are particularly fond of Plucker coordinates.

Share this post


Link to post
Share on other sites
Hi,

the problem is i don't know what's under me. It could be everything, a plane, a sphere, and so on (but i know, there is something ^_^).

I thought i could use something like glReadpixels and glUnproject (this is used for OpenGL selection) vertical from my position.

greetings

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!