Ignore:
Timestamp:
Feb 27, 2011, 8:11:34 PM (13 years ago)
Author:
Torben Dannhauer
Message:

Prototype of rampedEllipsoidFunction works.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • experimental/TerrainTest/rampedEllipsoidTechnique.cpp

    r264 r265  
    66{
    77        _height = 0.0;
    8         _rampWidth_percent = 10.0;
     8        _rampWidthFactor = 0.1; // 10% of ROI is ramp.
    99}
    1010
     
    1515void rampedEllipsoidTechnique::modifyHeightfield(osg::Vec4d& modificationROI, osg::HeightField* h, osg::Vec4d tileExtends)
    1616{
    17         //OSG_NOTIFY( osg::ALWAYS ) << "ellipsoidTechnique::modifyHeightfield()" << std::endl;
     17        //OSG_NOTIFY( osg::ALWAYS ) << "rampedEllipsoidTechnique::modifyHeightfield()" << std::endl;
    1818        //OSG_NOTIFY( osg::ALWAYS ) << "LAT: " << tileExtends[0] << " | " << tileExtends[1] << std::endl;
    1919        //OSG_NOTIFY( osg::ALWAYS ) << "LON: " << tileExtends[2] << " | " << tileExtends[3] << std::endl;
    2020
    21         // calculate colum start/end and row start/end of affected vertices
    22         int startX=0, startY=0, endX=h->getNumColumns(), endY=h->getNumRows();
     21        // Determine modificationROI without ramp
     22        double deltaLatPerSide = (modificationROI[1] - modificationROI[0]) * _rampWidthFactor / 2.0;
     23        double deltaLonPerSide = (modificationROI[3] - modificationROI[2]) * _rampWidthFactor / 2.0;
     24        osg::Vec4d coreROI = modificationROI;
     25        coreROI[0]+=deltaLatPerSide;
     26        coreROI[1]-=deltaLatPerSide;
     27        coreROI[2]+=deltaLonPerSide;
     28        coreROI[3]-=deltaLonPerSide;
    2329
    24        
    25         // Dertermine loop variables..
    26         if(tileExtends[0]<modificationROI[0])
    27                 startY = (modificationROI[0] - tileExtends[0]) / h->getYInterval();
    28         if(tileExtends[1]>modificationROI[1])
    29                 endY = (modificationROI[1] - tileExtends[0]) / h->getYInterval();
     30        // Calculate colum start/end and row start/end of affected vertices
     31        int Y_start=0, Y_startRamp=0, Y_startCore=0, Y_endCore=0, Y_endRamp=0, Y_end=h->getNumRows();           // Lat
     32        int X_start=0, X_startRamp=0, X_startCore=0, X_endCore=0, X_endRamp=0, X_end=h->getNumColumns();        // Lon
    3033
    31         if(tileExtends[2]<modificationROI[2])
    32                 startX = (modificationROI[2] - tileExtends[2]) / h->getXInterval();
    33         if(tileExtends[3]>modificationROI[3])
    34                 endX = (modificationROI[3] - tileExtends[2]) / h->getXInterval();
     34        Y_startRamp = (modificationROI[0]-tileExtends[0]) / h->getYInterval();
     35        Y_startCore = (coreROI[0]-tileExtends[0]) / h->getYInterval();
     36        Y_endCore   = (coreROI[1]-tileExtends[0]) / h->getYInterval();
     37        Y_endRamp   = (modificationROI[1]-tileExtends[0]) / h->getYInterval();
     38        clampValue(Y_startRamp, Y_start, Y_end);
     39        clampValue(Y_startCore, Y_start, Y_end);
     40        clampValue(Y_endCore, Y_start, Y_end);
     41        clampValue(Y_endRamp, Y_start, Y_end);
     42
     43        X_startRamp = (modificationROI[2]-tileExtends[2]) / h->getXInterval();
     44        X_startCore = (coreROI[2]-tileExtends[2]) / h->getXInterval();
     45        X_endCore   = (coreROI[3]-tileExtends[2]) / h->getXInterval();
     46        X_endRamp   = (modificationROI[3]-tileExtends[2]) / h->getXInterval();
     47        clampValue(X_startRamp, X_start, X_end);
     48        clampValue(X_startCore, X_start, X_end);
     49        clampValue(X_endCore, X_start, X_end);
     50        clampValue(X_endRamp, X_start, X_end);
     51
     52        // Determine loop variables..
     53        //if(tileExtends[0]<modificationROI[0])
     54        //      startY = (modificationROI[0] - tileExtends[0]) / h->getYInterval();
     55        //if(tileExtends[1]>modificationROI[1])
     56        //      endY = (modificationROI[1] - tileExtends[0]) / h->getYInterval();
     57
     58        //if(tileExtends[2]<modificationROI[2])
     59        //      startX = (modificationROI[2] - tileExtends[2]) / h->getXInterval();
     60        //if(tileExtends[3]>modificationROI[3])
     61        //      endX = (modificationROI[3] - tileExtends[2]) / h->getXInterval();
    3562
    3663
    37         // Modify height value of affected vertices
    38         for(int x=startX;x<endX;x++)
     64        // Modify height value of affected vertices in the core ROI
     65        for(int x=X_startRamp;x<X_endRamp;x++)
    3966        {
    40                 for(int y=startY;y<endY;y++)
     67                for(int y=Y_startRamp;y<Y_endRamp;y++)
    4168                {
    42                         h->setHeight( x, y, _height);
     69                        if( Y_startCore<=y && y<Y_endCore && X_startCore<=x && x<X_endCore )    // If vertex is inside core: Apply final height
     70                        {
     71                                h->setHeight( x, y, _height);
     72                        }
     73                        else    //  vertex is inside ramp but not inside core: apply ramp height
     74                        {
     75                                h->setHeight( x, y, _height-50.0);
     76                        }
     77                       
    4378                }
    4479        }
Note: See TracChangeset for help on using the changeset viewer.