Changeset 407 for experimental


Ignore:
Timestamp:
Aug 5, 2012, 11:09:39 PM (12 years ago)
Author:
Torben Dannhauer
Message:
 
Location:
experimental/distortionNG
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • experimental/distortionNG/DistortionManipulator.cpp

    r406 r407  
    308308                return;
    309309
    310         OSG_ALWAYS<<"ToDo: resetDistortion()"<<std::endl;
     310       
     311        _distortionSet->setDistortionMeshDimensions(2, 2, true);        // Reset dimensions and coordinates/texcoords & rebuild mesh data
     312        updateDistortionMesh(); // Rebuild OSG Mesh (drawable)
     313        // Restore ProjectionMatrix
     314       
     315        // Set up projection Matrix as it is done in View::setUpViewOnSingleScreen(
     316        double fovy, aspectRatio, zNear, zFar;
     317        _camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar);
     318
     319        double newAspectRatio = double(_distortionSet->intensityMap()->width) / double(_distortionSet->intensityMap()->height);
     320        double aspectRatioChange = newAspectRatio / aspectRatio;
     321        if (aspectRatioChange != 1.0)
     322        {
     323                _camera->getProjectionMatrix() *= osg::Matrix::scale(1.0/aspectRatioChange,1.0,1.0);
     324        }
     325
     326
    311327}
    312328
     
    599615                                                                                0.0     );
    600616                vertices->push_back( tmpVec );
    601                 //OSG_ALWAYS<<"Transfering mesh vertex : X:"<<tmpVec.x()<<" Y:"<<tmpVec.y()<<" Z:"<<tmpVec.z()<<std::endl;
     617                OSG_ALWAYS<<"Transfering mesh vertex : X:"<<tmpVec.x()<<" Y:"<<tmpVec.y()<<" Z:"<<tmpVec.z()<<std::endl;
    602618
    603619                // Note texCoords
     
    606622
    607623                texCoords->push_back(tmpTexCoords);
    608                 //OSG_ALWAYS<<"Transfering texcoord vertex : X:"<<tmpTexCoords.x()<<" Y:"<<tmpTexCoords.y()<<std::endl;
     624                OSG_ALWAYS<<"Transfering texcoord vertex : X:"<<tmpTexCoords.x()<<" Y:"<<tmpTexCoords.y()<<std::endl;
    609625
    610626                colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
  • experimental/distortionNG/DistortionSet.cpp

    r398 r407  
    2727        _matrixDirty = false;
    2828
    29         _distortionMeshRows = 2;
    30         _distortionMeshColumns = 2;
    31         _distortionMesh = new osg::Vec4Array();
     29        setDistortionMeshDimensions(2, 2);
    3230       
    3331        _intensityMap = NULL;
     
    5250}
    5351
    54 void DistortionSet::setDistortionMeshDimensions(int rows, int cols)
     52void DistortionSet::setDistortionMeshDimensions(int rows, int cols, bool enforceMeshRebuild)
    5553{
    5654        _distortionMeshRows = rows;
    5755        _distortionMeshColumns = cols;
    5856
    59         if(_distortionMesh->size() != _distortionMeshRows * _distortionMeshColumns)     // If dimensions differ: discard current mesh and create a new one
     57        if(!_distortionMesh.valid() || enforceMeshRebuild || _distortionMesh->size() != _distortionMeshRows * _distortionMeshColumns)   // If dimensions differ: discard current mesh and create a new one
    6058        {
    6159                _distortionMesh = new osg::Vec4Array(_distortionMeshRows * _distortionMeshColumns);
     
    6462                        for(int col=0;col<_distortionMeshColumns;col++)
    6563                        {
    66                                 float x=col/_distortionMeshColumns;     // Vertex X
    67                                 float y=row/_distortionMeshRows;        // Vertex Y
    68                                 float z=col/_distortionMeshColumns;     // TexCoord X
    69                                 float w=row/_distortionMeshRows;        // TexCoord Y
     64                                float x=col/(float)(_distortionMeshColumns-1);  // Vertex X
     65                                float y=row/(float)(_distortionMeshRows-1);     // Vertex Y
     66                                float z=col/(float)(_distortionMeshColumns-1);  // TexCoord X
     67                                float w=row/(float)(_distortionMeshRows-1);     // TexCoord Y
    7068
    7169                                _distortionMesh->at(row*_distortionMeshColumns+col).set(x,y,z,w);
  • experimental/distortionNG/DistortionSet.h

    r398 r407  
    5959        void clearDirtyStatus() { _meshDirty = false; _matrixDirty = false;}
    6060       
    61         void setDistortionMeshDimensions(int rows, int cols);
     61        void setDistortionMeshDimensions(int rows, int cols, bool enforceMeshRebuild=false);
    6262
    6363        osg::Image* getIntensityMap()  { return _intensityMap; }        // Also for manipulating the intensity map
  • experimental/distortionNG/main.cpp

    r404 r407  
    230230 * Laden des Containers.
    231231 * reset distortion implementieren.
    232  * Anwenden der distortion auf die Meshknoten oder die texturekoordinaten
     232 * Anwenden der manuellen distortion auf die Meshknoten oder die texturekoordinaten
    233233 *
    234234 *
Note: See TracChangeset for help on using the changeset viewer.