Changeset 386 for experimental


Ignore:
Timestamp:
Jun 15, 2012, 10:29:26 PM (13 years ago)
Author:
Torben Dannhauer
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionManipulator.cpp

    r385 r386  
    543543        osg::Vec3Array* vertices = new osg::Vec3Array;
    544544        osg::Vec2Array* texCoords = new osg::Vec2Array;
     545        osg::Vec4Array* colors = new osg::Vec4Array;
    545546
    546547        for(unsigned int i=0;i<_distortionSet->getDistortionMesh()->size();i++)
     
    551552                                                                                0.0     );
    552553                vertices->push_back( tmpVec );
    553                 OSG_ALWAYS<<"X:"<<tmpVec.x()<<" Y:"<<tmpVec.y()<<" Z:"<<tmpVec.z()<<std::endl;
     554                OSG_ALWAYS<<"Transfering mesh vertex : X:"<<tmpVec.x()<<" Y:"<<tmpVec.y()<<" Z:"<<tmpVec.z()<<std::endl;
    554555
    555556                // Note texCoords
     
    557558                                                                                        _distortionSet->getDistortionMesh()->at(i).w()*_screenPixHeight );
    558559                texCoords->push_back(tmpTexCoords);
     560
     561                colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
    559562        }
    560563
    561564        // Apply arrays
    562         _distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setVertexArray(vertices);
    563         _distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->setTexCoordArray(0, texCoords);    // todo: 0 ist hardcoded und müsste durch getTexUnitScene() ersetzt werden
    564         _distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry()->dirtyDisplayList();
    565 }
     565        osg::Geometry* geom = _distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry();
     566
     567        geom->removePrimitiveSet(0);
     568        geom->setVertexArray(vertices);
     569        geom->setTexCoordArray(0, texCoords);   // todo: 0 ist hardcoded und müsste durch getTexUnitScene() ersetzt werden
     570        geom->setColorArray(colors);
     571       
     572        // Quads grid
     573        unsigned int rows = _distortionSet->getDistortionMeshRows();
     574        unsigned int columns = _distortionSet->getDistortionMeshColumns();
     575        for ( unsigned int row=0; row<rows-1; row++ )   // each strip consists of two affected vertex rows, so we need only row-1 strips.
     576        {
     577                osg::ref_ptr<osg::DrawElementsUInt> de = new osg::DrawElementsUInt(osg::PrimitiveSet::QUAD_STRIP, columns*2);   // columns*2 = number of involved vertices for this strip.
     578                for ( unsigned int col=0; col<columns; col++ )
     579                {
     580                        (*de)[col*2 + 0] = row*columns + col;
     581                        (*de)[col*2 + 1] = (row+1)*columns + col;
     582                }
     583                geom->addPrimitiveSet( de.get() );
     584        }
     585       
     586        //geom->dirtyDisplayList();
     587}
Note: See TracChangeset for help on using the changeset viewer.