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

## 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 on other sites
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 on other sites
|
| (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 on other sites
Not an OpenGL question. Moved.

##### 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 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 on other sites
you also have ray-cylinder, ray-sphere, .... routines in the link I posted.

##### Share on other sites
Okay, thanks, i solved my problem.

greetings

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013734
×