Changeset 44
- Timestamp:
- Dec 10, 2004, 8:13:41 PM (20 years ago)
- Location:
- Swollen
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Swollen/include/swwreader.h
r36 r44 75 75 virtual osg::ref_ptr<osg::Vec3Array> getStagePrimitiveNormalArray() {return _stageprimitivenormals;} 76 76 virtual osg::ref_ptr<osg::Vec3Array> getStageCentroidsArray() {return _stagecentroids;} 77 virtual osg::ref_ptr<osg::Vec4Array> getStageColorArray() {return _stagecolors;} 78 77 79 78 80 virtual float getTime(unsigned int index) {return *(_ptime+index);} … … 129 131 osg::ref_ptr<osg::Vec3Array> _stagevertexnormals; 130 132 osg::ref_ptr<osg::Vec3Array> _stagecentroids; 133 osg::ref_ptr<osg::Vec4Array> _stagecolors; 131 134 132 135 // bedslope vertex scale and shift factors (for normalizing to unit cube) -
Swollen/swollen/bedslope.cpp
r6 r44 25 25 unsigned int nindices = sww->getNumberOfBedslopeIndices(); 26 26 27 _geom->setUseDisplayList( false);27 _geom->setUseDisplayList(true); 28 28 _geom->setVertexArray( vertices ); 29 29 _geom->setVertexIndices( indices ); -
Swollen/swollen/watersurface.cpp
r43 r44 8 8 9 9 #include <watersurface.h> 10 #include <osg/AlphaFunc> 10 11 #include <osg/BlendFunc> 11 12 #include <osg/PolygonMode> … … 18 19 #include <osgDB/ReadFile> 19 20 21 #include <osgUtil/TriStripVisitor> 22 20 23 21 24 #define DEF_WATER_COLOUR 0, 0, 0.5, 1 // R, G, B, Alpha (blue) 22 25 #define DEF_WATER_TRANSPARENCY 0.1 // 0=opaque, 1=transparent 23 #define DEF_ZOFFSET 0.0 026 #define DEF_ZOFFSET 0.01 24 27 25 28 // constructor … … 38 41 _node->addDrawable(_geom); 39 42 _node->setStateSet(_stateset); 40 _stateset->setAttribute(_material);43 //_stateset->setAttribute(_material); 41 44 42 // why??? 43 _geom->setUseDisplayList(false); 45 _geom->setUseDisplayList(true); 44 46 45 47 // initial geometry 46 48 setTimeStep(0); 47 49 48 _material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_WATER_COLOUR));49 _material->setSpecular(osg::Material::FRONT, osg::Vec4(1,1,1,1));50 _material->setTransparency(osg::Material::FRONT_AND_BACK, DEF_WATER_TRANSPARENCY);51 _material->setShininess(osg::Material::FRONT, 128);50 //_material->setDiffuse(osg::Material::FRONT, osg::Vec4(DEF_WATER_COLOUR)); 51 //_material->setSpecular(osg::Material::FRONT, osg::Vec4(1,1,1,1)); 52 //_material->setTransparency(osg::Material::FRONT_AND_BACK, DEF_WATER_TRANSPARENCY); 53 //_material->setShininess(osg::Material::FRONT, 128); 52 54 53 55 // environment map … … 57 59 texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); 58 60 texture->setImage(osgDB::readImageFile("envmap.jpg")); 59 _stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON );61 //_stateset->setTextureAttributeAndModes( 1, texture, osg::StateAttribute::ON ); 60 62 _stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); 61 63 62 64 // surface transparency 63 osg::BlendFunc* osgBlendFunc = new osg::BlendFunc(); 64 osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); 65 _stateset->setAttribute(osgBlendFunc); 66 _stateset->setMode(GL_BLEND, osg::StateAttribute::ON); 65 //osg::BlendFunc* osgBlendFunc = new osg::BlendFunc(); 66 //osgBlendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, osg::BlendFunc::ONE_MINUS_SRC_ALPHA); 67 //_stateset->setAttribute(osgBlendFunc); 68 //_stateset->setMode(GL_BLEND, osg::StateAttribute::ON); 69 70 osg::AlphaFunc* alphaFunc = new osg::AlphaFunc; 71 //alphaFunc->setFunction(osg::AlphaFunc::GEQUAL,0.1f); 72 alphaFunc->setFunction(osg::AlphaFunc::ALWAYS); 73 _stateset->setAttributeAndModes( alphaFunc, osg::StateAttribute::ON ); 74 67 75 _stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); 76 68 77 69 78 // automatically generate texture coords … … 74 83 texenv->setMode( osg::TexEnv::DECAL ); 75 84 texenv->setColor( osg::Vec4(0.6f,0.6f,0.6f,0.2f) ); 76 _stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON );77 _stateset->setTextureAttribute( 1, texenv );85 //_stateset->setTextureAttributeAndModes( 1, texgen, osg::StateAttribute::ON ); 86 //_stateset->setTextureAttribute( 1, texenv ); 78 87 } 79 88 … … 97 106 osg::ref_ptr<osg::Vec3Array> normals = _sww->getStagePrimitiveNormalArray(); 98 107 osg::ref_ptr<osg::Vec3Array> vertexnormals = _sww->getStageVertexNormalArray(); 99 108 osg::ref_ptr<osg::Vec4Array> colors = _sww->getStageColorArray(); 100 109 101 110 // vertical (z) offset to eliminate potential zbuffer problems with bedslope 102 //for( unsigned int iv=0; iv < vertices.get()->size(); iv++ ) 103 // vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, _zoffset ); 111 osg::UIntArray* colorindices = new osg::UIntArray(vertices.get()->size()); 112 for( unsigned int iv=0; iv < vertices.get()->size(); iv++ ) 113 { 114 vertices.get()->at(iv) += osg::Vec3f( 0.0, 0.0, _zoffset ); 115 colorindices->at(iv) = iv; 116 } 104 117 118 // geometry 105 119 _geom->setVertexArray( vertices.get() ); 106 120 _geom->setVertexIndices( indices.get() ); … … 108 122 osg::PrimitiveSet::TRIANGLES, 0, _sww->getNumberOfStageIndices() ) ); 109 123 110 //_geom->setNormalArray( normals.get() ); 111 //_geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE ); 124 // per vertex colors (using only alpha) 125 _geom->setColorArray( colors.get() ); 126 _geom->setColorIndices( colorindices ); 127 _geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); 112 128 129 // normals 113 130 _geom->setNormalArray( vertexnormals.get() ); 114 131 _geom->setNormalIndices( indices.get() ); 115 132 _geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); 133 134 // osgUtil::TriStripVisitor* optimize = new osgUtil::TriStripVisitor(); 135 // optimize->stripify( *_geom ); 116 136 117 137 } -
Swollen/swwreader/swwreader.cpp
r36 r44 39 39 #define DEF_CULLSTART CULLNONE 40 40 41 #define MIN(a, b) (a < b ? a : b) 42 #define MAX(a, b) (a > b ? a : b) 43 41 44 42 45 // only constructor, requires netcdf file … … 120 123 aspect_ratio = xrange/yrange; 121 124 if( aspect_ratio > 1.0 ) 122 123 _xscale = 1.0 / xrange;124 _xoffset = xmin;125 _xcenter = 0.5;126 127 _yscale = _xscale;128 _yoffset = ymin;129 _ycenter = 0.5 / aspect_ratio;130 131 _zscale = _xscale;132 _zoffset = zmin;133 _zcenter = 0.0;134 125 { 126 _xscale = 1.0 / xrange; 127 _xoffset = xmin; 128 _xcenter = 0.5; 129 130 _yscale = _xscale; 131 _yoffset = ymin; 132 _ycenter = 0.5 / aspect_ratio; 133 134 _zscale = _xscale; 135 _zoffset = zmin; 136 _zcenter = 0.0; 137 } 135 138 else 136 137 _yscale = 1.0 / yrange;138 _yoffset = ymin;139 _ycenter = 0.5;140 141 _xscale = _yscale;142 _xoffset = xmin;143 _xcenter = 0.5 / aspect_ratio;144 145 _zscale = _yscale;146 _zoffset = zmin;147 _zcenter = 0.0;148 139 { 140 _yscale = 1.0 / yrange; 141 _yoffset = ymin; 142 _ycenter = 0.5; 143 144 _xscale = _yscale; 145 _xoffset = xmin; 146 _xcenter = 0.5 / aspect_ratio; 147 148 _zscale = _yscale; 149 _zoffset = zmin; 150 _zcenter = 0.0; 151 } 149 152 150 153 osg::notify(osg::INFO) << "[SWWReader] xmin: " << xmin << std::endl; … … 252 255 _stagecentroids = new osg::Vec3Array; 253 256 _stageindices = new osg::UIntArray; 257 _stagecolors = new osg::Vec4Array; 254 258 osg::Vec3 v1b, v2b, v3b; 255 259 osg::Vec3 v1s, v2s, v3s; … … 261 265 // over all stage triangles 262 266 unsigned int nonculled = 0; 267 float alphamin = 1.0; 268 float alphamax = 0.0; 263 269 for (iv=0; iv < _nvolumes; iv++){ 264 270 … … 297 303 _stageindices->push_back( v3index ); 298 304 305 // alpha value based on stage-bedslope height difference 306 float alpha1 = ( v1s.z()-v1b.z() )*10.0; 307 float alpha2 = ( v2s.z()-v2b.z() )*10.0; 308 float alpha3 = ( v3s.z()-v3b.z() )*10.0; 309 alphamax = MAX( alphamax, alpha1 ); 310 alphamax = MAX( alphamax, alpha2 ); 311 alphamax = MAX( alphamax, alpha3 ); 312 alphamin = MIN( alphamin, alpha1 ); 313 alphamin = MIN( alphamin, alpha2 ); 314 alphamin = MIN( alphamin, alpha3 ); 315 316 osg::Vec4 color1, color2, color3; 317 color1.set( alpha1,alpha1,alpha1, 1.0 ); 318 color2.set( alpha2,alpha2,alpha2, 1.0 ); 319 color3.set( alpha3,alpha3,alpha3, 1.0 ); 320 //color1.set( alpha1,alpha1,alpha1, alpha1 ); 321 //color2.set( alpha2,alpha2,alpha2, alpha2 ); 322 //color3.set( alpha3,alpha3,alpha3, alpha3 ); 323 _stagecolors->push_back( color1 ); 324 _stagecolors->push_back( color2 ); 325 _stagecolors->push_back( color3 ); 326 299 327 // current triangle primitive normal 300 328 side1 = v2s - v1s; … … 317 345 318 346 } 347 348 std::cout << "index: " << index << " AlphaMax: " << alphamax << std::endl; 349 std::cout << "index: " << index << " AlphaMin: " << alphamin << std::endl; 319 350 320 351 // per-vertex normals -
Swollen/swwreadertest/swwreadertest.vcproj
r6 r44 103 103 CommandLine="$(TARGETPATH)"/> 104 104 <Tool 105 Name="VCPreBuildEventTool"/> 105 Name="VCPreBuildEventTool" 106 ExcludedFromBuild="TRUE"/> 106 107 <Tool 107 108 Name="VCPreLinkEventTool"/>
Note: See TracChangeset
for help on using the changeset viewer.