From: ehofman Date: Sun, 31 Jul 2005 08:56:27 +0000 (+0000) Subject: Harald JOHNSEN: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4ca25ca5339799f213c20bc0840e96de9d772769;p=simgear.git Harald JOHNSEN: added a cull test on fields --- diff --git a/simgear/scene/sky/cloudfield.cxx b/simgear/scene/sky/cloudfield.cxx index 37ff8910..d9608de6 100644 --- a/simgear/scene/sky/cloudfield.cxx +++ b/simgear/scene/sky/cloudfield.cxx @@ -249,17 +249,26 @@ static int densTable[][10] = { void SGCloudField::applyDensity(void) { int row = (int) (density / 10.0); int col = 0; + sgBox fieldBox; + list_of_Cloud::iterator iCloud; for( iCloud = theField.begin() ; iCloud != theField.end() ; iCloud++ ) { if(++col > 9) col = 0; if( densTable[row][col] ) { iCloud->visible = true; + fieldBox.extend( *iCloud->aCloud->getCenter() ); } else iCloud->visible = false; } last_density = density; draw_in_3d = ( theField.size() != 0); + sgVec3 center; + sgSubVec3( center, fieldBox.getMax(), fieldBox.getMin() ); + sgScaleVec3( center, 0.5f ); + center[1] = 0.0f; + field_sphere.setCenter( center ); + field_sphere.setRadius( fieldSize * 0.5f * 1.414f ); } // add one cloud, data is not copied, ownership given @@ -298,7 +307,15 @@ void SGCloudField::buildTestLayer(void) { void SGCloudField::cullClouds(sgVec3 eyePos, sgMat4 mat) { list_of_Cloud::iterator iCloud; - // TODO:cull the field before culling the clouds in the field (should eliminate 3 fields) + sgSphere tile_sphere; + tile_sphere.setRadius( field_sphere.getRadius() ); + sgVec3 tile_center; + sgSubVec3( tile_center, field_sphere.getCenter(), eyePos ); + tile_sphere.setCenter( tile_center ); + tile_sphere.orthoXform(mat); + if( frustum.contains( & tile_sphere ) == SG_OUTSIDE ) + return; + for( iCloud = theField.begin() ; iCloud != theField.end() ; iCloud++ ) { sgVec3 dist; sgSphere sphere; diff --git a/simgear/scene/sky/cloudfield.hxx b/simgear/scene/sky/cloudfield.hxx index 703b17a1..cb9968dd 100644 --- a/simgear/scene/sky/cloudfield.hxx +++ b/simgear/scene/sky/cloudfield.hxx @@ -76,7 +76,7 @@ private: sgMat4 transform; double deltax, deltay, alt; double last_lon, last_lat, last_course; - + sgSphere field_sphere; float last_density; bool draw_in_3d;