|
From: andrew7 <bd...@us...> - 2006-11-30 01:01:20
|
Update of /cvsroot/smartwin/SmartWin/tests/OpenGLSample1 In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv30879/tests/OpenGLSample1 Modified Files: Main.cpp Log Message: Add arrows to move around. (Just a bit of fun) Index: Main.cpp =================================================================== RCS file: /cvsroot/smartwin/SmartWin/tests/OpenGLSample1/Main.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Main.cpp 5 May 2006 17:21:44 -0000 1.4 +++ Main.cpp 30 Nov 2006 01:01:17 -0000 1.5 @@ -21,8 +21,21 @@ PAINTSTRUCT ps; HDC hDC; HWND hWnd; + float xoff, yoff, zoff; public: + + OpenGLWin() + { + homePosition(); + } + + void homePosition() + { + xoff = 0.0f; yoff = 0.0f; zoff = -5.0f; + } + + void init() { Seed cs; @@ -38,6 +51,9 @@ onPainting( & OpenGLWin::painting ); onClosing( & OpenGLWin::willClose ); setBounds( 100, 100, 700, 600 ); + + onKeyPressed( & OpenGLWin::KeyPressed ); + updateWidget(); } @@ -102,7 +118,7 @@ 30.0, // Field-of-view angle gldAspect, // Aspect ratio of view volume 1.0, // Distance to near clipping plane - 10.0 ); // Distance to far clipping plane + 100.0 ); // Distance to far clipping plane glViewport( 0, 0, glnWidth, glnHeight ); wglMakeCurrent( NULL, NULL ); ReleaseDC( hWnd, hDC ); @@ -179,7 +195,7 @@ glLoadIdentity(); // move the viewpoint out to where we can see everything - glTranslatef( 0.0f, 0.0f, - 5.0f ); + glTranslatef( xoff, yoff, zoff ); // 0, 0, -5.0 // Draw a large triangle out of three smaller triangles // sharing common vertex colors @@ -216,6 +232,49 @@ // Flush the drawing pipeline since it's single buffered glFlush (); } + + // IN: virtkey is a virtual key, which includes the special keys. + bool KeyPressed( int virtkey ) + { + float adj = 0.2f; + switch ( virtkey ) + { + case VK_SHIFT : return false; + + case VK_HOME : + case VK_ESCAPE : homePosition(); + break; + + case VK_LEFT : xoff -= adj; break; // Arrows + case VK_UP : yoff += adj; break; + case VK_RIGHT : xoff += adj; break; + case VK_DOWN : yoff -= adj; break; + + default: + bool control = getControlPressed(); + char key = virtualKeyToChar( virtkey ); + if ( key != 0 ) + { + if ( '+' == key ) { + zoff += 1.0f; + break; + } + if ( '-' == key ) { + zoff -= 1.0f; + break; + } + } + else + { + return false; + } + } + updateWidget(); + return true; + } + + + }; int SmartWinMain( Application & app ) |