Files Classes Functions Hierarchy
00001 #include <cassert> 00002 #include <iostream> 00003 #include <vector> 00004 #include <string> 00005 using namespace std; 00006 00007 #include <commandline.h> 00008 #include <graphmisc.h> 00009 #include <vrmltest.h> 00010 #include <vrmlshaperaw.h> 00011 #include <vrmlconvert.h> 00012 #include <zpr.h> 00013 00014 vrmlshapeparse vrmltest::vsp; 00015 vector< vrmlshape > vrmltest::vs; 00016 bool vrmltest::winding(false); 00017 vrmllines vrmltest::vL; 00018 00019 00020 void vrmltest::keyboard(unsigned char key, int x, int y) 00021 { 00022 switch (key) 00023 { 00024 case 27: exit(0); break; 00025 } 00026 } 00027 00028 void vrmltest::display() 00029 { 00030 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00031 myglPushMatrix temp; 00032 00033 unsigned int const imax = vs.size(); 00034 if (winding) 00035 for (unsigned int i=0; i<imax; ++i) 00036 vs[i].writePwind(); 00037 else 00038 for (unsigned int i=0; i<imax; ++i) 00039 vs[i].writePN(); 00040 00041 vL.writePC(); 00042 00043 glerrordisplay(); 00044 00045 glutSwapBuffers(); 00046 } 00047 00048 00049 void vrmltest::getfilename(string & filename) 00050 { 00051 cout << "Enter filename to parse." << endl; 00052 cout << " eg p3.wrl" << endl; 00053 00054 cin >> filename; 00055 } 00056 00057 void vrmltest::test01(int argc, char** argv) 00058 { 00059 vrmlshapeparse p; 00060 00061 // string filename; 00062 // getfilename(filename); 00063 00064 string filename("head.wrl"); 00065 assert( p.readfile(filename.c_str()) ); 00066 00067 vector< vrmlshape > s; 00068 vrmlconvert vc; 00069 00070 assert(vc.eval(s,p)); 00071 00072 cout << endl << endl; 00073 cout << "Printing vrmlshape" << endl; 00074 cout << endl; 00075 cout << "s.size()=" << s.size() << endl; 00076 cout << endl; 00077 00078 00079 for (unsigned int i=0; i<s.size(); ++i) 00080 s[i].print(cout); 00081 } 00082 00083 void vrmltest::test02(int argc, char** argv) 00084 { 00085 cout << endl; 00086 cout << "VRML reader" << endl; 00087 cout << endl; 00088 cout << "$./main filename=<file>.wrl" << endl; 00089 cout << " seenormals=true - to see the normals." << endl; 00090 cout << " winding=true - to see the triangles winding." << endl; 00091 cout << endl; 00092 00093 commandline cmd(argc,argv); 00094 string vrmlfile("head.wrl"); 00095 cmd.mapvar(vrmlfile,"vrmlfile"); 00096 if (vrmlfile.empty()) 00097 { 00098 cout << "error: file must be assigned." << endl; 00099 cout << " eg vrmlfile=head.wrl" << endl; 00100 return; 00101 } 00102 00103 if (! vsp.readfile(vrmlfile) ) 00104 { 00105 cout << "error: file not read in." << endl; 00106 return; 00107 } 00108 00109 vrmlconvert().eval(vs,vsp); 00110 00111 cmd.mapvar(winding,"winding"); 00112 00113 bool seenormals(false); 00114 cmd.mapvar(seenormals,"seenormals"); 00115 if (seenormals) 00116 { 00117 00118 float ci[3]; 00119 ci[0] = 1.0; 00120 ci[1] = 0.0; 00121 ci[2] = 0.0; 00122 00123 for (unsigned int i=0; i<vs.size(); ++i) 00124 vL.addnormals(vs[i],(float*)ci,1.8); 00125 } 00126 00127 glutInit(&argc,argv); 00128 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00129 glutInitWindowSize(800,800); 00130 glutCreateWindow(""); 00131 glutDisplayFunc(display); 00132 glutKeyboardFunc(keyboard); 00133 00134 zpr zz; 00135 00136 OpenGLinitialisation(); 00137 00138 glEnable(GL_DEPTH_TEST); 00139 glEnable(GL_CULL_FACE); 00140 glEnable(GL_NORMALIZE); 00141 00142 zz.update(); 00143 00144 camera::lookat(cmd,0.0,0.0,4.0); 00145 00146 GLdouble s=0.25; 00147 glScalef(s,s,s); 00148 00149 glutMainLoop(); 00150 } 00151 00152 void vrmltest::test03(int argc, char** argv) 00153 { 00154 vrmlshapeparse p; 00155 00156 string filename; 00157 getfilename(filename); 00158 00159 p.readfile(filename.c_str()); 00160 00161 cout << "Reading " << filename << endl; 00162 00163 if (p.vshp.empty()==false) 00164 { 00165 for (uint i=0; i<p.vshp.size(); ++i) 00166 p.vshp[i].print(cout); 00167 } 00168 } 00169
1.5.8