Show
Ignore:
Timestamp:
07/16/03 22:14:48 (11 years ago)
Author:
robert
Message:

Added osg::Matrix::getOtho,getFrustum and getLookAt() methods.

Added test for new matrix methods into unit tests example, but these really
should go in their own lib...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/examples/osgunittests/osgunittests.cpp

    r1844 r2039  
    22#include <osg/ArgumentParser> 
    33#include <osg/ApplicationUsage> 
     4 
     5#include <osg/Matrix> 
     6 
     7 
     8void testFrustum(double left,double right,double bottom,double top,double zNear,double zFar) 
     9{ 
     10    osg::Matrix f; 
     11    f.makeFrustum(left,right,bottom,top,zNear,zFar); 
     12 
     13     
     14    double c_zNear = f(3,2) / (f(2,2)-1.0f); 
     15    double c_zFar = f(3,2) / (1.0f+f(2,2)); 
     16     
     17    double c_left = c_zNear * (f(2,0)-1.0f) / f(0,0); 
     18    double c_right = c_zNear * (1.0f+f(2,0)) / f(0,0); 
     19 
     20    double c_top = c_zNear * (1+f(2,1)) / f(1,1); 
     21    double c_bottom = c_zNear * (f(2,1)-1.0f) / f(1,1); 
     22     
     23    f.getFrustum(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar); 
     24 
     25    std::cout << "testFrustum"<<std::endl; 
     26    std::cout << "  left = "<<left<<" compute "<<c_left<<std::endl; 
     27    std::cout << "  right = "<<right<<" compute "<<c_right<<std::endl; 
     28 
     29    std::cout << "  bottom = "<<bottom<<" compute "<<c_bottom<<std::endl; 
     30    std::cout << "  top = "<<top<<" compute "<<c_top<<std::endl; 
     31 
     32    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl; 
     33    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl; 
     34     
     35    std::cout << std::endl; 
     36} 
     37 
     38void testOrtho(double left,double right,double bottom,double top,double zNear,double zFar) 
     39{ 
     40    osg::Matrix f; 
     41    f.makeOrtho(left,right,bottom,top,zNear,zFar); 
     42 
     43    double c_zNear = (f(3,2)+1.0f) / f(2,2); 
     44    double c_zFar = (f(3,2)-1.0f) / f(2,2); 
     45     
     46    double c_left = -(1.0f+f(3,0)) / f(0,0); 
     47    double c_right = (1.0f-f(3,0)) / f(0,0); 
     48 
     49    double c_bottom = -(1.0f+f(3,1)) / f(1,1); 
     50    double c_top = (1.0f-f(3,1)) / f(1,1); 
     51     
     52    f.getOrtho(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar); 
     53 
     54 
     55    std::cout << "testOrtho"<<std::endl; 
     56    std::cout << "  left = "<<left<<" compute "<<c_left<<std::endl; 
     57    std::cout << "  right = "<<right<<" compute "<<c_right<<std::endl; 
     58 
     59    std::cout << "  bottom = "<<bottom<<" compute "<<c_bottom<<std::endl; 
     60    std::cout << "  top = "<<top<<" compute "<<c_top<<std::endl; 
     61 
     62    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl; 
     63    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl; 
     64     
     65    std::cout << std::endl; 
     66} 
     67 
     68void testLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up) 
     69{ 
     70    osg::Matrix mv; 
     71    mv.makeLookAt(eye,center,up); 
     72     
     73    osg::Vec3 c_eye,c_center,c_up; 
     74    mv.getLookAt(c_eye,c_center,c_up); 
     75     
     76    std::cout << "testLookAt"<<std::endl; 
     77    std::cout << "  eye "<<eye<< " compute "<<c_eye<<std::endl; 
     78    std::cout << "  eye "<<center<< " compute "<<c_center<<std::endl; 
     79    std::cout << "  eye "<<up<< " compute "<<c_up<<std::endl; 
     80     
     81    std::cout << std::endl; 
     82     
     83} 
    484 
    585int main( int argc, char** argv ) 
     
    1292    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 
    1393    arguments.getApplicationUsage()->addCommandLineOption("qt","Display qualified tests."); 
     94    arguments.getApplicationUsage()->addCommandLineOption("matrix","Display qualified tests."); 
    1495  
     96 
     97    if (arguments.argc()<=1) 
     98    { 
     99        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
     100        return 1; 
     101    } 
    15102 
    16103    bool printQualifiedTest = false;  
    17104    while (arguments.read("qt")) printQualifiedTest = true;  
     105 
     106    bool displayMatrixTest = false;  
     107    while (arguments.read("matrix")) displayMatrixTest = true;  
    18108 
    19109    // if user request help write it out to cout. 
     
    35125    } 
    36126     
    37     if (arguments.argc()<=1) 
     127 
     128    if (displayMatrixTest) 
    38129    { 
    39         arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); 
    40         return 1; 
     130        std::cout<<"******   Running matrix tests   ******"<<std::endl; 
     131 
     132        testFrustum(-1,1,-1,1,1,1000); 
     133        testFrustum(0,1,1,2,2.5,100000); 
     134 
     135        testOrtho(0,1,1,2,2.1,1000); 
     136        testOrtho(-1,10,1,20,2.5,100000); 
     137 
     138        testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(0.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0)); 
     139        testLookAt(osg::Vec3(10.0,4.0,2.0),osg::Vec3(10.0,4.0,2.0)+osg::Vec3(1.0,1.0,0.0),osg::Vec3(0.0,0.0,1.0)); 
     140 
    41141    } 
    42142