From a3f7547cf76540193b90b916f64a51040c5d0287 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 7 Jul 2004 09:04:21 +0000 Subject: [PATCH] Added support for automatically computing the local skirt orientation --- src/osgTerrain/DataSet.cpp | 52 ++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/src/osgTerrain/DataSet.cpp b/src/osgTerrain/DataSet.cpp index 2ce28d3da..dda7c530e 100644 --- a/src/osgTerrain/DataSet.cpp +++ b/src/osgTerrain/DataSet.cpp @@ -1993,6 +1993,23 @@ static osg::Vec3 computeLocalPosition(const osg::Matrixd& worldToLocal, double X X*worldToLocal(0,2) + Y*worldToLocal(1,2) + Z*worldToLocal(2,2) + worldToLocal(3,2)); } +static inline osg::Vec3 computeLocalSkirtVector(const osg::EllipsoidModel* et, const osg::HeightField* grid, unsigned int i, unsigned int j, float length, bool useLocalToTileTransform, const osg::Matrixd& localToWorld) +{ + // no local to tile transform + mapping from lat+longs to XYZ so we need to use + // a rotatated skirt vector - use the gravity vector. + double longitude = grid->getOrigin().x()+grid->getXInterval()*((double)(i)); + double latitude = grid->getOrigin().y()+grid->getYInterval()*((double)(j)); + double midZ = grid->getOrigin().z(); + double X,Y,Z; + et->convertLatLongHeightToXYZ(osg::DegreesToRadians(latitude),osg::DegreesToRadians(longitude),midZ,X,Y,Z); + osg::Vec3 gravitationVector = et->computeLocalUpVector(X,Y,Z); + gravitationVector.normalize(); + + if (useLocalToTileTransform) gravitationVector = osg::Matrixd::transform3x3(localToWorld,gravitationVector); + + return gravitationVector * -length; +} + osg::Node* DataSet::DestinationTile::createPolygonal() { std::cout<<"--------- DataSet::DestinationTile::createDrawableGeometry() ------------- "<getRadiusPolar() : 1.0; + float skirtLength = _extents.radius()*skirtRatio; bool useClusterCullingCallback = mapLatLongsToXYZ; @@ -2099,7 +2117,8 @@ osg::Node* DataSet::DestinationTile::createPolygonal() double length = sqrt((midX-minX)*(midX-minX) + (midY-minY)*(midY-minY)); - skirtVector.set(0.0f,0.0f,-length*skirtRatio); + skirtLength = length*skirtRatio; + skirtVector.set(0.0f,0.0f,-skirtLength); center_normal.set(midX,midY,midZ); center_normal.normalize(); @@ -2118,7 +2137,7 @@ osg::Node* DataSet::DestinationTile::createPolygonal() localToWorld.makeTranslate(midX,midY,midZ); worldToLocal.invert(localToWorld); - skirtVector.set(0.0f,0.0f,-_extents.radius()*skirtRatio); + skirtVector.set(0.0f,0.0f,-skirtLength); } } @@ -2133,14 +2152,15 @@ osg::Node* DataSet::DestinationTile::createPolygonal() et->convertLatLongHeightToXYZ(osg::DegreesToRadians(midLat),osg::DegreesToRadians(midLong),midZ,X,Y,Z); osg::Vec3 gravitationVector = et->computeLocalUpVector(X,Y,Z); gravitationVector.normalize(); - skirtVector = gravitationVector * _extents.radius()* skirtRatio; + skirtVector = gravitationVector * skirtLength; } else { - skirtVector.set(0.0f,0.0f,-_extents.radius()*skirtRatio); + skirtVector.set(0.0f,0.0f,-skirtLength); } + unsigned int vi=0; unsigned int r,c; @@ -2309,9 +2329,13 @@ osg::Node* DataSet::DestinationTile::createPolygonal() // mark these points as protected to prevent them from being removed during simplification pointsToProtectDuringSimplification.push_back((r)*numColumns+c); pointsToProtectDuringSimplification.push_back(vi); + + osg::Vec3 localSkirtVector = !mapLatLongsToXYZ ? + skirtVector : + computeLocalSkirtVector(et, grid.get(), c, r, skirtLength, useLocalToTileTransform, localToWorld); // add in the new point on the bottom of the skirt - v[vi] = v[(r)*numColumns+c]+skirtVector; + v[vi] = v[(r)*numColumns+c]+localSkirtVector; if (n.valid()) (*n)[vi] = (*n)[r*numColumns+c]; t[vi++] = t[(r)*numColumns+c]; } @@ -2327,8 +2351,12 @@ osg::Node* DataSet::DestinationTile::createPolygonal() pointsToProtectDuringSimplification.push_back((r)*numColumns+c); pointsToProtectDuringSimplification.push_back(vi); + osg::Vec3 localSkirtVector = !mapLatLongsToXYZ ? + skirtVector : + computeLocalSkirtVector(et, grid.get(), c, r, skirtLength, useLocalToTileTransform, localToWorld); + // add in the new point on the bottom of the skirt - v[vi] = v[(r)*numColumns+c]+skirtVector; + v[vi] = v[(r)*numColumns+c]+localSkirtVector; if (n.valid()) (*n)[vi] = (*n)[(r)*numColumns+c]; t[vi++] = t[(r)*numColumns+c]; } @@ -2344,8 +2372,12 @@ osg::Node* DataSet::DestinationTile::createPolygonal() pointsToProtectDuringSimplification.push_back((r)*numColumns+c); pointsToProtectDuringSimplification.push_back(vi); + osg::Vec3 localSkirtVector = !mapLatLongsToXYZ ? + skirtVector : + computeLocalSkirtVector(et, grid.get(), c, r, skirtLength, useLocalToTileTransform, localToWorld); + // add in the new point on the bottom of the skirt - v[vi] = v[(r)*numColumns+c]+skirtVector; + v[vi] = v[(r)*numColumns+c]+localSkirtVector; if (n.valid()) (*n)[vi] = (*n)[(r)*numColumns+c]; t[vi++] = t[(r)*numColumns+c]; } @@ -2361,8 +2393,12 @@ osg::Node* DataSet::DestinationTile::createPolygonal() pointsToProtectDuringSimplification.push_back((r)*numColumns+c); pointsToProtectDuringSimplification.push_back(vi); + osg::Vec3 localSkirtVector = !mapLatLongsToXYZ ? + skirtVector : + computeLocalSkirtVector(et, grid.get(), c, r, skirtLength, useLocalToTileTransform, localToWorld); + // add in the new point on the bottom of the skirt - v[vi] = v[(r)*numColumns+c]+skirtVector; + v[vi] = v[(r)*numColumns+c]+localSkirtVector; if (n.valid()) (*n)[vi] = (*n)[(r)*numColumns+c]; t[vi++] = t[(r)*numColumns+c]; }