Show
Ignore:
Timestamp:
10/21/14 17:10:27 (3 days ago)
Author:
robert
Message:

Added shaders to support experimental shader based displacement mapping technique osgTerrain::ShaderTerrain?.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgManipulator/TrackballDragger.cpp

    r13566 r13855  
    2929{ 
    3030 
    31 osg::Geometry* createCircleGeometry(float radius, unsigned int numSegments) 
    32 { 
    33     const float angleDelta = 2.0f*osg::PI/(float)numSegments; 
    34     const float r = radius; 
    35     float angle = 0.0f; 
    36     osg::Vec3Array* vertexArray = new osg::Vec3Array(numSegments); 
    37     osg::Vec3Array* normalArray = new osg::Vec3Array(numSegments); 
    38     for(unsigned int i = 0; i < numSegments; ++i,angle+=angleDelta) 
     31    osg::Geometry* createCircleGeometry(float radius, unsigned int numSegments) 
    3932    { 
    40         float c = cosf(angle); 
    41         float s = sinf(angle); 
    42         (*vertexArray)[i].set(c*r,s*r,0.0f); 
    43         (*normalArray)[i].set(c,s,0.0f); 
     33        const float angleDelta = 2.0f*osg::PI/(float)numSegments; 
     34        const float r = radius; 
     35        float angle = 0.0f; 
     36        osg::Vec3Array* vertexArray = new osg::Vec3Array(numSegments); 
     37        osg::Vec3Array* normalArray = new osg::Vec3Array(numSegments); 
     38        for(unsigned int i = 0; i < numSegments; ++i,angle+=angleDelta) 
     39        { 
     40            float c = cosf(angle); 
     41            float s = sinf(angle); 
     42            (*vertexArray)[i].set(c*r,s*r,0.0f); 
     43            (*normalArray)[i].set(c,s,0.0f); 
     44        } 
     45        osg::Geometry* geometry = new osg::Geometry(); 
     46        geometry->setVertexArray(vertexArray); 
     47        geometry->setNormalArray(normalArray, osg::Array::BIND_PER_VERTEX); 
     48        geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,vertexArray->size())); 
     49        return geometry; 
    4450    } 
    45     osg::Geometry* geometry = new osg::Geometry(); 
    46     geometry->setVertexArray(vertexArray); 
    47     geometry->setNormalArray(normalArray, osg::Array::BIND_PER_VERTEX); 
    48     geometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,vertexArray->size())); 
    49     return geometry; 
    50 } 
    5151 
    5252} 
     
    103103    } 
    104104 
     105    _axisLineWidth = 2.0f; 
     106    _pickCylinderHeight = 0.15f; 
     107 
    105108    setParentDragger(getParentDragger()); 
    106109} 
     
    112115void TrackballDragger::setupDefaultGeometry() 
    113116{ 
    114     osg::Geode* geode = new osg::Geode; 
     117    _geode = new osg::Geode; 
    115118    { 
    116119        osg::TessellationHints* hints = new osg::TessellationHints; 
     
    119122        hints->setCreateBackFace(false); 
    120123 
    121         osg::Cylinder* cylinder = new osg::Cylinder; 
    122         cylinder->setHeight(0.15f); 
    123         osg::ShapeDrawable* cylinderDrawable = new osg::ShapeDrawable(cylinder,hints); 
    124         geode->addDrawable(cylinderDrawable); 
     124        _cylinder = new osg::Cylinder; 
     125        _cylinder->setHeight(_pickCylinderHeight); 
     126        osg::ShapeDrawable* cylinderDrawable = new osg::ShapeDrawable(_cylinder, hints); 
     127        _geode->addDrawable(cylinderDrawable); 
    125128        setDrawableToAlwaysCull(*cylinderDrawable); 
    126         geode->addDrawable(createCircleGeometry(1.0f, 100)); 
     129        _geode->addDrawable(createCircleGeometry(1.0f, 100)); 
    127130    } 
    128131 
     
    131134        osg::PolygonMode* polymode = new osg::PolygonMode; 
    132135        polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE); 
    133         geode->getOrCreateStateSet()->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); 
    134         geode->getOrCreateStateSet()->setAttributeAndModes(new osg::LineWidth(2.0f),osg::StateAttribute::ON); 
     136        _geode->getOrCreateStateSet()->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); 
     137        _lineWidth = new osg::LineWidth(_axisLineWidth); 
     138        _geode->getOrCreateStateSet()->setAttributeAndModes(_lineWidth, osg::StateAttribute::ON); 
    135139 
    136         #if !defined(OSG_GLES2_AVAILABLE) 
    137             geode->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON); 
    138         #endif 
     140#if !defined(OSG_GLES2_AVAILABLE) 
     141        _geode->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON); 
     142#endif 
    139143 
    140144    } 
    141145 
    142146    // Add line to all the individual 1D draggers. 
    143     _xDragger->addChild(geode); 
    144     _yDragger->addChild(geode); 
    145     _zDragger->addChild(geode); 
     147    _xDragger->addChild(_geode); 
     148    _yDragger->addChild(_geode); 
     149    _zDragger->addChild(_geode); 
    146150 
    147151 
     
    173177    } 
    174178} 
     179 
     180void TrackballDragger::setAxisLineWidth(float linePixelWidth) 
     181{ 
     182    _axisLineWidth = linePixelWidth; 
     183    if (_lineWidth.valid()) 
     184        _lineWidth->setWidth(linePixelWidth); 
     185} 
     186void TrackballDragger::setPickCylinderHeight(float pickCylinderHeight) 
     187{ 
     188    _pickCylinderHeight = pickCylinderHeight; 
     189    if (_cylinder.valid()) 
     190        _cylinder->setHeight(pickCylinderHeight); 
     191}