<html> <head> </head><body><pre><html> <head> </head><body><pre>&lt;html&gt; &lt;head&gt; &lt;/head&gt;&lt;body&gt;&lt;pre&gt;&amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&amp;lt;pre&amp;gt;&amp;amp;lt;html&amp;amp;gt; &amp;amp;lt;head&amp;amp;gt; &amp;amp;lt;/head&amp;amp;gt;&amp;amp;lt;body&amp;amp;gt;&amp;amp;lt;pre&amp;amp;gt;/* ** File: box0.c ** Description: Renders a 3D image of x, y, z axes. ** Rev: 1.0 ** Created: 06 August 2001 ** Last Update: 23 September 2002 ** Author: Fran Soddell ** Email: F.Soddell@bendigo.latrobe.edu.au **/ #include &amp;amp;amp;lt;GL/glut.h&amp;amp;amp;gt; #include &amp;amp;amp;lt;stdio.h&amp;amp;amp;gt; #define TRUE 1 #define FALSE 0 /* ** manage 3D */ enum {x,y,z}; /* ** window management */ int width=250; int height=250; int xPosition=50; int yPosition=70; /* ** manage view */ GLint xOrigin; GLint yOrigin; /* ** manage world projection */ enum {xLeft,xRight,yBottom,yTop,zNear,zFar}; GLdouble world[]={ -2.0,2.0,-2.0,2.0,0.1,1000 }; GLdouble fovy =90.0; GLdouble aspect =1.0; int perspective =TRUE; /* ** manage camera */ GLdouble eye[]={ 2.0,2.0,2.0 }; GLdouble centre[]={ 0.0,0.0,0.0 }; GLdouble up[]={ 0.0,1.0,0.0 }; /* ** manage colour */ #define NUM_COLOURS 8 #define ALPHA 0.0 enum {red,green,blue, yellow,magenta,cyan, white,black}; typedef GLfloat colourType[3]; colourType colour[NUM_COLOURS]={ {1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}, {1.0,1.0,0.0},{1.0,0.0,1.0},{0.0,1.0,1.0}, {1.0,1.0,1.0},{0.0,0.0,0.0} }; /* ** *********************************************************** */ void renderAxis(double length){ glPushMatrix(); glBegin(GL_LINES); glVertex3d(0,0,0); glVertex3d(0,0,length); glEnd(); glTranslated(0,0,length-0.2); glutWireCone(0.04,0.2,12,9); glPopMatrix(); } void axes(){ glLineWidth(1); glColor3fv(colour[red]); /* z-axis */ renderAxis(1.5); glPushMatrix(); /* y-axis */ glRotated(90,0,1.0,0); glColor3fv(colour[green]); renderAxis(1.5); /* x-axis */ glRotated(-90,1,0,0); glColor3fv(colour[blue]); renderAxis(1.5); glPopMatrix(); } void setCamera(){ glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(eye[x],eye[y],eye[z], centre[x],centre[y],centre[z], up[x],up[y],up[z]); } void setProjection(){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(!perspective) glOrtho(world[xLeft], world[xRight], world[yBottom],world[yTop], world[zNear], world[zFar]); else gluPerspective(fovy,1,world[zNear],world[zFar]); } void display(){ /* ** Clear the window with the background colour before ** (re)rendering. */ glClear(GL_COLOR_BUFFER_BIT); setCamera(); axes(); glFlush(); } void reshapeWindow(int w, int h){ int yOrigin=0, xOrigin=0; /* ** When window is resized, retain ** image proportions AND ensure ** origin remains centred. */ if(w&amp;amp;amp;gt;h){ yOrigin=(h-w)/2; h=w; } else{ xOrigin=(w-h)/2; w=h; } glViewport(xOrigin,yOrigin,(GLsizei)w,(GLsizei)h); setProjection(); } void keyboard(unsigned char key,int xMouse,int yMouse){ switch(key){ case 27 : exit(0); case &amp;#39;p&amp;#39;: perspective=!perspective; setProjection(); break; case &amp;#39;f&amp;#39;: if(fovy&amp;amp;amp;lt;180) fovy+=0.5; setProjection(); break; case &amp;#39;F&amp;#39;: if(fovy&amp;amp;amp;gt;0) fovy-=0.5; setProjection(); break; } glutPostRedisplay(); } void setUpGLUT(int argc,char ** argv){ glutInit(&amp;amp;amp;amp;argc,argv); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); glutInitWindowSize(width,height); glutInitWindowPosition(xPosition,yPosition); glutCreateWindow(&amp;amp;amp;quot;Box - Polygonal Mesh&amp;amp;amp;quot;); /* ** Register callbacks. */ glutDisplayFunc(display); glutReshapeFunc(reshapeWindow); glutKeyboardFunc(keyboard); } void initialiseGL(){ glClearColor(1,1,1,ALPHA); } int main(int argc,char ** argv){ setUpGLUT(argc,argv); initialiseGL(); /* ** Display window and ** enter the GLUT event processing loop. */ glutMainLoop(); return 0; } &amp;amp;lt;/pre&amp;amp;gt;&amp;amp;lt;/body&amp;amp;gt;&amp;amp;lt;/html&amp;amp;gt;&amp;lt;/pre&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;</pre></body></html></pre></body></html>