#include #include "showroom.h" #include "3ds.h" #include "3dUnit.h" #include "3dStructs.h" /*########################### Showroom.cpp ########################### # Load the file "test.3ds" and lets you rotate and scale the model # Texturing not yet implemented # $Author: Johannes Bader # $Revision: 1.0 # $Date: 5.5.04 ###################################################################### */ int g_ViewMode = GL_LINE_STRIP; /* drawing mode */ bool g_bLighting = false; /* Turn lighting on initially */ static double alpha = 0; /* azimuth */ static double beta = 0; /* elevation */ static double zoom = 1; /* zoom */ C3dUnit TestModel( "test.3ds" ); /* Load the Test Model */ void init( void ) { glClearColor( 0.0, 0.0, 0.0, 0.0 ); glShadeModel( GL_FLAT ); /* Use the following function to display the properties of the model */ /* TestModel.PrintProperties(); */ /* Load the 3ds File */ TestModel.Import3ds(); } int showroom(int argc, char** argv) { /* Nothing special about this function */ glutInit( &argc, argv ); glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB ); glutInitWindowSize( 500,500); glutInitWindowPosition( 100,100); glutCreateWindow( "Showroom" ); init(); glutDisplayFunc( display ); glutReshapeFunc( reshape ); glutKeyboardFunc( keyboard ); glutMainLoop(); return 0; } void keyboard( unsigned char key, int x, int y ) { /* Use the following keys to control the Model */ switch( key ) { case 'a': alpha += 5; break; case 'd': alpha -= 5; break; case 'w': zoom = zoom*1.1; break; case 's': zoom = zoom/1.1; if( zoom <= 0.0 ) zoom = 0.001; break; case 'q': beta += 5; break; case 'e': beta -= 5; break; case 'y': if(g_ViewMode == GL_TRIANGLES) { // We our drawing mode is at triangles g_ViewMode = GL_LINE_STRIP; // Go to line stips } else { g_ViewMode = GL_TRIANGLES; // Go to triangles } break; } /* After changing the viewing postition -> redisplay */ glutPostRedisplay(); } void display( void ) { /* Standart */ glClear( GL_COLOR_BUFFER_BIT); glColor3f( 1.0, 1.0, 1.0 ); /* Rotate azimuth, elevation and scale */ glPushMatrix(); gluLookAt( 5, 0, 0, 0.0, 0.0, 0.0, 0.0, 1, 0.0 ); glRotatef( (GLfloat)beta, 0.0, 0.0, 1.0 ); glRotatef( (GLfloat)alpha, 0.0, 1.0, 0.0 ); glScalef( zoom,zoom,zoom); /* Use this function to draw a Unit with g_ViewMode */ TestModel.Draw( g_ViewMode ); glPopMatrix(); glutSwapBuffers(); } void reshape( int w, int h ) { /* Standart */ glViewport( 0,0,(GLsizei) w, (GLsizei) h ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glFrustum( -1.0,1.0,-1.0,1.0,1.5,20.0); glMatrixMode( GL_MODELVIEW); } int main(int argc, char** argv ) { showroom(argc, argv); return 0; }