Files Classes Functions Hierarchy
00001 00002 #include <iostream> 00003 using namespace std; 00004 00005 #include <GL/glut.h> 00006 00007 #include <commandline.h> 00008 #include <gobj.h> 00009 #include <graphmisc.h> 00010 #include <point.h> 00011 #include <print.h> 00012 #include <vecinterp.h> 00013 #include <zpr.h> 00014 00015 typedef point2<double> pt2; 00016 00017 gobjContainer xGraphics; 00018 00019 void test01() 00020 { 00021 00022 pt2 p0(1.0,0.0); 00023 pt2 p1(0.0,1.0); 00024 00025 vecInterp2D0<pt2> fx(p0,p1); 00026 00027 pt2 y; 00028 fx(y,0.0); 00029 cout << SHOW(y) << endl; 00030 cout << SHOW(fx(0.0)) << endl; 00031 cout << SHOW(fx(1.0)) << endl; 00032 00033 } 00034 00035 void test02() 00036 { 00037 pt2 p0(0.0,0.0); 00038 pt2 dp0(0.0,1.0); 00039 pt2 p1(1.0,0.0); 00040 pt2 dp1(0.0,0.0); 00041 00042 vecInterp2D1<pt2> fx(p0,dp0,p1,dp1); 00043 00044 cout << "enter t: "; 00045 double t; 00046 cin >> t; 00047 00048 pt2 y; 00049 fx(y,t); 00050 cout << SHOW(y) << endl; 00051 } 00052 00053 void display01() 00054 { 00055 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 00056 00057 gobj::global->draw(); 00058 00059 00060 glerrordisplay(); 00061 00062 glutSwapBuffers(); 00063 } 00064 00065 00066 00067 void keyboard01(unsigned char key, int x, int y) 00068 { 00069 switch (key) 00070 { 00071 case 27: 00072 exit(0); 00073 break; 00074 } 00075 } 00076 00077 00078 00079 void test03(int argc, char** argv) 00080 { 00081 glutInit(&argc,argv); 00082 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 00083 glutInitWindowSize(800,600); 00084 glutCreateWindow(""); 00085 glutDisplayFunc(display01); 00086 glutKeyboardFunc(keyboard01); 00087 00088 OpenGLinitialisation(); 00089 00090 glEnable(GL_DEPTH_TEST); 00091 glEnable(GL_CULL_FACE); 00092 glEnable(GL_NORMALIZE); 00093 00094 00095 xGraphics.set(); 00096 00097 gobjQuadric * q = new gobjQuadric(); 00098 q->radius = 0.05; 00099 q->slices=20; 00100 q->loops=6; 00101 gobjpush(q); 00102 00103 uint n=10; 00104 00105 double Pi=3.14159265; 00106 00107 gobjpush( new gobjglColor3ub(255,0,0) ); 00108 //gobjpush( new gobjglColor3ub(192,192,192) ); 00109 00110 vector<pt2> pt; 00111 vector<pt2> dpt; 00112 00113 double t=0.0; 00114 double dt = 2.0*Pi/(double)n; 00115 for (uint i=0; i<n; ++i) 00116 { 00117 pt.push_back( pt2(cos(t),sin(t)) ); 00118 dpt.push_back( pt2(-sin(t),cos(t)) ); 00119 t += dt; 00120 00121 gobjpush( new gobjMySphereDraw(pt[i],q) ); 00122 } 00123 00124 gobjpush( new gobjglColor3ub(205,133,63) ); 00125 00126 gobjpush( new gobjglPushAttrib(GL_LIGHTING) ); 00127 gobjpush( new gobjglDisable(GL_LIGHTING) ); 00128 00129 gobjMyCircle * c1 = new gobjMyCircle(); 00130 gobjpush( c1 ); 00131 gobjpush( new gobjMyCircleDraw( point3<double>(), *c1 ) ); 00132 00133 gobjpush( new gobjglPopAttrib() ); 00134 00135 00136 typedef point3<double> pt3; 00137 00138 vector<pt3> bluepoints; 00139 vector<pt3> greenpoints; 00140 uintc k=20; 00141 doublec dk = 1.0/((double)k-1); 00142 for (uint z=0; z<n; ++z) 00143 { 00144 vecInterp2D0<pt3> fx2(pt[z],pt[(z+1)%n]); 00145 vecInterp2D1<pt3> fx(pt[z],dpt[z],pt[(z+1)%n],dpt[(z+1)%n]); 00146 00147 for (uint i=0; i<k; ++i) 00148 bluepoints.push_back( fx2(i*dk) ); 00149 00150 for (uint i=0; i<k; ++i) 00151 greenpoints.push_back( fx(i*dk) ); 00152 } 00153 00154 00155 gobjpush( new gobjglPushAttrib(GL_LIGHTING) ); 00156 //gobjpush( new gobjglDisable(GL_LIGHTING) ); 00157 gobjpush( new gobjglColor3ub(0,255,0) ); 00158 00159 00160 gobjQuadric * q2 = new gobjQuadric(); 00161 q2->radius = 0.02; 00162 q2->slices=20; 00163 q2->loops=6; 00164 gobjpush(q2); 00165 for (uint i=0; i<greenpoints.size(); ++i) 00166 { gobjpush( new gobjMySphereDraw(greenpoints[i],q2) ); } 00167 gobjpush( new gobjglColor3ub(0,0,255) ); 00168 for (uint i=0; i<bluepoints.size(); ++i) 00169 { gobjpush( new gobjMySphereDraw(bluepoints[i],q2) ); } 00170 00171 00172 gobjpush( new gobjglPopAttrib() ); 00173 00174 00175 00176 // zpr::setViewVolumeFromXaxis(wx,wy,-2.0,10.0,-2.0,-1.0,1.0); 00177 00178 //zpr::init(); 00179 00180 zpr zz; 00181 00182 glutMainLoop(); 00183 } 00184 00185 00186 00187 00188 int main(int argc, char** argv) 00189 { 00190 commandline cmd(argc,argv); 00191 uint prog(0); 00192 cmd.mapvar(prog,"prog"); 00193 00194 switch (prog) 00195 { 00196 case 0: 00197 cout << "vecinterp - explores vector interpolation" << endl; 00198 cout << "./main prog=1 - test interpolation at end points" << endl; 00199 cout << "./main prog=2 - test first order interp." << endl; 00200 cout << "./main prog=3 - Visual comparision of linear and "; 00201 cout << "first order interpolation" << endl; 00202 00203 break; 00204 00205 case 1: test01(); break; 00206 case 2: test02(); break; 00207 case 3: test03(argc,argv); break; 00208 00209 default: cout << "error: No case handled." << endl; return 1; 00210 } 00211 00212 return 0; 00213 } 00214
1.5.8