## How do you determine terrain elevation (Y coord)?

### How do you determine terrain elevation (Y coord)?

Has anyone developed a fast algorithm, or know of an
OpenInventor function to determine terrain elevation (Y coord)
given X and Z coords?  Or, has anyone developed a terrain
following algorithm using OpenInventor?

I am trying to determine the elevation (the Y coordinate) of
particular points in my terrain database at run-time.  I would
like to have tanks, etc. drive over the database and pitch and
roll accordingly to the changes in elevation.  To do this I
need to know the elevation of the terrain under the tank.

If possible, I would like to avoid searching the entire scene
graph for the polygon under the tank and determining elevation
from there.

My first thought was to use the SoRayPickAction to determine
the elevation.  I would like to cast the ray through to tank
and have it determine the objects below it.  However, I
believe SoRayPickAction uses the viewport and camera positions
which is not what I want.  Any ideas???

Thanks for any help or suggestions.

Wm. Frank Dea
--
Research Engineer
Southwest Research Institute (SwRI)
San Antonio, TX

### How do you determine terrain elevation (Y coord)?

> My first thought was to use the SoRayPickAction to determine
> the elevation.  I would like to cast the ray through to tank
> and have it determine the objects below it.  However, I
> believe SoRayPickAction uses the viewport and camera positions
> which is not what I want.  Any ideas???

Assuming that there are no caverns in your terrain, and that all
of the elevations are greater than or equal to zero:

start     = SbVec3f (tank_x, 0., tank_z) ;
direction = SbVec3f (0., 1., 0.) ;
near      =  0. ;
far       = -1 ;
SoRayPickAction::setRay (start, direction, near, far) ;

Quote:> If possible, I would like to avoid searching the entire scene
> graph for the polygon under the tank and determining elevation
> from there.

That depends on what you apply the action to.

SoAction::apply()

--
Ted Hall                                       ^
Department of Architecture                    '-`
Chinese University of Hong Kong             '- - -`
Sha Tin, New Territories                 '- - - - - -`
HONG KONG                           \'- - - - - - - - - -`/

I've been trying to work out some of the ray-casting stuff by hand in
order to implement a quasi-3D view (ala Doom, Wolf3D, etc).  Supposing
you have a wall defined by two points.  If you shoot a ray it is simple
to determine where the ray would intersect the wall.  But how do you know
if the ray strikes above or below the wall without resorting to 3D?  I
was thinking it had to be a function of the distance the ray travelled to
get to the wall.

On the same subject, does anyone know how to narrow down which wall
segments to check so each ray doesn't have to check them all?

Actually, another question is, is there some simple way of knowing
whether the intersection of two lines occurs within a segment of one of
the lines without resorting to four comparisions?  That is, something
other than
if(Px > Wx1 && Px < Wx2 && Py > Wy1 && Py < Wy2)
In fact, this presupposes that Wx1<Wx2 and Wy1<Wy2 in the first place.
(Px,y=Intersection Point, Wx1,y1 and Wx2,y2 are the wall's endpoints)

Anyway, any ideas would be appreciated.

Alex