void OnMouseClick(int button, int state, int x, int y) { mouseButton = button; if ( state == GLUT_DOWN ) { bMousePressed = true; hCamera.mousePress(x, y); } else if ( state == GLUT_UP ) { bMousePressed = false; hCamera.mouseRelease(x, y); } }
//====================================================================================== // the Windows Procedure event handler LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) //====================================================================================== { static HGLRC hRC; // rendering context static HDC hDC; // device context char string[] = "Hello, world!"; // text to be displayed //int width, height; // window width and height int cx, cy; GLfloat h; int mx, my; switch(message) { case WM_CREATE: // window is being created return 0; break; case WM_ACTIVATE: // Watch For Window Activate Message { if (!HIWORD(wParam)) // Check Minimization State { g_active=TRUE; // Program Is Active } else { g_active=FALSE; // Program Is No Longer Active } return 0; // Return To The Message Loop } case WM_CLOSE: // windows is closing // send WM_QUIT to message queue PostQuitMessage(0); return 0; case WM_KEYDOWN: if(wParam == VK_ESCAPE) g_bEnd = TRUE; else if ( wParam == VK_SPACE ) { g_bPause = !g_bPause; } else if ( wParam == 79 ) // 'o' { bool bPause = g_bPause; g_bPause = true; TCHAR lpstrFile[MAX_PATH]=""; // MAX_PATH = 260 OPENFILENAME OFN = { sizeof(OPENFILENAME), g_hWnd, NULL, "Bullet Physics Files (*.bullet)\0*.bullet\0ALL Files (*.*)\0*.*\0\0", NULL, 0, 1, lpstrFile, MAX_PATH, NULL, 0, NULL, "Load Bullet Physics File Dialog", OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, 0, 0, "bullet", 0, NULL, NULL }; if ( GetOpenFileName(&OFN) ) { if ( !g_BulletSim.LoadBulletFile(lpstrFile) ) { MessageBox(g_hWnd, "Failed to load the bullet file", "Error", MB_OK | MB_ICONERROR); } } g_bPause = bPause; } else if ( wParam == 82 ) // 'r' { g_BulletSim.ReloadBulletFile(); } break; case WM_SIZE: cy = HIWORD(lParam); // retrieve width and height cx = LOWORD(lParam); GLfloat w; h = 1.0; if(cy == 0) w = (GLfloat) cx; else w = (GLfloat) cx / (GLfloat) cy; glViewport(0, 0, cx, cy); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-w, w, -h, h, 3.0, 3000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return 0; break; case WM_LBUTTONDOWN: mx = LOWORD(lParam); my = HIWORD(lParam); //SetCapture(g_hWnd); hCamera.mousePress(mx, my); return 0; break; case WM_LBUTTONUP: mx = LOWORD(lParam); my = HIWORD(lParam); //ReleaseCapture(); hCamera.mouseRelease(mx, my); return 0; break; case WM_RBUTTONDOWN: mx = LOWORD(lParam); my = HIWORD(lParam); //SetCapture(g_hWnd); hCamera.mousePress(mx, my); return 0; break; case WM_RBUTTONUP: mx = LOWORD(lParam); my = HIWORD(lParam); //ReleaseCapture(); hCamera.mouseRelease(mx, my); return 0; break; case WM_MOUSEMOVE: mx = LOWORD(lParam); my = HIWORD(lParam); gmx = mx; gmy = my; if( wParam == MK_LBUTTON ) { hCamera.mouseMove(mx, my, Left_button); } else if( wParam == MK_RBUTTON ) { hCamera.mouseMove(mx, my, Right_button); } else if( wParam == (MK_RBUTTON | MK_LBUTTON) ) { hCamera.mouseMove(mx, my, (Right_button | Left_button) ); } return 0; break; default: break; } return (DefWindowProc(hwnd, message, wParam, lParam)); }