/* Demo of unprojection and the mouse callback. Implemented Fall 2003 Scott D. Anderson */ #include #include #include twTriple A = {0,0,0}; twTriple B = {0,0,0}; void display(void) { twDisplayInit(); twCamera(); twTriple sideColor = {0.8,0.2,0.3}; twTriple roofColor = {0.4,0.4,0.2}; twDrawBarn(sideColor,roofColor); glBegin{GL_LINES}; twColorName(TW_YELLOW); glVertex3fv(A); twColorName(TW_MAGENTA); glVertex3fv(B); glEnd(); glFlush(); glutSwapBuffers(); } void myMouseClick(int button, int state, int x, int y) { twTriple win = {x,y}; win[2] = 0; // near plane twUnProject(A,win); win[2] = 1; // far plane twUnProject(B,win); glutPostRedisplay(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(500,500); glutCreateWindow(argv[0]); glutDisplayFunc(display); glutDisplayFunc(myMouseClick); twVertexArray(barn, 10); // determines dimensions of barn twMainInit(); glutMainLoop(); return 0; }