Sending a Ray

Started by
6 comments, last by Ludi83 19 years, 3 months ago
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
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
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 :)
-- Lukasz SzczepanskiAssociate Producer, Gamelion Studios - Polandhttp://nestor.vg Periodic gaming and design rantings.
Not an OpenGL question. Moved.

____________________________________________________________www.elf-stone.com | Automated GL Extension Loading: GLee 5.00 for Win32 and Linux

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.

Everything is better with Metal.

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

Everything is better with Metal.

Okay, thanks, i solved my problem.

greetings

This topic is closed to new replies.

Advertisement