Tanner Lovelace (LOVELACE++at++dcscorp.com)
Tue, 11 Jul 1995 10:57:07 -0400
I'm trying to use performer's intersection routines to test for
obstacles in front of a vehicle. Unfortunately, I don't think
I entirely understand performer's approach to intersections.
Basically, given some base coordinate, I want to test for
intersections straight ahead, and to either side at a 40 degree
angle. I want to limit the test to about 100 meters in front of
the vehicle (it's not necessary to go out any further).
What follows is the code I have to do this. Unfortunately,
it doesn't seem to work. I'm sure I'm just overlooking something
obvious, and if anyone has any suggestions, I would be appreciative.
Thanks in advance.
Tanner Lovelace
DCS Corporation
Alexandria, VA
---------------------------------------------------------------------------
obstacle_scan_results_type is defined as a struct composed of
three floats (left, middle, right). Ignore the fact that
base_coord doesn't actually get set in this function.
otw_scene is the entire scene graph.
---------------------------------------------------------------------------
short scan_for_obstacles(obstacle_scan_results_type&
obstacle_scan_results,
pfScene *otw_scene)
{
static pfCoord base_coord;
static pfSegSet seg_set;
static pfHit **hits[3];
// Setup obstacle scan results to be a *very* big number to begin with.
// That way if we don't intersect, we'll just return the equivalent of
// infinity (float max).
obstacle_scan_results.left = FLT_MAX; // defined in limits.h
obstacle_scan_results.middle = FLT_MAX; // defined in limits.h
obstacle_scan_results.right = FLT_MAX; // defined in limits.h
// Copy the base coordinate to our segments. This will form three
// vectors starting at the same place and pointing to the same direction.
memcpy(&seg_set.segs[0].pos, &base_coord.xyz, sizeof(pfVec3));
memcpy(&seg_set.segs[0].dir, &base_coord.hpr, sizeof(pfVec3));
memcpy(&seg_set.segs[1].pos, &base_coord.xyz, sizeof(pfVec3));
memcpy(&seg_set.segs[1].dir, &base_coord.hpr, sizeof(pfVec3));
memcpy(&seg_set.segs[2].pos, &base_coord.xyz, sizeof(pfVec3));
memcpy(&seg_set.segs[2].dir, &base_coord.hpr, sizeof(pfVec3));
// Now, lets point two of the vectors to either side.
seg_set.segs[1].dir[0] = base_coord.hpr[0] - 40.0; // 40 degs ccw
seg_set.segs[2].dir[0] = base_coord.hpr[0] + 40.0; // 40 degs cw
// Setup length of our rays to intersect with.
seg_set.segs[0].length = 100; // 100 meters
seg_set.segs[1].length = 100; // 100 meters
seg_set.segs[2].length = 100; // 100 meters
// Set up segment to be tested against geometry
seg_set.mode = PFTRAV_IS_PRIM | PFTRAV_IS_CULL_BACK;
seg_set.userData = 0;
seg_set.activeMask = 0x7; // bit vector specifying which segs to use
seg_set.isectMask = PFUCOLLIDE_MASK;
seg_set.bound = 0;
seg_set.discFunc = 0;
if (pfSegsIsectNode(otw_scene, &seg_set, hits))
{
// Clip segment for next intersection test.
pfQueryHit(hits[0][0], PFQHIT_SEG, &seg_set.segs[0]);
// Set obstacle_scan_results to length
obstacle_scan_results.middle = seg_set.segs[0].length;
// Clip segment for next intersection test.
pfQueryHit(hits[1][0], PFQHIT_SEG, &seg_set.segs[1]);
// Set obstacle_scan_results to length
obstacle_scan_results.left = seg_set.segs[1].length;
// Clip segment for next intersection test.
pfQueryHit(hits[2][0], PFQHIT_SEG, &seg_set.segs[2]);
// Set obstacle_scan_results to length
obstacle_scan_results.right = seg_set.segs[2].length;
}
else
{
cout << "No collison detected!" << endl;
}
return 1;
}
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:51:39 PDT