Ignore:
Timestamp:
Jun 30, 2012, 8:56:16 PM (12 years ago)
Author:
Torben Dannhauer
Message:

vertex- and texcoord warping works now :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionSetupStrategyProjectSyntropy.cpp

    r393 r394  
    2828        _blendmapFilename = "";
    2929        _frustumFilename = "";
    30         _vertexDistortionFilename = "";
    31         _texCoordDistortionFilename = "";
    32         _distortionType = DistortionSetupStrategy::UNDEFINED;
     30        _distortionFilename = "";
    3331
    3432        _distortionInitialized=false;
     
    4038}
    4139
    42 void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles( std::string vertexDistortionFile, std::string texCoordDistortionFile, std::string blendmapFile, std::string frustumFile, DistortionSetupStrategy::distortionType type)
    43 {
    44         _distortionType = type;
     40void DistortionSetupStrategyProjectSyntropy::setDistortionInputFiles(std::string distortionFile, std::string blendmapFile, std::string frustumFile)
     41{
    4542        _blendmapFilename = blendmapFile;
    4643        _frustumFilename = frustumFile;
    47         _vertexDistortionFilename = vertexDistortionFile;
    48         _texCoordDistortionFilename = texCoordDistortionFile;
     44        _distortionFilename = distortionFile;
    4945}
    5046
     
    168164}
    169165
    170 int DistortionSetupStrategyProjectSyntropy::readMeshPointsFromCSVFile(std::string filePath, osg::Vec2Array* tmpMesh)
     166int DistortionSetupStrategyProjectSyntropy::readMeshPointsFromCSVFile(std::string filePath, osg::Vec4Array* tmpMesh)
    171167{
    172168        int numValues=6;
     
    211207
    212208                                // Store values into array
    213                                 tmpMesh->push_back(osg::Vec2(values[0], values[1]));
     209                                tmpMesh->push_back(osg::Vec4(values[0], values[1], values[2], values[3]));
    214210                        }
    215211                }
     
    233229        }
    234230
    235         if(     _distortionType == DistortionSetupStrategy::UNDEFINED
    236                         || _blendmapFilename.empty()
    237                         || _frustumFilename.empty()
    238                         || ( _vertexDistortionFilename.empty() && _distortionType == DistortionSetupStrategy::VERTEXDISTORTION )
    239                         || ( _texCoordDistortionFilename.empty() && _distortionType == DistortionSetupStrategy::TEXCOORDDISTORTION )
    240         )
    241         {
    242                 OSG_ALWAYS<<"DistortionSetupStrategyProjectSyntropy::delegateDistortionSetup : You have not specified the imput filenames and distortion type correctly!"<<std::endl;
     231        if(      _blendmapFilename.empty() || _frustumFilename.empty() ||  _distortionFilename.empty() )
     232        {
     233                OSG_ALWAYS<<"DistortionSetupStrategyProjectSyntropy::delegateDistortionSetup : You have not specified the imput filenames correctly!"<<std::endl;
    243234                return;
    244235        }
     
    348339                        //*******************************************************************************************//
    349340                        //***    MESH WARPING                                                                                                                                     ***//
    350                         //***    Both Vertex Warping and Texcoord Warping is supported. Although there might      ***//
     341                        //***    Both Vertex Warping and Texcoord Warping is supported.
     342                        //***    The input file contains . Although there might      ***//
    351343                        //***    be a preferred version for osgvisual, both options should be implemented in osg  ***//
    352344                        //*******************************************************************************************//
    353345
    354346                        // Exctract mesh dimensions from file and pass them to the container.
    355                         // If soley texCoordDistortion is used, _texCoordDistortionFilename is used to determine the dimensions, otherwise _vertexDistortionFilename
     347
    356348                        int distortionMeshRows=0, distortionMeshColumns=0;
    357                         readMeshDimensionsFromCSVFile(_distortionType==DistortionSetupStrategy::TEXCOORDDISTORTION?_texCoordDistortionFilename:_vertexDistortionFilename, &distortionMeshRows, &distortionMeshColumns);
     349                        readMeshDimensionsFromCSVFile(_distortionFilename, &distortionMeshRows, &distortionMeshColumns);
    358350
    359351                        distortionSet->setDistortionMeshRows(distortionMeshRows);
    360352                        distortionSet->setDistortionMeshColumns(distortionMeshColumns);
    361353
    362                         // If vertex- and texCoord distortion is combined: Ensure both files have the same dimensions
    363                         if(_distortionType==DistortionSetupStrategy::COMBINEDDISTORTION)
    364                         {
    365                                 int texCoordRows=0, texCoordColumns=0;
    366                                 readMeshDimensionsFromCSVFile(_texCoordDistortionFilename, &distortionMeshRows, &distortionMeshColumns);
    367                                 if(distortionMeshRows!=texCoordRows || distortionMeshColumns!=texCoordColumns)
    368                                 {
    369                                         OSG_ALWAYS<<"The mesh dimensions of the vertex- and textureCoordinate-file differ!"<<std::endl;
    370                                         return;
    371                                 }
    372                         }
    373 
    374354                        // Read in the mesh arrays
    375                         osg::Vec2Array* vertexMeshVec2 = new osg::Vec2Array;
    376                         osg::Vec2Array* texCoordMeshVec2 = new osg::Vec2Array;
    377                         osg::Vec4Array* distortionMesh = new osg::Vec4Array(distortionMeshRows*distortionMeshColumns);
    378                        
    379                         if((_distortionType==VERTEXDISTORTION) || (_distortionType==COMBINEDDISTORTION))
    380                         {
    381                                 readMeshPointsFromCSVFile(_vertexDistortionFilename, vertexMeshVec2);
    382                         }
    383 
    384                         if((_distortionType==TEXCOORDDISTORTION) || (_distortionType==COMBINEDDISTORTION))
    385                         {
    386                                 readMeshPointsFromCSVFile(_texCoordDistortionFilename, texCoordMeshVec2);
    387                         }
    388 
    389                         // Transfer the read values into the combinedArray
    390                         for(int row=0;row<distortionMeshRows;row++)
    391                         {
    392                                 for(int col=0;col<distortionMeshColumns;col++)
    393                                 {
    394                                         float x=(float)col/(float)(distortionMeshColumns-1);    // Vertex X
    395                                         float y=(float)row/(float)(distortionMeshRows-1);               // Vertex Y
    396                                         float z=(float)col/(float)(distortionMeshColumns-1);    // TexCoord X
    397                                         float w=(float)row/(float)(distortionMeshRows-1);               // TexCoord Y
    398 
    399                                         if(_distortionType==VERTEXDISTORTION || _distortionType==COMBINEDDISTORTION)
    400                                         {
    401                                                 x = vertexMeshVec2->at(row*distortionMeshColumns + col).x();
    402                                                 y = vertexMeshVec2->at(row*distortionMeshColumns + col).y();
    403                                         }
    404                                         if(_distortionType==TEXCOORDDISTORTION || _distortionType==COMBINEDDISTORTION)
    405                                         {
    406                                                 z = texCoordMeshVec2->at(row*distortionMeshColumns + col).x();
    407                                                 w = texCoordMeshVec2->at(row*distortionMeshColumns + col).y();
    408                                         }
    409 
    410                                         distortionMesh->at(row*distortionMeshColumns+col).set(x,y,z,w);
    411                                 }
    412                         }
     355                        osg::Vec4Array* distortionMesh = new osg::Vec4Array;
     356                        readMeshPointsFromCSVFile(_distortionFilename, distortionMesh);
    413357
    414358#if 1
     
    421365
    422366                        distortionSet->setDistortionMesh(distortionMesh);
    423                         //distortionSet->setDistortionMeshColumns(distortionMeshColumns);
    424                         //distortionSet->setDistortionMeshRows(distortionMeshRows);
    425367                        distortionSet->setDistortionMeshDimensions(distortionMeshRows, distortionMeshColumns);
    426368                }
Note: See TracChangeset for help on using the changeset viewer.