source: Swollen/swollen/bedslope.cpp @ 65

Last change on this file since 65 was 65, checked in by darran, 20 years ago
File size: 2.4 KB
Line 
1
2
3#include <bedslope.h>
4
5#include <osg/Texture2D>
6#include <osg/TexEnv>
7#include <osgUtil/SmoothingVisitor>
8
9
10#define DEF_BEDSLOPE_COLOUR     145, 122, 59, 255     // R, G, B, Alpha (brown)
11
12
13// constructor
14BedSlope::BedSlope(SWWReader* sww)
15{
16    // persistent
17    _sww = sww;
18
19    // bedslope geometry as triangles with shared vertices
20    _geom = new osg::Geometry;
21
22    // geometry from sww file
23    osg::Vec3Array* vertices = _sww->getBedslopeVertexArray().get();
24    //osg::Vec3Array* normals = _sww->getBedslopeNormalArray().get();
25
26    _geom->setUseDisplayList(true);
27    _geom->setVertexArray( vertices );
28    _geom->addPrimitiveSet( _sww->getBedslopeIndexArray().get() );
29    //_geom->setNormalArray( normals );
30    //_geom->setNormalBinding( osg::Geometry::BIND_PER_PRIMITIVE );
31    _geom->setTexCoordArray( 0, _sww->getBedslopeTextureCoords().get() );
32
33    osg::UByte4Array* color = new osg::UByte4Array(1);
34    (*color)[0] = osg::UByte4( 255,255,255,255 );
35    _geom->setColorArray( color );
36    _geom->setColorBinding( osg::Geometry::BIND_OVERALL );
37
38    // Calculate per-vertex normals
39    osgUtil::SmoothingVisitor* visitor = new osgUtil::SmoothingVisitor();
40    visitor->smooth( *_geom );
41
42    // bedslope texture
43    osg::Texture2D* texture = new osg::Texture2D;
44    texture->setDataVariance(osg::Object::DYNAMIC);
45    texture->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
46    texture->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
47    texture->setImage( _sww->getBedslopeTexture() );
48
49    // material
50    _material = new osg::Material();
51    _material->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4(0.2, 0.2, 0.2, 1.0) );
52    _material->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4(1.0, 1.0, 1.0, 1.0) );
53    _material->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4(0.8, 0.8, 0.8, 1.0) );
54    _material->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4(0.0, 0.0, 0.0, 1.0) );
55
56
57    // state
58    _stateset = new osg::StateSet;
59    _stateset->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON );
60    _stateset->setAttributeAndModes(_material, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE );
61    _stateset->setMode( GL_BLEND, osg::StateAttribute::ON );
62    _stateset->setMode( GL_LIGHTING, osg::StateAttribute::ON );
63
64    _node = new osg::Geode;
65    _node->setName("bedslope");
66    _node->addDrawable(_geom);
67    _node->setStateSet(_stateset);
68
69}
70
Note: See TracBrowser for help on using the repository browser.