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

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

Added Vec2d, Vec3d and Vec4d classes, and remapped Vec2, Vec3 and Vec4 to
Vec2f, Vec3f an Vec4f respectively, with typedef's to the from Vec* to Vec*f.

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