| | 4 | |
| | 5 | #include <osg/Matrix> |
| | 6 | |
| | 7 | |
| | 8 | void 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 | |
| | 38 | void 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 | |
| | 68 | void 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 | } |
| 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 | |