Changeset 104


Ignore:
Timestamp:
Jun 10, 2005, 5:24:31 PM (20 years ago)
Author:
darran
Message:
  • towards steep culling based on alpha transparency.
Location:
Swollen
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • Swollen/doc/contract2_hours.txt

    r103 r104  
    33------------------
    44
     5total = 163 hours (4.3 weeks)
     6subtotal = 9 hours
     7
     810 June, Friday (4 hours)
     9- sww file "texture" attribute image now found in same location as .sww
     10- steep culling reintroduced
     11- built and released distro20050610 for windows
    512
    6138 June, Wednesday (3 hours)
  • Swollen/swollen/bedslope.cpp

    r95 r104  
    7777
    7878}
    79 
    80 
    81 void BedSlope::toggleTexture()
    82 {
    83 
    84         // FIXME: stateset no longer defined for non-textured bedslope
    85     if ( _texture )
    86     {
    87         _stateset->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::OFF );
    88         _texture = false;
    89     }
    90     else
    91     {
    92         _stateset->setTextureMode( 0, GL_TEXTURE_2D, osg::StateAttribute::ON );
    93         _texture = true;
    94     }
    95 
    96 }
  • Swollen/swollen/bedslope.h

    r72 r104  
    2929    virtual osg::Geode* get(){ return _node; }
    3030    virtual osg::BoundingBox getBound(){ return _geom->getBound(); }
    31     virtual void toggleTexture();
    3231
    3332
  • Swollen/swollen/keyboardeventhandler.cpp

    r92 r104  
    1414    _prevtime = 0;
    1515    _togglewireframe = false;
     16    _toggleculling = false;
    1617}
    1718
     
    7677                break;
    7778
     79            case 'c':
     80                _toggleculling = true;
     81                handled = true;
     82                break;
     83
     84
    7885            }
    7986
     
    120127
    121128
     129bool KeyboardEventHandler::toggleCulling()
     130{
     131    if( _toggleculling )
     132    {
     133        _toggleculling = false;
     134        return true;
     135    }
     136    return false;
     137}
     138
     139
  • Swollen/swollen/keyboardeventhandler.h

    r92 r104  
    2323    virtual bool timestepChanged();
    2424    virtual bool toggleWireframe();
     25    virtual bool toggleCulling();
    2526    virtual int getTimestep(){return (unsigned int) _timestep;}
    2627    virtual void setTime(float time);
     
    2930    int _direction, _timestep, _ntimesteps;
    3031    float _tps, _prevtime, _tpsorig;
    31     bool _paused, _timestepchanged, _togglewireframe;
     32    bool _paused, _timestepchanged, _togglewireframe, _toggleculling;
    3233};
    3334
  • Swollen/swollen/main.cpp

    r103 r104  
    131131    // Lighting
    132132    DirectionalLight* light = new DirectionalLight(rootStateSet);
    133     light->setPosition( osg::Vec3(0,0,2) );  // z is up
     133    light->setPosition( osg::Vec3(1,1,1) );  // z is up
    134134
    135135    std::string lightposstr;
     
    218218            water->toggleWireframe();
    219219
     220        if( event_handler->toggleCulling() )
     221            std::cout << "toggle culling" << std::endl;
     222
     223
    220224        // update the scene by traversing with the update visitor
    221225        viewer.update();
  • Swollen/swollen/watersurface.cpp

    r73 r104  
    6767
    6868    osg::TexEnv* texenv = new osg::TexEnv;
    69     texenv->setMode( osg::TexEnv::DECAL );
     69    //texenv->setMode( osg::TexEnv::DECAL );
     70    texenv->setMode( osg::TexEnv::BLEND );
    7071    texenv->setColor( osg::Vec4(0.6f,0.6f,0.6f,0.2f) );
    7172    _stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );
  • Swollen/swwreader/swwreader.cpp

    r103 r104  
    88
    99#include <SWWReader.h>
     10#include <cstdlib>
    1011#include <string>
    1112#include <fstream>
     
    1516#include <osgDB/Registry>
    1617#include <osgDB/ReadFile>
     18#include <osgDB/FileNameUtils>
    1719
    1820#include <stdlib.h>
     
    7880    if( nc_inq_attlen(_ncid, NC_GLOBAL, "texture", &attlen) != NC_ENOTATT )
    7981    {
    80        char* filename;
    81        if( (filename = (char*) malloc(attlen+1)) != NULL){
    82           int status;
    83           status = nc_get_att_text(_ncid, NC_GLOBAL, "texture", filename);
    84           if( status == NC_NOERR )
    85           {
    86              filename[attlen] = '\0';  // ensure string is terminated, not a requirement for netcdf attributes
    87              osg::notify(osg::INFO) << "[SWWReader] embedded image filename: " << filename <<  std::endl;
    88              setBedslopeTexture( std::string(filename) );
    89           }
    90           free( filename );
    91        }
     82        char* texfilename;
     83        if( (texfilename = (char*) malloc(attlen+1)) != NULL){
     84                int status;
     85                status = nc_get_att_text(_ncid, NC_GLOBAL, "texture", texfilename);
     86                if( status == NC_NOERR )
     87                {
     88                    texfilename[attlen] = '\0';  // ensure string is terminated, not a requirement for netcdf attributes
     89                    osg::notify(osg::INFO) << "[SWWReader] embedded image filename: " << texfilename <<  std::endl;
     90                setBedslopeTexture( osgDB::getFilePath(filename) + std::string("/") + std::string(texfilename) );
     91                }
     92            free( texfilename );
     93        }
    9294    }
    9395
     
    163165    }
    164166
    165 
    166167    osg::notify(osg::INFO) << "[SWWReader] xscale: " << _xscale <<  std::endl;
    167168    osg::notify(osg::INFO) << "[SWWReader] yscale: " << _yscale <<  std::endl;
     
    169170    osg::notify(osg::INFO) << "[SWWReader] zmax: " << zmax <<  std::endl;
    170171    osg::notify(osg::INFO) << "[SWWReader] zscale: " << _zscale <<  std::endl;
    171 
    172 
    173 
    174     // alpha-scaling defaults
    175     _alphamin = 0.8;       
    176     _alphamax = 1.0;
    177     _heightmin = 0.0;
    178     _heightmax = 1.0;   
    179172
    180173
     
    198191        _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_scale - _xcenter,
    199192                                                 (_py[iv]-_yoffset)*_scale - _ycenter,
    200                                                  (_pz[iv]-_zoffset)*_scale - _zcenter) );
     193                                                 (_pz[iv]-_zoffset)*_scale - _zcenter - 0.00) );
    201194
    202195    // bedslope index array, pvolumes array indexes into x, y and z
     
    334327    count[1] = _npoints;
    335328
     329    // empty array for storing list of steep triangles
     330    osg::ref_ptr<osg::IntArray> steeptri = new osg::IntArray;
     331
     332    // alpha-scaling defaults
     333    _alphamin = 0.8;
     334    _alphamax = 1.0;
     335    _heightmin = 0.00;
     336    _heightmax = 1.0;
     337
    336338    // stage heights from netcdf file (x and y are same as bedslope)
    337339    int status = nc_get_vars_float (_ncid, _stageid, start, count, stride, _pstage);
     
    375377        _stagecentroids->push_back( (v1s+v2s+v3s)/3.0 );
    376378        _stageprimitivenormals->push_back( nrm );
    377     }
    378 
     379
     380        // identify steep triangles
     381        if( fabs(nrm * osg::Vec3f(0,0,1)) < 0.4 )
     382        {
     383            steeptri->push_back( iv );
     384        }
     385    }
     386
     387
     388    int seed = 5;
     389    srand(seed);
     390    float r, g, b;
    379391
    380392    // stage height above bedslope mapped as alpha value
     
    387399    for (iv=0; iv < _npoints; iv++)
    388400    {
    389         height = _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z();
     401        height = _stagevertices->at(iv).z() - _bedslopevertices->at(iv).z();
    390402       
    391         if (height < _heightmin)
    392         {
    393             alpha = 0.0;
    394         }
    395         else
    396         {
    397             alpha = alphascale * (height - _heightmin) + _alphamin;
    398             if( alpha > _alphamax )
    399                 alpha = _alphamax;       
    400         }
    401         _stagecolors->push_back( osg::Vec4( 1.0, 1.0, 1.0, alpha ) );
    402     }
     403        if (height < _heightmin)
     404        {
     405            alpha = 0.0;
     406        }
     407        else
     408        {
     409                alpha = alphascale * (height - _heightmin) + _alphamin;
     410                if( alpha > _alphamax )
     411                    alpha = _alphamax;   
     412        }
     413
     414        r = ((float) rand())/RAND_MAX;
     415        g = ((float) rand())/RAND_MAX;
     416        b = ((float) rand())/RAND_MAX;
     417        //alpha = ((float) rand())/RAND_MAX;
     418        alpha = 0.9;
     419        _stagecolors->push_back( osg::Vec4( r, g, b, alpha ) );
     420    }
     421
     422    for (iv=0; iv < steeptri->size() ; iv++)
     423    {
     424        int tri = steeptri->at(iv);
     425        v1index = _pvolumes[3*tri+0];
     426        v2index = _pvolumes[3*tri+1];
     427        v3index = _pvolumes[3*tri+2];
     428
     429        r = ((float) rand())/RAND_MAX;
     430        g = ((float) rand())/RAND_MAX;
     431        b = ((float) rand())/RAND_MAX;
     432
     433        std::cout << tri << std::endl;
     434
     435        // FIXME: needs to be an overwrite rather than a push
     436        //_stagecolors->push_back( osg::Vec4( 1, 1, 1, alpha ) );
     437    }
     438
    403439
    404440
Note: See TracChangeset for help on using the changeset viewer.