#include #include "camera_gl.h" #include static GLint Height; /*height of window*/ static Camera_GL *TheCamera; static Point3D Pyramid[] = {{0.0,0.0,0.0},{10.0,0.0,0.0}, {10.0,10.0,0.0},{0.0,10.0,0.0}, {5.0,5.0,40.0}}; /*read in command line argument*/ int Eye; /*- for L, + for R*/ float VPDistance; /*view plane distance*/ /*preset half inter-pupilary distance*/ #define HIPD 1.5 static void displayPyramid(void) { /*base*/ glBegin(GL_POLYGON); glColor3f(0.0,0.0,0.0); glVertex3f(Pyramid[0].x,Pyramid[0].y,Pyramid[0].z); glVertex3f(Pyramid[3].x,Pyramid[3].y,Pyramid[3].z); glVertex3f(Pyramid[2].x,Pyramid[2].y,Pyramid[2].z); glVertex3f(Pyramid[1].x,Pyramid[1].y,Pyramid[1].z); glEnd(); /*front*/ glBegin(GL_POLYGON); glColor3f(1.0,0.0,0.0); glVertex3f(Pyramid[0].x,Pyramid[0].y,Pyramid[0].z); glVertex3f(Pyramid[1].x,Pyramid[1].y,Pyramid[1].z); glVertex3f(Pyramid[4].x,Pyramid[4].y,Pyramid[4].z); glEnd(); /*right*/ glBegin(GL_POLYGON); glColor3f(0.0,1.0,0.0); glVertex3f(Pyramid[1].x,Pyramid[1].y,Pyramid[1].z); glVertex3f(Pyramid[2].x,Pyramid[2].y,Pyramid[2].z); glVertex3f(Pyramid[4].x,Pyramid[4].y,Pyramid[4].z); glEnd(); /*back*/ glBegin(GL_POLYGON); glColor3f(0.0,0.0,1.0); glVertex3f(Pyramid[4].x,Pyramid[4].y,Pyramid[4].z); glVertex3f(Pyramid[2].x,Pyramid[2].y,Pyramid[2].z); glVertex3f(Pyramid[3].x,Pyramid[3].y,Pyramid[3].z); glEnd(); /*left*/ glBegin(GL_POLYGON); glColor3f(1.0,1.0,0.0); glVertex3f(Pyramid[0].x,Pyramid[0].y,Pyramid[0].z); glVertex3f(Pyramid[4].x,Pyramid[4].y,Pyramid[4].z); glVertex3f(Pyramid[3].x,Pyramid[3].y,Pyramid[3].z); glEnd(); } static void display () { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); displayPyramid(); glFlush(); } static void reshape(int width, int height) { setCOP_GL(TheCamera,(float)(HIPD*Eye),0.0,0.0); setVPDistance_GL(TheCamera,VPDistance); setClipPlanes_GL(TheCamera,0.1,200.0); setVPWindow_GL(TheCamera,-10.0,10.0,-10.0,10.0); clickProject_GL(TheCamera); glViewport (0, 0, width, height); /*define the viewport*/ } static void initialise(void) { /*GL_FLAT or GL_SMOOTH*/ glShadeModel(GL_FLAT); /*set the background (clear) Color to white*/ glClearColor(1.0,1.0,1.0,0.0); glEnable(GL_DEPTH_TEST); /*set the depth buffer for clearing*/ glClearDepth(1.0); /*initialise the camera*/ TheCamera = newCamera_GL(); setVRP_GL(TheCamera,5.0,5.0,100.0); setVPN_GL(TheCamera,0.0,0.0,-1.0); setVUV_GL(TheCamera,0.0,1.0,0.0); clickView_GL(TheCamera); } int main(int argc, char** argv) { int window; glutInit(&argc,argv); if(argc != 3){ printf("stereo eye(-1 or 1) vpdistance\n"); exit(0); } Eye = atoi(argv[1]); VPDistance = (float)atof(argv[2]); /*record the window height*/ Height = 200; glutInitWindowSize(Height,Height); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH); if(Eye < 0) window = glutCreateWindow("Left"); else if(Eye == 0) window = glutCreateWindow("Mono"); else window = glutCreateWindow("Right"); glutSetWindow(window); initialise(); /*register callbacks*/ glutDisplayFunc(display); /*display function*/ glutReshapeFunc(reshape); glutMainLoop(); }