proj home

Files   Classes   Functions   Hierarchy  

zprtest Class Reference

Test zpr class. More...

#include <zprtest.h>

List of all members.

Public Member Functions

int test01 (int argc, char **argv)
 Display axes at the origin.
void test02 (int argc, char **argv)
 Extracting the frustrum from the projection matrix.
void test03 (int argc, char **argv)
 Changing OpenGL's projection and having the change read back into zpr.

Static Public Member Functions

static void keyboard (unsigned char key, int x, int y)
 Keyboard handler.
static void display ()
 Display test.


Detailed Description

Test zpr class.

Definition at line 12 of file zprtest.h.


Member Function Documentation

void zprtest::display (  )  [static]

Display test.

Definition at line 25 of file zprtest.cpp.

References glerrordisplay().

Referenced by test01(), test02(), and test03().

00026 {
00027   // Drawing a coordinate system with cone pointers
00028 
00029   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00030   glPushMatrix();
00031 
00032 glerrordisplay();
00033 
00034   glDisable(GL_LIGHTING);
00035   glBegin(GL_LINES);
00036     glColor3f(0,0,1);
00037     glVertex3f(0,0,0);
00038     glVertex3f(0,0,1);
00039     glColor3f(0,1,0);
00040     glVertex3f(0,0,0);
00041     glVertex3f(0,1,0);
00042     glColor3f(1,0,0);
00043     glVertex3f(0,0,0);
00044     glVertex3f(1,0,0);
00045   glEnd();
00046 
00047 glerrordisplay();
00048 
00049   glEnable(GL_LIGHTING);
00050   // glutSolidCone(base_radius,length,base_verticies,cone_axis_verticies)
00051 
00052   // The colors RGB correspont to the XYZ axes
00053 
00054   glPushMatrix();
00055   // First Translate the coordinate system
00056     glTranslatef(1,0,0);
00057     glColor3f(1,0,0);
00058 
00059       // Pointing along the z-axis
00060 
00061       // Rotation is counter clockwise in the plane with y normal
00062       //     This gets us pointing along the x-axis
00063     glRotatef(90,0,1,0);
00064 
00065       //glTranslatef(1,0,0);
00066     glutSolidCone(.2,1.0,10,5);
00067   glPopMatrix();
00068 
00069 glerrordisplay();
00070 
00071   glPushMatrix();
00072     glTranslatef(0,1,0);
00073     glColor3f(0,1,0);
00074     glRotatef(270,1,0,0);
00075     glutSolidCone(.2,1.0,10,5);
00076   glPopMatrix();
00077 
00078   glPushMatrix();
00079     // Already pointing along the z-axis
00080     glTranslatef(0,0,1);
00081     glColor3f(0,0,1);
00082     glutSolidCone(.2,1.0,10,5);
00083   glPopMatrix();
00084 
00085 glerrordisplay();
00086 
00087   glutSwapBuffers();
00088 
00089   glPopMatrix();
00090 }

void zprtest::keyboard ( unsigned char  key,
int  x,
int  y 
) [static]

Keyboard handler.

Definition at line 92 of file zprtest.cpp.

Referenced by test01(), test02(), and test03().

00093 {
00094   switch (key)
00095   {
00096     case 27:
00097       exit(0);
00098       break;
00099   }
00100 }

int zprtest::test01 ( int  argc,
char **  argv 
)

Display axes at the origin.

Definition at line 126 of file zprtest.cpp.

References display(), keyboard(), and zpr::printInfo().

00127 {
00128   glutInit(&argc, argv);
00129   glutInitDisplayMode
00130     (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00131   int wx=800; 
00132   int wy=600;
00133   glutInitWindowSize(wx,wy);
00134   glutCreateWindow("Coordinate Axes");
00135 
00136   zpr zz;
00137 
00138   cout << "After construction." << endl;
00139   zz.printInfo();
00140 
00141   // Callbacks
00142 
00143   glutKeyboardFunc(zprtest::keyboard);
00144   glutDisplayFunc(zprtest::display);
00145   //glutIdleFunc(zpreval);
00146 
00147   glEnable(GL_NORMALIZE);
00148 
00149 //  glScalef(0.25,0.25,0.25);
00150 /*
00151 
00152   glMatrixMode(GL_PROJECTION);
00153   glLoadIdentity();
00154   //gluPerspective(65, (GLdouble)wx/(GLdouble)wy, .25, 10); 
00155  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
00156 
00157   // COP - Center Of Projection
00158   // VRP - View Reference Point
00159   // VUP - View UP
00160   glMatrixMode(GL_MODELVIEW);
00161   glLoadIdentity();
00162   gluLookAt(
00163     0.0,0.0,0.0, 
00164     0.0,0.0,8.0, 
00165     0.0,1.0,0.0); 
00166 
00167   zz.update();
00168 */
00169 
00170   OpenGLinitialisation();
00171 
00172   // Never returns
00173   glutMainLoop();
00174 
00175   return 0;
00176 }

void zprtest::test02 ( int  argc,
char **  argv 
)

Extracting the frustrum from the projection matrix.

Definition at line 180 of file zprtest.cpp.

References zprGLmatrix::access(), display(), keyboard(), and SHOW.

00181 {
00182   cout << "Starting up OpenGL." << endl;
00183 
00184   glutInit(&argc, argv);
00185   glutInitDisplayMode
00186     (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00187   int wx=800; 
00188   int wy=600;
00189   glutInitWindowSize(wx,wy);
00190   glutCreateWindow("Coordinate Axes");
00191   zpr zz;
00192   
00193   //zpr::init(wx,wy);
00194   glutKeyboardFunc(zprtest::keyboard);
00195   glutDisplayFunc(zprtest::display);
00196 
00197 
00198   GLdouble pmatrix[16];
00199 
00200   glMatrixMode(GL_PROJECTION);
00201   glLoadIdentity();
00202   glGetDoublev(GL_PROJECTION_MATRIX,pmatrix);
00203   cout << "The identity matrix should be printed." << endl;
00204   GLdouble * p2 = & pmatrix[0];
00205   zprGLmatrix(p2).print();
00206   cout << endl;
00207 
00208   GLdouble left=-1.0;
00209   GLdouble right=1.0;
00210   GLdouble bottom=-0.5;
00211   GLdouble top=1.5;
00212   GLdouble zNear=1.0;
00213   GLdouble zFar=4.2;
00214   cout << SHOW(left) << endl;
00215   cout << SHOW(right) << endl;
00216   cout << SHOW(bottom) << endl;
00217   cout << SHOW(top) << endl;
00218   cout << SHOW(zNear) << endl;
00219   cout << SHOW(zFar) << endl;
00220   glFrustum(left,right,bottom,top,zNear,zFar);
00221 
00222   glGetDoublev(GL_PROJECTION_MATRIX,pmatrix);
00223   cout << "Calculate the view frustrum with OpenGL" << endl;
00224   zprGLmatrix(p2).print();
00225   cout << endl << endl;
00226   zprGLmatrix(p2).printTranspose();
00227   cout << endl;
00228 
00229   zprGLmatrix mat(p2);
00230 
00231   GLdouble a[6];
00232   a[0] = mat.access(0,0);
00233   a[1] = mat.access(1,1);
00234   a[2] = mat.access(0,2);
00235   a[3] = mat.access(1,2);
00236   a[4] = mat.access(2,2);
00237   a[5] = mat.access(2,3);
00238   cout << SHOW(a[0]) << endl;
00239   cout << SHOW(a[1]) << endl;
00240   cout << SHOW(a[2]) << endl;
00241   cout << SHOW(a[3]) << endl;
00242   cout << SHOW(a[4]) << endl;
00243   cout << SHOW(a[5]) << endl;
00244 
00245   GLdouble c0 = (1.0-a[4])/(1.0+a[4]);
00246   cout << SHOW(c0) << endl;
00247   GLdouble z0 = a[5]*(c0+1.0)*-0.5/c0;
00248   cout << SHOW(z0) << endl;
00249   GLdouble z1 = -c0*z0;
00250   cout << SHOW(z1) << endl;
00251   GLdouble x0 = z0*(a[2]-1.0)/a[0];
00252   cout << SHOW(x0) << endl;
00253   GLdouble x1 = (z0*2.0+a[0]*x0)/a[0];
00254   cout << SHOW(x1) << endl;
00255   GLdouble y0 = z0*(a[3]-1.0)/a[1];
00256   cout << SHOW(y0) << endl;
00257   GLdouble y1 = (z0*2.0+a[1]*y0)/a[1];
00258   cout << SHOW(y1) << endl;
00259 }

void zprtest::test03 ( int  argc,
char **  argv 
)

Changing OpenGL's projection and having the change read back into zpr.

Definition at line 262 of file zprtest.cpp.

References display(), keyboard(), zpr::printInfo(), zpr::readProjection(), and SHOW.

00263 {
00264   cout << "Starting up OpenGL." << endl;
00265 
00266   glutInit(&argc, argv);
00267   glutInitDisplayMode
00268     (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
00269   int wx=800; 
00270   int wy=600;
00271   glutInitWindowSize(wx,wy);
00272   glutCreateWindow("Coordinate Axes");
00273 
00274   zpr zz; 
00275   //zpr::init(wx,wy);
00276 
00277   glutKeyboardFunc(zprtest::keyboard);
00278   glutDisplayFunc(zprtest::display);
00279 
00280 
00281 
00282   cout << "printing out zpr's state." << endl;
00283   zz.printInfo();
00284 /*
00285   cout << "zprtest03.cpp glFrustum(left,right,bottom,top,zNear,zFar)" << endl;
00286   cout << SHOW(left) << endl;
00287   cout << SHOW(right) << endl;
00288   cout << SHOW(bottom) << endl;
00289   cout << SHOW(top) << endl;
00290   cout << SHOW(zNear) << endl;
00291   cout << SHOW(zFar) << endl;
00292 */
00293 
00294 /*
00295   cout << endl;
00296   cout << "zpr's current frustrum" << endl;
00297   zpr::printInfo();
00298 */
00299   cout << endl;
00300 
00301   printMatrixMode();
00302 
00303   cout << "Changing OpenGL's frustrum" << endl;
00304 
00305   {
00306     myglPushMatrixMode tmp;
00307 
00308     glMatrixMode(GL_PROJECTION);
00309     glLoadIdentity();
00310     GLdouble x0=-1.0;
00311     GLdouble x1=1.0;
00312     GLdouble y0=-0.5;
00313     GLdouble y1=1.5;
00314     GLdouble z0=1.0;
00315     GLdouble z1=4.2;
00316     glFrustum(x0,x1,y0,y1,z0,z1);
00317     cout << SHOW(x0) << endl;
00318     cout << SHOW(x1) << endl;
00319     cout << SHOW(y0) << endl;
00320     cout << SHOW(y1) << endl;
00321     cout << SHOW(z0) << endl;
00322     cout << SHOW(z1) << endl;
00323     cout << "glFrustum(x0,x1,y0,y1,z0,z1);" << endl;
00324 
00325     cout << "Reading OpenGL's projection matrix." << endl;
00326 
00327     zz.readProjection();
00328   
00329     printMatrixMode();
00330   }
00331   cout << endl;
00332 
00333   printMatrixMode();
00334  
00335   cout << "zpr's current state" << endl;
00336   zz.printInfo();
00337   cout << endl;
00338 
00339 }


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:50:26 2011 for Chelton Evans Source by  doxygen 1.5.8