VR-Forces 4.1.1 Class Documentation
15.3 - Querying the Terrain Interface

DtTerrainInterface provides a set of intersection methods you can use to query the terrain database, using 3D chords to define the segment and direction of interest for intersections.

You can ask:

Additionally, for a given intersection query you can specify what kinds of information you want to receive:

For example, to query the terrain interface for the intersection with the terrain surface, returning the location of the intersection only, do the following:

// Set up chord for intersection test. Query starts at p1 and ends at p2.
DtPoint p1(2200, 2200, 10000);
DtPoint p2(2200, 2200, -10000);
DtChord chord(p1, p2);
DtPoint isectPoint;
double intersectionTime;
// Calculate intersection with the terrain skin
if(terrainInterface->intersect(chord, isectPoint, intersectionTime))
{
DtInfo("Intersected terrain at location %s\n", isectPoint.string());
}

You can use the intersectionTime parameter returned in the intersect() method to determine where along the chord the intersection with the terrain occurred. Values for intersection time t, given a chord(p1, p2) indicate the following:

intersectionpoint.png
Intersection Point

In the figure, a call to intersect() with chord (P0, P1) intersects the terrain at point Q. The method will return TRUE, because point Q lies along the chord, and the intersection time at Q will be a value between 0 and 1. The intersection time at point R (which lies on an extension of the chord) has an intersection time > 1.

To get more information about the intersection point, you can call a variant of intersect() that returns a DtChordIntersectionRecord (chrdIntRec.h), instead of just the DtPoint. The DtChordIntersectionRecord can return information such as the location of the intersection, surface type, normal vector of the terrain at that point, and the polygon intersected. For example, to make an intersection test (similar to the previous example), requesting the intersection point and normal, do the following:

// Set up chord for intersection test. Query starts at p1 and ends at p2.
DtPoint p1(2200, 2200, 10000);
DtPoint p2(2200, 2200, -10000);
DtChord chord(p1, p2);
// Return intersection details in intersectRecord
DtChordIntersectionRecord intersectRecord;
// Calculate intersection with terrain skin, requesting that the normal
// and the location of the intersection point be retrieved.
DtGdbNodeDtIntersectRecordType flag = (DtGdbNodeDtIntersectRecordType)(DtGdbNodeIRT_IPOINT | DtGdbNodeIRT_INORMAL);
// Try to intersect the terrain to get the left triangle
if(terrainInterface.intersect(chord, intersectionRecord, flag))
{
DtInfo("Normal at terrain intersection %s is %s\n",
intersectRecord.intesectionPoint().string(),
intersectRecord.normal().string());
}

[<< Using the DtTerrainInterface Class] [Home] [Top of Page] [Using Vector Networks >>]


Document ID: Generated on Mon Apr 8 19:24:01 EDT 2013 from SVN revision 125877
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)