From: frohlich Date: Thu, 8 Jun 2006 05:58:36 +0000 (+0000) Subject: Make use of the ground material types X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4fde3031ebd16e03cf29e7622d10d996f6f14976;p=flightgear.git Make use of the ground material types --- diff --git a/src/Scenery/hitlist.cxx b/src/Scenery/hitlist.cxx index 3a7a46159..264c6f9f8 100644 --- a/src/Scenery/hitlist.cxx +++ b/src/Scenery/hitlist.cxx @@ -702,7 +702,8 @@ bool fgCurrentElev( sgdVec3 abs_view_pos, double max_alt_m, sgdVec3 scenery_center, ssgTransform *terra_transform, FGHitList *hit_list, - double *terrain_elev, double *radius, double *normal) + double *terrain_elev, double *radius, double *normal, + int & this_hit ) { // SGTimeStamp start; start.stamp(); @@ -724,7 +725,7 @@ bool fgCurrentElev( sgdVec3 abs_view_pos, double max_alt_m, sgdSetMat4(xform,fxform); hit_list->Intersect( terra_transform, xform, orig, dir ); - int this_hit = -1; + this_hit = -1; int max_hit = -1; double hit_elev = -9999; double max_elev = -9999; diff --git a/src/Scenery/hitlist.hxx b/src/Scenery/hitlist.hxx index e1faaac3d..0bb99c074 100644 --- a/src/Scenery/hitlist.hxx +++ b/src/Scenery/hitlist.hxx @@ -93,7 +93,8 @@ bool fgCurrentElev( sgdVec3 abs_view_pos, FGHitList *hit_list, double *terrain_elev, double *radius, - double *normal ); + double *normal, + int & this_hit ); bool fgCurrentElev( sgdVec3 abs_view_pos, double max_alt_m, diff --git a/src/Scenery/scenery.cxx b/src/Scenery/scenery.cxx index 4c82beae2..0bbe2163e 100644 --- a/src/Scenery/scenery.cxx +++ b/src/Scenery/scenery.cxx @@ -32,6 +32,7 @@ #include #include #include +#include #include
@@ -143,6 +144,17 @@ FGScenery::get_elevation_m(double lat, double lon, double max_alt, return get_cart_elevation_m(pos, 0, alt, exact); } +bool +FGScenery::get_material_m(double lat, double lon, double max_alt, + double& alt, string & material, bool exact) +{ + sgdVec3 pos; + sgGeodToCart(lat*SG_DEGREES_TO_RADIANS, lon*SG_DEGREES_TO_RADIANS, + max_alt, pos); + + return get_cart_material_m(pos, 0, alt, material, exact); +} + bool FGScenery::get_cart_elevation_m(const sgdVec3& pos, double max_altoff, double& alt, bool exact) @@ -159,6 +171,52 @@ FGScenery::get_cart_elevation_m(const sgdVec3& pos, double max_altoff, // overridden with actual values if a terrain intersection is // found + int this_hit; + double hit_radius = 0.0; + sgdVec3 hit_normal = { 0.0, 0.0, 0.0 }; + + bool hit = false; + if ( fabs(pos[0]) > 1.0 || fabs(pos[1]) > 1.0 || fabs(pos[2]) > 1.0 ) { + sgdVec3 sc; + sgdSetVec3(sc, center[0], center[1], center[2]); + + sgdVec3 ncpos; + sgdCopyVec3(ncpos, pos); + + FGHitList hit_list; + + // scenery center has been properly defined so any hit should + // be valid (and not just luck) + hit = fgCurrentElev(ncpos, max_altoff+sgdLengthVec3(pos), + sc, (ssgTransform*)get_scene_graph(), + &hit_list, &alt, &hit_radius, hit_normal, this_hit); + } + + if (replaced_center) + set_center( saved_center ); + + return hit; +} + +bool +FGScenery::get_cart_material_m(const sgdVec3& pos, double max_altoff, + double& alt, string& material, bool exact) +{ + Point3D saved_center = center; + bool replaced_center = false; + if (exact) { + Point3D ppos(pos[0], pos[1], pos[2]); + if (30.0*30.0 < ppos.distance3Dsquared(center)) { + set_center( ppos ); + replaced_center = true; + } + } + + material = ""; + + // overridden with actual values if a terrain intersection is + // found + int this_hit; double hit_radius = 0.0; sgdVec3 hit_normal = { 0.0, 0.0, 0.0 }; @@ -176,7 +234,33 @@ FGScenery::get_cart_elevation_m(const sgdVec3& pos, double max_altoff, // be valid (and not just luck) hit = fgCurrentElev(ncpos, max_altoff+sgdLengthVec3(pos), sc, (ssgTransform*)get_scene_graph(), - &hit_list, &alt, &hit_radius, hit_normal); + &hit_list, &alt, &hit_radius, hit_normal, + this_hit ); + + if( hit ) + { + ssgEntity *entity = hit_list.get_entity( this_hit ); + + if( entity != NULL && entity->isAKindOf(ssgTypeLeaf()) ) + { + ssgLeaf *leaf = (ssgLeaf*) hit_list.get_entity( this_hit ); + ssgState *st = leaf->getState(); + + if( st != NULL && st->isAKindOf(ssgTypeSimpleState()) ) + { + ssgSimpleState *ss = (ssgSimpleState *) st; + + if( !globals->get_matlib()->find( ss, material ) ) + { + material = "not-in-matlib"; + } + } + } + } + else + { + material = "no-hit"; + } } if (replaced_center) diff --git a/src/Scenery/scenery.hxx b/src/Scenery/scenery.hxx index b24f63a35..58690188f 100644 --- a/src/Scenery/scenery.hxx +++ b/src/Scenery/scenery.hxx @@ -94,6 +94,8 @@ public: /// All values are meant to be in meters or degrees. bool get_elevation_m(double lat, double lon, double max_alt, double& alt, bool exact = false); + bool get_material_m(double lat, double lon, double max_alt, + double& alt, string & material, bool exact = false); /// Compute the elevation of the scenery beow the cartesian point pos. /// you the returned scenery altitude is not higher than the position @@ -108,6 +110,8 @@ public: /// All values are meant to be in meters. bool get_cart_elevation_m(const sgdVec3& pos, double max_altoff, double& radius, bool exact = false); + bool get_cart_material_m(const sgdVec3& pos, double max_altoff, + double& radius, string& material, bool exact = false); /// Compute the nearest intersection point of the line starting from /// start going in direction dir with the terrain.