[1869] | 1 | #include <GL/glut.h> |
---|
| 2 | #include "showroom.h" |
---|
| 3 | #include "3ds.h" |
---|
| 4 | #include "3dUnit.h" |
---|
| 5 | #include "3dStructs.h" |
---|
| 6 | |
---|
| 7 | /*########################### Showroom.cpp ########################### |
---|
| 8 | # Load the file "test.3ds" and lets you rotate and scale the model |
---|
| 9 | # Texturing not yet implemented |
---|
| 10 | # $Author: Johannes Bader |
---|
| 11 | # $Revision: 1.0 |
---|
| 12 | # $Date: 5.5.04 |
---|
| 13 | ###################################################################### */ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | int g_ViewMode = GL_LINE_STRIP; /* drawing mode */ |
---|
| 17 | bool g_bLighting = false; /* Turn lighting on initially */ |
---|
| 18 | |
---|
| 19 | static double alpha = 0; /* azimuth */ |
---|
| 20 | static double beta = 0; /* elevation */ |
---|
| 21 | static double zoom = 1; /* zoom */ |
---|
| 22 | |
---|
| 23 | C3dUnit TestModel( "test.3ds" ); /* Load the Test Model */ |
---|
| 24 | |
---|
| 25 | void init( void ) |
---|
| 26 | { |
---|
| 27 | glClearColor( 0.0, 0.0, 0.0, 0.0 ); |
---|
| 28 | glShadeModel( GL_FLAT ); |
---|
| 29 | /* Use the following function to display the properties of the model */ |
---|
| 30 | /* TestModel.PrintProperties(); */ |
---|
| 31 | |
---|
| 32 | /* Load the 3ds File */ |
---|
| 33 | TestModel.Import3ds(); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | int showroom(int argc, char** argv) |
---|
| 37 | { |
---|
| 38 | /* Nothing special about this function */ |
---|
| 39 | glutInit( &argc, argv ); |
---|
| 40 | glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB ); |
---|
| 41 | glutInitWindowSize( 500,500); |
---|
| 42 | glutInitWindowPosition( 100,100); |
---|
| 43 | glutCreateWindow( "Showroom" ); |
---|
| 44 | init(); |
---|
| 45 | glutDisplayFunc( display ); |
---|
| 46 | glutReshapeFunc( reshape ); |
---|
| 47 | glutKeyboardFunc( keyboard ); |
---|
| 48 | glutMainLoop(); |
---|
| 49 | return 0; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | void keyboard( unsigned char key, int x, int y ) |
---|
| 53 | { |
---|
| 54 | /* Use the following keys to control the Model */ |
---|
| 55 | switch( key ) { |
---|
| 56 | case 'a': |
---|
| 57 | alpha += 5; break; |
---|
| 58 | case 'd': |
---|
| 59 | alpha -= 5; break; |
---|
| 60 | case 'w': |
---|
| 61 | zoom = zoom*1.1; break; |
---|
| 62 | case 's': |
---|
| 63 | zoom = zoom/1.1; |
---|
| 64 | if( zoom <= 0.0 ) zoom = 0.001; break; |
---|
| 65 | case 'q': |
---|
| 66 | beta += 5; break; |
---|
| 67 | case 'e': |
---|
| 68 | beta -= 5; break; |
---|
| 69 | case 'y': |
---|
| 70 | if(g_ViewMode == GL_TRIANGLES) { // We our drawing mode is at triangles |
---|
| 71 | g_ViewMode = GL_LINE_STRIP; // Go to line stips |
---|
| 72 | } else { |
---|
| 73 | g_ViewMode = GL_TRIANGLES; // Go to triangles |
---|
| 74 | } |
---|
| 75 | break; |
---|
| 76 | } |
---|
| 77 | /* After changing the viewing postition -> redisplay */ |
---|
| 78 | glutPostRedisplay(); |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | void display( void ) |
---|
| 82 | { |
---|
| 83 | /* Standart */ |
---|
| 84 | glClear( GL_COLOR_BUFFER_BIT); |
---|
| 85 | glColor3f( 1.0, 1.0, 1.0 ); |
---|
| 86 | |
---|
| 87 | /* Rotate azimuth, elevation and scale */ |
---|
| 88 | glPushMatrix(); |
---|
| 89 | gluLookAt( 5, 0, 0, 0.0, 0.0, 0.0, 0.0, 1, 0.0 ); |
---|
| 90 | glRotatef( (GLfloat)beta, 0.0, 0.0, 1.0 ); |
---|
| 91 | glRotatef( (GLfloat)alpha, 0.0, 1.0, 0.0 ); |
---|
| 92 | glScalef( zoom,zoom,zoom); |
---|
| 93 | |
---|
| 94 | /* Use this function to draw a Unit with g_ViewMode */ |
---|
| 95 | TestModel.Draw( g_ViewMode ); |
---|
| 96 | |
---|
| 97 | glPopMatrix(); |
---|
| 98 | glutSwapBuffers(); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | void reshape( int w, int h ) |
---|
| 103 | { |
---|
| 104 | /* Standart */ |
---|
| 105 | glViewport( 0,0,(GLsizei) w, (GLsizei) h ); |
---|
| 106 | glMatrixMode( GL_PROJECTION ); |
---|
| 107 | glLoadIdentity(); |
---|
| 108 | glFrustum( -1.0,1.0,-1.0,1.0,1.5,20.0); |
---|
| 109 | glMatrixMode( GL_MODELVIEW); |
---|
| 110 | } |
---|