root/OpenSceneGraph/trunk/examples/osgunittests/osgunittests.cpp @ 2323

Revision 2323, 6.7 kB (checked in by robert, 11 years ago)

Added getPerspective() method to Matrix* and SceneView?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#include <osg/UnitTestFramework>
2#include <osg/ArgumentParser>
3#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    double c_left=0;
14    double c_right=0;
15    double c_top=0;
16    double c_bottom=0;
17    double c_zNear=0;
18    double c_zFar=0;
19   
20   
21    std::cout << "testFrustum"<<f.getFrustum(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar)<<std::endl;
22    std::cout << "  left = "<<left<<" compute "<<c_left<<std::endl;
23    std::cout << "  right = "<<right<<" compute "<<c_right<<std::endl;
24
25    std::cout << "  bottom = "<<bottom<<" compute "<<c_bottom<<std::endl;
26    std::cout << "  top = "<<top<<" compute "<<c_top<<std::endl;
27
28    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
29    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
30   
31    std::cout << std::endl;
32}
33
34void testOrtho(double left,double right,double bottom,double top,double zNear,double zFar)
35{
36    osg::Matrix f;
37    f.makeOrtho(left,right,bottom,top,zNear,zFar);
38
39    double c_left=0;
40    double c_right=0;
41    double c_top=0;
42    double c_bottom=0;
43    double c_zNear=0;
44    double c_zFar=0;
45
46    std::cout << "testOrtho "<< f.getOrtho(c_left,c_right,c_bottom,c_top,c_zNear,c_zFar) << std::endl;
47    std::cout << "  left = "<<left<<" compute "<<c_left<<std::endl;
48    std::cout << "  right = "<<right<<" compute "<<c_right<<std::endl;
49
50    std::cout << "  bottom = "<<bottom<<" compute "<<c_bottom<<std::endl;
51    std::cout << "  top = "<<top<<" compute "<<c_top<<std::endl;
52
53    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
54    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
55   
56    std::cout << std::endl;
57}
58
59void testPerspective(double fovy,double aspect,double zNear,double zFar)
60{
61    osg::Matrix f;
62    f.makePerspective(fovy,aspect,zNear,zFar);
63
64    double c_fovy=0;
65    double c_aspect=0;
66    double c_zNear=0;
67    double c_zFar=0;
68
69    std::cout << "testPerspective "<< f.getPerspective(c_fovy,c_aspect,c_zNear,c_zFar) << std::endl;
70    std::cout << "  fovy = "<<fovy<<" compute "<<c_fovy<<std::endl;
71    std::cout << "  aspect = "<<aspect<<" compute "<<c_aspect<<std::endl;
72
73    std::cout << "  zNear = "<<zNear<<" compute "<<c_zNear<<std::endl;
74    std::cout << "  zFar = "<<zFar<<" compute "<<c_zFar<<std::endl;
75   
76    std::cout << std::endl;
77}
78
79void testLookAt(const osg::Vec3& eye,const osg::Vec3& center,const osg::Vec3& up)
80{
81    osg::Matrix mv;
82    mv.makeLookAt(eye,center,up);
83   
84    osg::Vec3 c_eye,c_center,c_up;
85    mv.getLookAt(c_eye,c_center,c_up);
86   
87    std::cout << "testLookAt"<<std::endl;
88    std::cout << "  eye "<<eye<< " compute "<<c_eye<<std::endl;
89    std::cout << "  eye "<<center<< " compute "<<c_center<<std::endl;
90    std::cout << "  eye "<<up<< " compute "<<c_up<<std::endl;
91   
92    std::cout << std::endl;
93   
94}
95
96void sizeOfTest()
97{
98  std::cout<<"sizeof(bool)=="<<sizeof(bool)<<std::endl;
99  std::cout<<"sizeof(char)=="<<sizeof(char)<<std::endl;
100  std::cout<<"sizeof(short)=="<<sizeof(short)<<std::endl;
101  std::cout<<"sizeof(int)=="<<sizeof(int)<<std::endl;
102  std::cout<<"sizeof(long)=="<<sizeof(long)<<std::endl;
103  std::cout<<"sizeof(long int)=="<<sizeof(long int)<<std::endl;
104
105#if defined(_MSC_VER)
106  // long long isn't supported on VS6.0...
107  std::cout<<"sizeof(__int64)=="<<sizeof(__int64)<<std::endl;
108#else
109  std::cout<<"sizeof(long long)=="<<sizeof(long long)<<std::endl;
110#endif
111  std::cout<<"sizeof(float)=="<<sizeof(float)<<std::endl;
112  std::cout<<"sizeof(double)=="<<sizeof(double)<<std::endl;
113}
114
115int main( int argc, char** argv )
116{
117    osg::ArgumentParser arguments(&argc,argv);
118
119    // set up the usage document, in case we need to print out how to use this program.
120    arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" is the example which runs units tests.");
121    arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options]");
122    arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information");
123    arguments.getApplicationUsage()->addCommandLineOption("qt","Display qualified tests.");
124    arguments.getApplicationUsage()->addCommandLineOption("sizeof","Display sizeof tests.");
125    arguments.getApplicationUsage()->addCommandLineOption("matrix","Display qualified tests.");
126 
127
128    if (arguments.argc()<=1)
129    {
130        arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION);
131        return 1;
132    }
133
134    bool printQualifiedTest = false;
135    while (arguments.read("qt")) printQualifiedTest = true;
136
137    bool printMatrixTest = false;
138    while (arguments.read("matrix")) printMatrixTest = true;
139
140    bool printSizeOfTest = false;
141    while (arguments.read("sizeof")) printSizeOfTest = true;
142
143    // if user request help write it out to cout.
144    if (arguments.read("-h") || arguments.read("--help"))
145    {
146        std::cout<<arguments.getApplicationUsage()->getCommandLineUsage()<<std::endl;
147        arguments.getApplicationUsage()->write(std::cout,arguments.getApplicationUsage()->getCommandLineOptions());
148        return 1;
149    }
150
151    // any option left unread are converted into errors to write out later.
152    arguments.reportRemainingOptionsAsUnrecognized();
153
154    // report any errors if they have occured when parsing the program aguments.
155    if (arguments.errors())
156    {
157        arguments.writeErrorMessages(std::cout);
158        return 1;
159    }
160   
161
162    if (printMatrixTest)
163    {
164        std::cout<<"******   Running matrix tests   ******"<<std::endl;
165
166        testFrustum(-1,1,-1,1,1,1000);
167        testFrustum(0,1,1,2,2.5,100000);
168
169        testOrtho(0,1,1,2,2.1,1000);
170        testOrtho(-1,10,1,20,2.5,100000);
171
172        testPerspective(20,1,1,1000);
173        testPerspective(90,2,1,1000);
174
175        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));
176        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));
177
178    }
179   
180    if (printSizeOfTest)
181    {
182        std::cout<<"**** sizeof() tests  ******"<<std::endl;
183       
184        sizeOfTest();
185
186        std::cout<<std::endl;
187    }
188
189
190    if (printQualifiedTest)
191    {
192         std::cout<<"*****   Qualified Tests  ******"<<std::endl;
193
194         osgUtx::QualifiedTestPrinter printer;
195         osgUtx::TestGraph::instance().root()->accept( printer );   
196         std::cout<<std::endl;
197    }
198
199    std::cout<<"******   Running tests   ******"<<std::endl;
200
201    // Global Data or Context
202    osgUtx::TestContext ctx;
203    osgUtx::TestRunner runner( ctx );
204    runner.specify("root");
205
206    osgUtx::TestGraph::instance().root()->accept( runner );
207
208    return 0;
209}
Note: See TracBrowser for help on using the browser.