![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsDerivedGLUTCallbackFns.cpp 00003 00004 See TAPsGLUTCallbackFns.hpp 00005 00006 SUKITTI PUNAK (08/17/2005) 00007 UPDATE (08/30/2005) 00008 ******************************************************************************/ 00009 #include "TAPsDerivedGLUTCallbackFns.hpp" 00010 // Using Inclusion Model (i.e. definitions are included in declarations) 00011 // (this name.cpp is included in name.hpp) 00012 // Each friend is defined directly inside its declaration. 00013 00014 BEGIN_NAMESPACE_TAPs__OpenGL 00015 //============================================================================= 00016 // Constructor(s) and Destructor 00017 //----------------------------------------------------------------------------- 00018 DerivedGLUTCallbackFns::DerivedGLUTCallbackFns () 00019 {} 00020 //----------------------------------------------------------------------------- 00021 DerivedGLUTCallbackFns::~DerivedGLUTCallbackFns () 00022 {} 00023 //----------------------------------------------------------------------------- 00024 //============================================================================= 00025 // DisplayFn 00026 //----------------------------------------------------------------------------- 00027 void DerivedGLUTCallbackFns::DisplayFn () 00028 { 00029 glClearColor( 1, 1, 1, 1 ); 00030 static const GLfloat light_model_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f }; 00031 glLightModelfv( GL_LIGHT_MODEL_AMBIENT, light_model_ambient ); 00032 TAPs::OpenGL::Fn::InitializeLight( GL_LIGHT0, 00033 0.3f, 0.3f, 0.3f, 1.0f, // ambient 00034 0.4f, 0.45f, 0.4f, 0.9f, // diffuse 00035 0.5f, 0.5f, 1.0f, 0.5f, // specular 00036 0.0f, 0.4f, 1.0f, 0.0f // position 00037 ); 00038 Material m; 00039 m.SetMaterial( Enum::METAL_SILVER ); 00040 m.ApplyMaterial( Enum::FRONT ); 00041 glEnable( GL_DEPTH_TEST ); 00042 glEnable( GL_LIGHTING ); 00043 //---------------------------------------------------------------- 00044 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 00045 glRotatef( 0.3, 1, 0, 0 ); 00046 glRotatef( 0.6, 0, 1, 0 ); 00047 glRotatef( 0.9, 0, 0, 1 ); 00048 glutSolidCube( 50 ); 00049 glutPostRedisplay(); 00050 glutSwapBuffers(); 00051 } 00052 //----------------------------------------------------------------------------- 00053 //============================================================================= 00054 // ReshapeFn 00055 //----------------------------------------------------------------------------- 00056 void DerivedGLUTCallbackFns::ReshapeFn ( int width, int height ) 00057 { 00058 /* 00059 static const float K_FOV_Y = 40; 00060 static const float K_CANONICAL_SPHERE_RADIUS = sqrt( 3.0f ); 00061 static const float K_PI = 3.1415926535897932384626433832795; 00062 //------------------------------------------------------------------- 00063 glViewport( 0, 0, static_cast<GLsizei>(width), static_cast<GLsizei>(height) ); 00064 //------------------------------------------------------------------- 00065 // Compute the viewing parameters based on a fixed fov and viewing 00066 // sphere enclosing a canonical box centered at the origin 00067 //T nearDist = K_CANONICAL_SPHERE_RADIUS / tan( (K_FOV_Y/2.0) * K_PI / 180.0 ); 00068 //T farDist = nearDist + 2.0 * K_CANONICAL_SPHERE_RADIUS; 00069 float nearDist = 1; 00070 float farDist = 100; 00071 //std::cout << "nearDist: " << nearDist << " farDist: " << farDist << std::endl; 00072 float aspect = static_cast<float>(width) / static_cast<float>(height); 00073 //------------------------------------------------------------------- 00074 glMatrixMode( GL_PROJECTION ); 00075 glLoadIdentity(); 00076 gluPerspective( K_FOV_Y, aspect, nearDist, farDist ); 00077 */ 00078 00079 glViewport( 0, 0, width, height ); 00080 glMatrixMode( GL_PROJECTION ); 00081 glLoadIdentity(); 00082 gluPerspective( 45.0, (float)width / (float)height, 0.1, 1000.0 ); 00083 glMatrixMode( GL_MODELVIEW ); 00084 glLoadIdentity(); 00085 gluLookAt( 00086 0, 0, 200, // eye position 00087 0, 0, 0, // look at 00088 0, 1, 0 // up vector 00089 ); 00090 00091 } 00092 //----------------------------------------------------------------------------- 00093 //============================================================================= 00094 // KeyboardFn 00095 //----------------------------------------------------------------------------- 00096 void DerivedGLUTCallbackFns::KeyboardFn ( unsigned char key, int x, int y ) 00097 { 00098 //---------------------------------------------------------------- 00099 switch ( key ) { 00100 case 'q': 00101 case 'Q': 00102 case 27: // ESC for exit the program 00103 exit( EXIT_SUCCESS ); 00104 break; 00105 } 00106 //---------------------------------------------------------------- 00107 //glutPostRedisplay(); 00108 //---------------------------------------------------------------- 00109 } 00110 //----------------------------------------------------------------------------- 00111 //============================================================================= 00112 // SpecialFn 00113 //----------------------------------------------------------------------------- 00114 void DerivedGLUTCallbackFns::SpecialFn ( int key, int x, int y ) 00115 { 00116 //---------------------------------------------------------------- 00117 switch ( key ) { 00118 case GLUT_KEY_F1: 00119 break; 00120 case GLUT_KEY_UP: 00121 break; 00122 case GLUT_KEY_DOWN: 00123 break; 00124 case GLUT_KEY_LEFT: 00125 break; 00126 case GLUT_KEY_RIGHT: 00127 break; 00128 } 00129 //---------------------------------------------------------------- 00130 //glutPostRedisplay(); 00131 //---------------------------------------------------------------- 00132 } 00133 //----------------------------------------------------------------------------- 00134 //============================================================================= 00135 // MouseFn 00136 //----------------------------------------------------------------------------- 00137 void DerivedGLUTCallbackFns::MouseFn ( int button, int state, int x, int y ) 00138 { 00139 //---------------------------------------------------------------- 00140 if ( state == GLUT_DOWN ) { 00141 //------------------------------------------------------ 00142 if ( button == GLUT_LEFT_BUTTON ) { 00143 } 00144 //------------------------------------------------------ 00145 else if ( button == GLUT_MIDDLE_BUTTON ) { 00146 } 00147 //------------------------------------------------------ 00148 else if ( button == GLUT_RIGHT_BUTTON ) { 00149 } 00150 } 00151 else if ( state == GLUT_UP ) { 00152 //------------------------------------------------------ 00153 if ( button == GLUT_LEFT_BUTTON ) { 00154 } 00155 //------------------------------------------------------ 00156 else if ( button == GLUT_MIDDLE_BUTTON ) { 00157 } 00158 //------------------------------------------------------ 00159 else if ( button == GLUT_RIGHT_BUTTON ) { 00160 } 00161 } 00162 //---------------------------------------------------------------- 00163 } 00164 //----------------------------------------------------------------------------- 00165 //============================================================================= 00166 // MotionFn 00167 //----------------------------------------------------------------------------- 00168 void DerivedGLUTCallbackFns::MotionFn ( int x, int y ) 00169 { 00170 //---------------------------------------------------------------- 00171 //---------------------------------------------------------------- 00172 } 00173 //----------------------------------------------------------------------------- 00174 //============================================================================= 00175 // IdleFn 00176 //----------------------------------------------------------------------------- 00177 void DerivedGLUTCallbackFns::IdleFn () 00178 { 00179 //---------------------------------------------------------------- 00180 //---------------------------------------------------------------- 00181 } 00182 //----------------------------------------------------------------------------- 00183 //============================================================================= 00184 // Initialize 00185 //----------------------------------------------------------------------------- 00186 void DerivedGLUTCallbackFns::Initialize () 00187 { 00188 //---------------------------------------------------------------- 00189 //---------------------------------------------------------------- 00190 } 00191 //----------------------------------------------------------------------------- 00192 //============================================================================= 00193 END_NAMESPACE_TAPs__OpenGL 00194 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00195 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8