[Plib-devel] ssgIntersctLOS
Brought to you by:
sjbaker
From: Norman V. <nh...@ca...> - 2000-06-20 01:49:07
|
Hi All, In the process of rewriting the FlightGear elevation code, I have tried to make it generic enough to be of general use to the PLib community. If anyone is interested in BETA testing a collection of routines that will gather info about the intersection of a directed line segment and a SSG graph, drop me a line. Info gathered for each point of intersection: pointer to intersected leaf index of intersected face in said leaf coordinates of intersection point normal to face at intersection point Example Usage: ssgBranch *scene; sgVec3 line_orig, line_dir; // declare it FGHitList hit_list; // this is all you have to do :-) hit_list.Intersect( scene, line_orig, line_dir ) ; // Things you can do int closest = -1; float dist, min_dist = FLT_MAX; for ( int i=0; i<hit_list.num_hits(); i++ ) { ssgEntity *leaf = hit_list.get_entity(i); int tri_index = hit_list.get_face(i); sgVec3 this_point = hit_list.get_point(i); sgVec3 this_normal = hit_list.get_normal(i); dist = sgDistanceSquaredVec3( line_orig, this_point); if( dist < min_dist ) { min_dist = dist; closest = i; } short i1, i2, i3; leaf->getTriangle( tri_index, &i1, &i2, &i3 ); float intersected_tri[3][3]; sgCopyVec3(intersected_tri[0], leaf->getVertex(i1); sgCopyVec3(intersected_tri[1], leaf->getVertex(i2); sgCopyVec3(intersected_tri[2], leaf->getVertex(i3); } Cheers Norman Vine |