Changeset 13
- Timestamp:
- Nov 2, 2004, 11:20:45 PM (20 years ago)
- Location:
- Swollen
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
Swollen/include/swwreader.h
r6 r13 83 83 84 84 // stage culling 85 virtual void toggleCullNearZero() {_cullnearzero = _cullnearzero ? false : true;} 86 virtual bool getCullNearZero() {return _cullnearzero;} 87 virtual float getCullNearZeroValue() {return _cullnearzerovalue;} 88 virtual void toggleCullSteepAngle() {_cullsteepangle = _cullsteepangle ? false : true;} 89 virtual bool getCullSteepAngle() {return _cullsteepangle;} 90 virtual float getCullSteepAngleValue() {return _cullsteepanglevalue;} 85 virtual void toggleCullSetting(); 86 virtual float getCullNearZero() {return _cullnearzero;} 87 virtual float getCullSteepAngle() {return _cullsteepangle;} 88 virtual void setCullNearZero( float value ) {_cullnearzero = value; } 89 virtual void setCullSteepAngle( float value ) {_cullsteepangle = value; } 91 90 92 91 virtual triangle_list getConnectivity(unsigned int index) {return _connectivity.at(index);} … … 131 130 osg::ref_ptr<osg::Vec3Array> _stagecentroids; 132 131 132 // bedslope vertex scale and shift factors (for normalizing to unit cube) 133 float _xscale, _yscale, _zscale; 134 float _xoffset, _yoffset, _zoffset; 133 135 134 136 // stack of return values from netcdf function calls … … 143 145 144 146 // stage culling 145 bool_cullnearzero;146 float _cull nearzerovalue;147 bool _cullsteepangle;148 float _cullsteepanglevalue;147 float _cullnearzero; 148 float _cullsteepangle; 149 enum cullstate { CULLALL, CULLNEARZERO, CULLSTEEPANGLE, CULLNONE }; 150 cullstate _cullsetting; 149 151 150 152 }; -
Swollen/swollen/keyboardeventhandler.cpp
r9 r13 14 14 _prevtime = 0; 15 15 _togglewireframe = false; 16 _togglecull nearzero= false;16 _togglecullsetting = false; 17 17 } 18 18 … … 73 73 74 74 case 'w': 75 76 77 75 _togglewireframe = true; 76 handled = true; 77 break; 78 78 79 80 _togglecullnearzero= true;81 82 79 case 'c': 80 _togglecullsetting = true; 81 handled = true; 82 break; 83 83 } 84 84 … … 125 125 126 126 127 bool KeyboardEventHandler::toggleCull NearZero()127 bool KeyboardEventHandler::toggleCullSetting() 128 128 { 129 if( _togglecull nearzero)129 if( _togglecullsetting ) 130 130 { 131 _togglecull nearzero= false;131 _togglecullsetting = false; 132 132 return true; 133 133 } -
Swollen/swollen/keyboardeventhandler.h
r9 r13 23 23 virtual bool timestepChanged(); 24 24 virtual bool toggleWireframe(); 25 virtual bool toggleCull NearZero();25 virtual bool toggleCullSetting(); 26 26 virtual int getTimestep(){return (unsigned int) _timestep;} 27 27 virtual void setTime(float time); … … 30 30 int _direction, _timestep, _ntimesteps; 31 31 float _tps, _prevtime, _tpsorig; 32 bool _paused, _timestepchanged, _togglewireframe, _togglecull nearzero;32 bool _paused, _timestepchanged, _togglewireframe, _togglecullsetting; 33 33 }; 34 34 -
Swollen/swollen/main.cpp
r12 r13 114 114 115 115 116 // center model in x and y 116 // center model in x and y (now done in swwreader) 117 /* 117 118 osg::BoundingBox bbox = bedslope->getBound(); 118 119 float scale = 1.0/bbox.radius(); 119 model->setScale( osg::Vec3(scale,scale,scale) );120 120 model->setPosition( -bbox.center()*scale ); 121 121 */ 122 123 // FIXME: should be reasonable default and adjustable 124 model->setScale( osg::Vec3(1.0, 1.0, 0.2) ); 122 125 123 126 // sky … … 156 159 157 160 161 unsigned int timestep = 0; 158 162 while( !viewer.done() ) 159 163 { … … 163 167 // current time 164 168 double time = viewer.getFrameStamp()->getReferenceTime(); 165 166 // events167 if( event_handler->toggleWireframe() )168 water->toggleWireframe();169 if( event_handler->toggleCullNearZero() )170 sww->toggleCullNearZero();171 169 172 170 // advance sww frame? … … 174 172 if( event_handler->timestepChanged() ) 175 173 { 176 unsigned inttimestep = event_handler->getTimestep();174 timestep = event_handler->getTimestep(); 177 175 water->setTimeStep(timestep); 178 176 hud->setTime( sww->getTime(timestep) ); 179 177 } 178 179 // events 180 if( event_handler->toggleWireframe() ) 181 water->toggleWireframe(); 182 if( event_handler->toggleCullSetting() ) 183 { 184 sww->toggleCullSetting(); 185 water->setTimeStep(timestep); // forced reload 186 } 187 180 188 181 189 // update the scene by traversing with the update visitor -
Swollen/swollen/watersurface.cpp
r11 r13 19 19 20 20 21 #define DEF_WATER_COLOUR 0, 0, 0.5, 1 22 #define DEF_WATER_TRANSPARENCY 0.1 23 21 #define DEF_WATER_COLOUR 0, 0, 0.5, 1 // R, G, B, Alpha (blue) 22 #define DEF_WATER_TRANSPARENCY 0.1 // 0=opaque, 1=transparent 23 #define DEF_ZOFFSET 0.01 24 24 25 25 // constructor … … 32 32 _stateset = new osg::StateSet; 33 33 _material = new osg::Material; 34 _zoffset = DEF_ZOFFSET; 34 35 35 36 // construct local scenegraph hierarchy … … 98 99 99 100 100 // vertical (z) offset to eliminate zbuffer problems101 // vertical (z) offset to eliminate potential zbuffer problems with bedslope 101 102 for( unsigned int iv=0; iv < vertices.get()->size(); iv++ ) 102 vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, 0.0);103 vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, _zoffset ); 103 104 104 105 _geom->setVertexArray( vertices.get() ); -
Swollen/swollen/watersurface.h
r6 r13 29 29 virtual void setTimeStep( unsigned int ts ); 30 30 virtual void toggleWireframe(); 31 virtual void setOffset( float amount ){ _zoffset = amount; } 32 virtual float getOffset(){ return _zoffset; } 31 33 32 34 protected: … … 38 40 osg::Material* _material; 39 41 virtual ~WaterSurface(); 42 float _zoffset; 40 43 41 44 }; -
Swollen/swwreader/swwreader.cpp
r8 r13 35 35 #include <stdio.h> 36 36 37 #define DEF_CULLNEARZERO 0.001 38 #define DEF_CULLSTEEPANGLE 0.9 39 #define DEF_CULLSTART CULLNONE 40 41 37 42 // only constructor, requires netcdf file 38 43 SWWReader::SWWReader(const std::string& filename) … … 61 66 _status.push_back( nc_inq_dimlen(_ncid, _ntimestepsid, &_ntimesteps) ); 62 67 if (this->_statusHasError()) return; 63 64 // debug info65 osg::notify(osg::INFO) << "[SWWReader]" << std::endl;66 osg::notify(osg::INFO) << " nvolumes: " << _nvolumes << std::endl;67 osg::notify(osg::INFO) << " nvertices: " << _nvertices << std::endl;68 osg::notify(osg::INFO) << " npoints: " << _npoints << std::endl;69 osg::notify(osg::INFO) << " ntimesteps: " << _ntimesteps << std::endl;70 71 68 72 69 // variable ids … … 101 98 unsigned int v1index, v2index, v3index; 102 99 100 // bedslope extents and resultant scale factors 101 float xmin, xmax, xrange; 102 float ymin, ymax, yrange; 103 float zmin, zmax, zrange; 104 xmin = _px[0]; 105 xmax = _px[0]; 106 ymin = _py[0]; 107 ymax = _py[0]; 108 zmin = _pz[0]; 109 zmax = _pz[0]; 110 for( iv=1; iv < _npoints; iv++ ) 111 { 112 if( _px[iv] < xmin ) xmin = _px[iv]; 113 if( _px[iv] > xmax ) xmax = _px[iv]; 114 if( _py[iv] < ymin ) ymin = _py[iv]; 115 if( _py[iv] > ymax ) ymax = _py[iv]; 116 if( _pz[iv] < zmin ) zmin = _pz[iv]; 117 if( _pz[iv] > zmax ) zmax = _pz[iv]; 118 } 119 _xscale = 1.0/(xmax - xmin); _xoffset = xmin; 120 _yscale = 1.0/(ymax - ymin); _yoffset = ymin; 121 _zscale = (zmax==zmin) ? 1.0 : 1.0/(zmax - zmin); _zoffset = zmin; 122 std::cout << "xmin: " << xmin << std::endl; 123 std::cout << "xmax: " << xmax << std::endl; 124 std::cout << "ymin: " << ymin << std::endl; 125 std::cout << "ymax: " << ymax << std::endl; 126 std::cout << "zmin: " << zmin << std::endl; 127 std::cout << "zmax: " << zmax << std::endl; 128 std::cout << "xscale: " << _xscale << std::endl; 129 std::cout << "yscale: " << _yscale << std::endl; 130 std::cout << "zscale: " << _zscale << std::endl; 131 132 103 133 // culling defaults 104 _cullnearzero = true; 105 _cullnearzerovalue = 0.001; 106 _cullsteepangle = true; 107 _cullsteepanglevalue = 0.9; 134 _cullsetting = DEF_CULLSTART; 135 _cullnearzero = DEF_CULLNEARZERO; 136 _cullsteepangle = DEF_CULLSTEEPANGLE; 108 137 109 138 // compute triangle connectivity, a list (indexed by vertex number) … … 120 149 } 121 150 122 // load bedslope vertex array 151 // load bedslope vertex array, shifting and scaling vertices to unit cube 152 // centred about the origin 123 153 _bedslopevertices = new osg::Vec3Array; 124 154 for (iv=0; iv < _npoints; iv++) 125 _bedslopevertices->push_back( osg::Vec3(_px[iv], _py[iv], _pz[iv]) ); 155 _bedslopevertices->push_back( osg::Vec3( (_px[iv]-_xoffset)*_xscale - 0.5, 156 (_py[iv]-_yoffset)*_yscale - 0.5, 157 (_pz[iv]-_zoffset)*_zscale - 0.5) ); 126 158 127 159 // load bedslope index array, pvolumes array indexes into x, y and z … … 180 212 int status = nc_get_vars_float (_ncid, _stageid, start, count, stride, _pstage); 181 213 182 // load stage vertex array 214 // load stage vertex array, scaling and shifting vertices to lie in the unit cube 183 215 _stagevertices = new osg::Vec3Array; 184 216 for (iv=0; iv < _npoints; iv++) 185 _stagevertices->push_back( osg::Vec3(_px[iv], _py[iv], _pstage[iv]) ); 217 _stagevertices->push_back( osg::Vec3( 218 (_px[iv]-_xoffset)*_xscale - 0.5, 219 (_py[iv]-_yoffset)*_yscale - 0.5, 220 (_pstage[iv]-_zoffset)*_zscale - 0.5) ); 186 221 187 222 // stage index and per primitive normal and centroid arrays … … 212 247 213 248 // shallow water depth culling test 214 if( _cullnearzero && ((v1s.z()+v2s.z()+v3s.z())/3.0 - _bedslopecentroids->at(iv).z()) < _cullnearzerovalue ) 249 if( (_cullsetting == CULLALL || _cullsetting == CULLNEARZERO) && 250 ((v1s.z()+v2s.z()+v3s.z())/3.0 - _bedslopecentroids->at(iv).z()) < _cullnearzero ) 215 251 { 216 252 culledlist->push_back( iv ); … … 219 255 220 256 // steep bedslope culling test 221 if( _culls teepangle )222 { 223 if( _bedslopenormals->at(iv) * osg::Vec3f(0,0,1) < _cullsteepangle value)257 if( _cullsetting == CULLALL || _cullsetting == CULLSTEEPANGLE ) 258 { 259 if( _bedslopenormals->at(iv) * osg::Vec3f(0,0,1) < _cullsteepangle ) 224 260 { 225 261 culledlist->push_back( iv ); … … 283 319 284 320 321 322 void SWWReader::toggleCullSetting() 323 { 324 325 switch( _cullsetting ) 326 { 327 328 case CULLALL: 329 _cullsetting = CULLNEARZERO; 330 osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLNEARZERO" << std::endl; 331 break; 332 333 case CULLNEARZERO: 334 _cullsetting = CULLSTEEPANGLE; 335 osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLSTEEPANGLE" << std::endl; 336 break; 337 338 case CULLSTEEPANGLE: 339 _cullsetting = CULLNONE; 340 osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLNONE" << std::endl; 341 break; 342 343 case CULLNONE: 344 _cullsetting = CULLALL; 345 osg::notify(osg::INFO) << "[SWWReader::toggleCullSetting] CULLALL" << std::endl; 346 break; 347 348 } 349 } 350 351 352 285 353 bool SWWReader::_statusHasError() 286 354 {
Note: See TracChangeset
for help on using the changeset viewer.