Sending a Ray
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
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
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 :)
|
| (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 :)
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement