Ignore:
Timestamp:
Jun 16, 2012, 1:57:23 PM (12 years ago)
Author:
Torben Dannhauer
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionManipulator.cpp

    r386 r387  
    547547        for(unsigned int i=0;i<_distortionSet->getDistortionMesh()->size();i++)
    548548        {
     549                osg::Vec4 tmpSrc = _distortionSet->getDistortionMesh()->at(i);
     550
    549551                // Scale vector with the screen resolution
    550                 osg::Vec3 tmpVec = osg::Vec3(   _distortionSet->getDistortionMesh()->at(i).x()*_screenPixWidth,
    551                                                                                 _distortionSet->getDistortionMesh()->at(i).y()*_screenPixHeight,
     552                osg::Vec3 tmpVec = osg::Vec3(   tmpSrc.x()*_screenPixWidth,
     553                                                                                tmpSrc.y()*_screenPixHeight,
    552554                                                                                0.0     );
    553555                vertices->push_back( tmpVec );
     
    555557
    556558                // Note texCoords
    557                 osg::Vec2 tmpTexCoords = osg::Vec2(     _distortionSet->getDistortionMesh()->at(i).z()*_screenPixWidth,
    558                                                                                         _distortionSet->getDistortionMesh()->at(i).w()*_screenPixHeight );
     559                osg::Vec2 tmpTexCoords = osg::Vec2(     tmpSrc.z()*_screenPixWidth,
     560                                                                                        tmpSrc.w()*_screenPixHeight );
    559561                texCoords->push_back(tmpTexCoords);
     562                //OSG_ALWAYS<<"Transfering texcoord vertex : X:"<<tmpTexCoords.x()<<" Y:"<<tmpTexCoords.y()<<std::endl;
    560563
    561564                colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
    562565        }
    563566
    564         // Apply arrays
     567        // --------- Apply Arrays -----------------
    565568        osg::Geometry* geom = _distortionSet->getDistortionInternals()->getChild(osgViewer::DistortionSet::MESH)->asGeode()->getDrawable(0)->asGeometry();
    566569
    567         geom->removePrimitiveSet(0);
     570        // If arraysize differs: Replace primite sets
     571        bool regeneratePrimitiveSets = true;
     572        osg::Vec3Array* prevArray = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray());
     573        if(prevArray)
     574                regeneratePrimitiveSets = prevArray->size()!=vertices->size()?true:false;
     575       
     576        // Set new Arrays
    568577        geom->setVertexArray(vertices);
    569578        geom->setTexCoordArray(0, texCoords);   // todo: 0 ist hardcoded und müsste durch getTexUnitScene() ersetzt werden
    570579        geom->setColorArray(colors);
    571        
    572         // Quads grid
     580
     581        // If required: regenerate primitiveset:
     582        OSG_ALWAYS<<"PrimitiveSet regeneration required!"<<std::endl;
     583        geom->removePrimitiveSet(0, geom->getNumPrimitiveSets());       
     584        //// Create new primitives : Quads grid
    573585        unsigned int rows = _distortionSet->getDistortionMeshRows();
    574586        unsigned int columns = _distortionSet->getDistortionMeshColumns();
     
    583595                geom->addPrimitiveSet( de.get() );
    584596        }
    585        
    586         //geom->dirtyDisplayList();
    587 }
     597}
Note: See TracChangeset for help on using the changeset viewer.