home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1996, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* lookat.c - use input from the keyboard to control the viewpoint
- *
- * F1 key - print help information
- * Left Arrow Key - move the reference point to the left
- * Right Arrow Key - move the reference point to the right
- * Up Arrow Key - move the reference point up
- * Down Arrow Key - move the reference point down
- * Escape key - exit the program
- */
-
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
- #include <math.h>
- #include <stdio.h> /* for printf */
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid keyboard( GLubyte, GLint, GLint );
- GLvoid specialkeys( GLint, GLint, GLint );
-
- void printHelp( char * );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* Global Variables */
-
- static GLdouble xRef = 0.0, yRef = 0.0;
-
- static char *progname;
-
- GLvoid
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet( GLUT_SCREEN_WIDTH );
- height = glutGet( GLUT_SCREEN_HEIGHT );
- glutInitWindowPosition( 4, height / 4 );
- glutInitWindowSize( (width / 2) - 4, height / 2 );
- glutInitDisplayMode( GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutSpecialFunc( specialkeys );
- glutReshapeFunc( reshape );
- glutDisplayFunc( drawScene );
-
- progname = argv[0];
- printHelp( progname );
-
- glutMainLoop();
- }
-
- void
- printHelp( char *progname )
- {
- fprintf(stdout, "\n%s - uses keyboard input to control the "
- "location of the reference point point\n\n"
- "F1 Key - print Help information\n"
- "Left Arrow Key - move reference point to the left\n"
- "Right Arrow Key - move reference point to the right\n"
- "Up Arrow Key - move reference point up\n"
- "Down Arrow Key - move reference point down\n"
- "Escape Key - exit the program\n\n",
- progname);
- }
-
- GLvoid
- initgfx( GLvoid )
- {
- glClearColor( 0.0, 0.0, 0.0, 1.0 );
- glShadeModel( GL_FLAT );
- glEnable( GL_DEPTH_TEST );
- }
-
- GLvoid
- reshape( GLsizei width, GLsizei height )
- {
- GLdouble aspect;
-
- glViewport( 0, 0, width, height );
-
- aspect = (GLdouble) width / (GLdouble) height;
-
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- gluPerspective( 45.0, aspect, 1.0, 20.0 );
- glMatrixMode( GL_MODELVIEW );
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case KEY_ESC: /* Exit when the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- specialkeys( GLint key, GLint x, GLint y )
- {
- switch (key) {
- case GLUT_KEY_F1: /* print Help */
- printHelp( progname );
- break;
-
- case GLUT_KEY_LEFT: /* move reference point to the left */
- xRef -= 0.5;
- if (xRef < -4.0) xRef = -4.0;
- glutPostRedisplay();
- break;
-
- case GLUT_KEY_RIGHT: /* move reference point to the right */
- xRef += 0.5;
- if (xRef > 4.0) xRef = 4.0;
- glutPostRedisplay();
- break;
-
- case GLUT_KEY_UP: /* move reference point up */
- yRef += 0.5;
- if (yRef > 3.0) yRef = 3.0;
- glutPostRedisplay();
- break;
-
- case GLUT_KEY_DOWN: /* move reference point down */
- yRef -= 0.5;
- if (yRef < -3.0) yRef = -3.0;
- glutPostRedisplay();
- break;
- }
- }
-
- GLvoid
- drawScene( GLvoid )
- {
- static GLfloat upperArmColor[] = { 1.0, 0.0, 0.0 };
- static GLfloat lowerArmColor[] = { 0.8, 0.5, 0.5 };
-
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
-
- glPushMatrix();
-
- /* Move the reference point */
- gluLookAt( 0.0, 0.0, 8.0, xRef, yRef, 0.0, 0.0, 1.0, 0.0 );
-
- XYaxes();
-
- /* Draw the shoulder at the new origin */
- glTranslatef( 1.0, 0.0, 0.0 );
- glColor3fv( upperArmColor );
- WireBox( 2.0, 0.4, 1.0 );
-
- /* Draw the lower arm at the end of the upper arm and
- * rotate it 45 degrees */
- glTranslatef( 1.0, 0.0, 0.0 );
- glRotatef( 45.0, 0.0, 0.0, 1.0 );
- glTranslatef( 1.0, 0.0, 0.0 );
- glColor3fv( lowerArmColor );
- WireBox( 2.0, 0.4, 1.0 );
- glPopMatrix();
-
- glutSwapBuffers();
- }
-