Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** >> 25 // >> 26 // >> 27 // $Id$ >> 28 // 25 // 29 // 26 // G4OpenGLWin32Viewer : Class to provide Wind << 30 // G4OpenGLWin32Viewer : Class to provide WindowsNT specific 27 // functionality for Ope << 31 // functionality for OpenGL in GEANT4 28 // 32 // 29 // 27/06/2003 : G.Barrand : implementation (at 33 // 27/06/2003 : G.Barrand : implementation (at last !). 30 34 >> 35 #ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER >> 36 31 #include "G4OpenGLWin32Viewer.hh" 37 #include "G4OpenGLWin32Viewer.hh" 32 #include "G4VViewer.hh" 38 #include "G4VViewer.hh" 33 #include "G4VSceneHandler.hh" 39 #include "G4VSceneHandler.hh" 34 #include "G4OpenGLSceneHandler.hh" 40 #include "G4OpenGLSceneHandler.hh" 35 #include "G4Scene.hh" << 36 41 37 #include "G4ios.hh" 42 #include "G4ios.hh" 38 #include "G4VisExtent.hh" 43 #include "G4VisExtent.hh" 39 #include "G4LogicalVolume.hh" 44 #include "G4LogicalVolume.hh" 40 #include "G4VSolid.hh" 45 #include "G4VSolid.hh" 41 #include "G4Point3D.hh" 46 #include "G4Point3D.hh" 42 #include "G4Normal3D.hh" 47 #include "G4Normal3D.hh" 43 48 44 #include "G4SystemOfUnits.hh" << 45 49 46 ////////////////////////////////////////////// 50 ////////////////////////////////////////////////////////////////////////////// 47 void G4OpenGLWin32Viewer::SetView ( 51 void G4OpenGLWin32Viewer::SetView ( 48 ) 52 ) 49 ////////////////////////////////////////////// 53 ////////////////////////////////////////////////////////////////////////////// 50 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 54 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 51 { 55 { 52 if(!fHDC) return; 56 if(!fHDC) return; 53 if(!fHGLRC) return; 57 if(!fHGLRC) return; 54 ::wglMakeCurrent(fHDC,fHGLRC); 58 ::wglMakeCurrent(fHDC,fHGLRC); 55 G4OpenGLViewer::SetView (); 59 G4OpenGLViewer::SetView (); 56 } 60 } 57 61 58 ////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////// 59 void G4OpenGLWin32Viewer::ShowView ( 63 void G4OpenGLWin32Viewer::ShowView ( 60 ) 64 ) 61 ////////////////////////////////////////////// 65 ////////////////////////////////////////////////////////////////////////////// 62 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 66 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 63 { 67 { 64 if(!fHDC) return; 68 if(!fHDC) return; 65 glFlush (); 69 glFlush (); 66 // Empty the Windows message queue : 70 // Empty the Windows message queue : 67 MSG event; 71 MSG event; 68 while ( ::PeekMessage(&event, NULL, 0, 0, PM 72 while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) { 69 ::TranslateMessage(&event); 73 ::TranslateMessage(&event); 70 ::DispatchMessage (&event); 74 ::DispatchMessage (&event); 71 } 75 } 72 } 76 } 73 77 74 ////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////// 75 void G4OpenGLWin32Viewer::GetWin32Connection ( 79 void G4OpenGLWin32Viewer::GetWin32Connection ( 76 ) 80 ) 77 ////////////////////////////////////////////// 81 ////////////////////////////////////////////////////////////////////////////// 78 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 82 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 79 { 83 { 80 } 84 } 81 85 82 ////////////////////////////////////////////// 86 ////////////////////////////////////////////////////////////////////////////// 83 void G4OpenGLWin32Viewer::CreateGLWin32Context 87 void G4OpenGLWin32Viewer::CreateGLWin32Context ( 84 ) 88 ) 85 ////////////////////////////////////////////// 89 ////////////////////////////////////////////////////////////////////////////// 86 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 90 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 87 { 91 { 88 } 92 } 89 93 90 ////////////////////////////////////////////// 94 ////////////////////////////////////////////////////////////////////////////// 91 void G4OpenGLWin32Viewer::CreateMainWindow ( 95 void G4OpenGLWin32Viewer::CreateMainWindow ( 92 ) 96 ) 93 ////////////////////////////////////////////// 97 ////////////////////////////////////////////////////////////////////////////// 94 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 98 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 95 { 99 { 96 if(fWindow) return; //Done. 100 if(fWindow) return; //Done. 97 101 98 // Bill Gates stuff... 102 // Bill Gates stuff... 99 static const char className[] = "G4OpenGLWin 103 static const char className[] = "G4OpenGLWin32"; 100 static G4bool done = false; << 104 static bool done = false; 101 if(done==false) { 105 if(done==false) { 102 WNDCLASS wc; 106 WNDCLASS wc; 103 wc.style = CS_HREDRAW | CS_VREDRAW; 107 wc.style = CS_HREDRAW | CS_VREDRAW; 104 wc.lpfnWndProc = (WNDPROC)WindowProc; 108 wc.lpfnWndProc = (WNDPROC)WindowProc; 105 wc.cbClsExtra = 0; 109 wc.cbClsExtra = 0; 106 wc.cbWndExtra = 0; 110 wc.cbWndExtra = 0; 107 wc.hInstance = ::GetModuleHandle(NULL); 111 wc.hInstance = ::GetModuleHandle(NULL); 108 wc.hIcon = LoadIcon (NULL, IDI_APPLICATIO 112 wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); 109 wc.hCursor = LoadCursor(NULL,IDC_CROSS); 113 wc.hCursor = LoadCursor(NULL,IDC_CROSS); 110 wc.hbrBackground = NULL; 114 wc.hbrBackground = NULL; 111 wc.lpszMenuName = className; 115 wc.lpszMenuName = className; 112 wc.lpszClassName = className; 116 wc.lpszClassName = className; 113 ::RegisterClass(&wc); 117 ::RegisterClass(&wc); 114 done = true; 118 done = true; 115 } 119 } 116 120 117 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.Ge 121 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY()); 118 122 119 G4int x_res=GetSystemMetrics(SM_CXSCREEN); << 123 int x_res=GetSystemMetrics(SM_CXSCREEN); 120 G4int y_res=GetSystemMetrics(SM_CYSCREEN); << 124 int y_res=GetSystemMetrics(SM_CYSCREEN); 121 125 122 //FIXME : NOT tested ! 126 //FIXME : NOT tested ! 123 fWindow = ::CreateWindowEx(0, className,fNam << 127 fWindow = ::CreateWindow(className,fName.c_str(), 124 WS_OVERLAPPEDWINDOW, 128 WS_OVERLAPPEDWINDOW, 125 //WS_CHILD | WS_VISIBLE, 129 //WS_CHILD | WS_VISIBLE, 126 // 0,0, 130 // 0,0, 127 fVP.GetWindowAbsolu 131 fVP.GetWindowAbsoluteLocationHintX(x_res), 128 fVP.GetWindowAbsolu 132 fVP.GetWindowAbsoluteLocationHintY(y_res), 129 getWinWidth(), getWinHeight(), 133 getWinWidth(), getWinHeight(), 130 NULL, NULL, 134 NULL, NULL, 131 ::GetModuleHandle(NULL), 135 ::GetModuleHandle(NULL), 132 NULL); 136 NULL); 133 if(!fWindow) return; 137 if(!fWindow) return; 134 138 135 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LON << 139 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG(this)); 136 140 137 // initialize OpenGL rendering : 141 // initialize OpenGL rendering : 138 fHDC = ::GetDC(fWindow); 142 fHDC = ::GetDC(fWindow); 139 if( fHDC && (SetWindowPixelFormat(fHDC)==TRU 143 if( fHDC && (SetWindowPixelFormat(fHDC)==TRUE) ) { 140 fHGLRC = ::wglCreateContext(fHDC); 144 fHGLRC = ::wglCreateContext(fHDC); 141 } 145 } 142 146 143 if(fHDC && fHGLRC) { 147 if(fHDC && fHGLRC) { 144 ::wglMakeCurrent(fHDC,fHGLRC); 148 ::wglMakeCurrent(fHDC,fHGLRC); 145 } 149 } 146 150 147 //G.Barrand : avoid to indirectly pass in << 148 // WindowProc/[WM_SIZE,WM_PAINT << 149 // from this method. Else we have << 150 fInCreateWindow = true; << 151 << 152 ::SetForegroundWindow(fWindow); 151 ::SetForegroundWindow(fWindow); 153 ::ShowWindow(fWindow,SW_SHOWDEFAULT); 152 ::ShowWindow(fWindow,SW_SHOWDEFAULT); 154 ::UpdateWindow(fWindow); 153 ::UpdateWindow(fWindow); 155 ::DrawMenuBar(fWindow); 154 ::DrawMenuBar(fWindow); 156 << 157 fInCreateWindow = false; << 158 } 155 } 159 156 160 ////////////////////////////////////////////// 157 ////////////////////////////////////////////////////////////////////////////// 161 G4OpenGLWin32Viewer::G4OpenGLWin32Viewer ( 158 G4OpenGLWin32Viewer::G4OpenGLWin32Viewer ( 162 G4OpenGLSceneHandler& scene 159 G4OpenGLSceneHandler& scene 163 ) 160 ) 164 :G4VViewer (scene, -1) 161 :G4VViewer (scene, -1) 165 ,G4OpenGLViewer (scene) 162 ,G4OpenGLViewer (scene) 166 ,fMouseHovered(false) << 167 ,fMousePressed(false) << 168 ,fMousePressedX(0) << 169 ,fMousePressedY(0) << 170 ,fHDC(0) << 171 ,fWindow(0) 163 ,fWindow(0) >> 164 ,fHDC(0) 172 ,fHGLRC(0) 165 ,fHGLRC(0) 173 ,fInCreateWindow(false) << 174 ////////////////////////////////////////////// 166 ////////////////////////////////////////////////////////////////////////////// 175 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 167 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 176 { 168 { 177 } 169 } 178 170 179 ////////////////////////////////////////////// 171 ////////////////////////////////////////////////////////////////////////////// 180 G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer ( 172 G4OpenGLWin32Viewer::~G4OpenGLWin32Viewer ( 181 ) 173 ) 182 ////////////////////////////////////////////// 174 ////////////////////////////////////////////////////////////////////////////// 183 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 175 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 184 { 176 { 185 // This is the end (Jim Morisson). 177 // This is the end (Jim Morisson). 186 if (fViewId >= 0) { 178 if (fViewId >= 0) { 187 if(wglGetCurrentContext()!=NULL) wglMakeCu 179 if(wglGetCurrentContext()!=NULL) wglMakeCurrent(NULL,NULL); 188 if(fHGLRC) { 180 if(fHGLRC) { 189 wglDeleteContext(fHGLRC); 181 wglDeleteContext(fHGLRC); 190 fHGLRC = NULL; 182 fHGLRC = NULL; 191 } 183 } 192 184 193 if(fWindow) { 185 if(fWindow) { 194 ::SetWindowLongPtr(fWindow,GWLP_USERDATA 186 ::SetWindowLongPtr(fWindow,GWLP_USERDATA,LONG(NULL)); 195 if(fHDC) ::ReleaseDC(fWindow,fHDC); 187 if(fHDC) ::ReleaseDC(fWindow,fHDC); 196 ::DestroyWindow(fWindow); 188 ::DestroyWindow(fWindow); 197 } 189 } 198 } 190 } 199 } 191 } 200 192 201 ////////////////////////////////////////////// 193 ////////////////////////////////////////////////////////////////////////////// 202 LRESULT CALLBACK G4OpenGLWin32Viewer::WindowPr << 194 LRESULT CALLBACK G4OpenGLWin32Viewer::WindowProc ( 203 HWND aWindow << 195 HWND aWindow 204 ,UINT aMessage << 196 ,UINT aMessage 205 ,WPARAM aWParam 197 ,WPARAM aWParam 206 ,LPARAM aLParam 198 ,LPARAM aLParam 207 ) 199 ) 208 ////////////////////////////////////////////// 200 ////////////////////////////////////////////////////////////////////////////// 209 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 201 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 210 { 202 { 211 switch (aMessage) { << 203 /* 212 case WM_SIZE: { << 204 switch (aMessage) { 213 //FIXME : have to handle WM_RESIZE << 205 case WM_PAINT:{ 214 // Seems to be done (ovidio.pena AT upm. << 206 printf("debug : PAINT\n"); 215 auto* This = (G4OpenGLWin32Viewer*) << 207 HDC hDC; 216 ::GetWindowLongPtr(aWindow, << 208 PAINTSTRUCT ps; 217 if (This) { << 209 hDC = BeginPaint(aWindow,&ps); 218 This->fWinSize_x = (G4int) LOWORD(aLPa << 210 if(This) { 219 This->fWinSize_y = (G4int) HIWORD(aLPa << 211 // FIXME : To have an automatic refresh someone have to redraw here. 220 if (!This->fInCreateWindow) { << 212 } 221 This->SetView(); << 213 EndPaint(aWindow, &ps); 222 glViewport(0, 0, This->fWinSize_x, T << 214 223 This->DrawView(); << 215 //FIXME : have to handle WM_RESIZE 224 } << 216 //pView->fWinSize_x = (G4int) width; 225 } << 217 //pView->fWinSize_y = (G4int) height; 226 return 0; << 218 G4OpenGLWin32Viewer* This = 227 } << 219 (G4OpenGLWin32Viewer*)::GetWindowLong(aWindow,GWL_USERDATA); 228 << 220 if(This) { 229 case WM_PAINT: { << 230 PAINTSTRUCT ps; << 231 BeginPaint(aWindow, &ps); << 232 auto* This = (G4OpenGLWin32Viewer*) << 233 ::GetWindowLongPtr(aWindow, << 234 if (This) { << 235 //FIXME : To have an automatic refresh << 236 // Seems to be done (ovidio.pena AT up << 237 if(!This->fInCreateWindow) { << 238 This->SetView(); << 239 This->ClearView(); << 240 This->DrawView(); << 241 } << 242 } << 243 EndPaint(aWindow, &ps); << 244 return 0; << 245 } << 246 << 247 case WM_LBUTTONDOWN: { << 248 auto* This = (G4OpenGLWin32Viewer*) << 249 ::GetWindowLongPtr(aWindow, << 250 This->TrackMouse(LOWORD(aLParam), HIWORD << 251 return 0; << 252 } << 253 << 254 case WM_RBUTTONDOWN: { << 255 auto* This = (G4OpenGLWin32Viewer*) << 256 ::GetWindowLongPtr(aWindow, << 257 This->TrackMouse(LOWORD(aLParam), HIWORD << 258 return 0; << 259 } << 260 << 261 case WM_LBUTTONUP: { << 262 auto* This = (G4OpenGLWin32Viewer*) << 263 ::GetWindowLongPtr(aWindow, << 264 This->ReleaseMouse(); << 265 return 0; << 266 } << 267 << 268 case WM_RBUTTONUP: { << 269 auto* This = (G4OpenGLWin32Viewer*) << 270 ::GetWindowLongPtr(aWindow, << 271 This->ReleaseMouse(); << 272 return 0; << 273 } << 274 << 275 case WM_MOUSEHOVER: { << 276 auto* This = (G4OpenGLWin32Viewer*) << 277 ::GetWindowLongPtr(aWindow, << 278 This->fMouseHovered = true; << 279 return 0; << 280 } << 281 << 282 case WM_MOUSELEAVE: { << 283 auto* This = (G4OpenGLWin32Viewer*) << 284 ::GetWindowLongPtr(aWindow, << 285 This->fMouseHovered = false; << 286 return 0; << 287 } << 288 << 289 case WM_MOUSEMOVE: { << 290 auto* This = (G4OpenGLWin32Viewer*) << 291 ::GetWindowLongPtr(aWindow, << 292 << 293 if (!This->fMouseHovered) { << 294 // mouse hover/leave tracking << 295 TRACKMOUSEEVENT tme; << 296 tme.cbSize = sizeof(tme); << 297 tme.dwFlags = TME_HOVER | TME_LEAVE; << 298 tme.hwndTrack = aWindow; << 299 tme.dwHoverTime = HOVER_DEFAULT; << 300 ::TrackMouseEvent(&tme); << 301 This->fMouseHovered = true; << 302 } << 303 << 304 if (This->fMousePressed) { << 305 G4int x = (G4int) LOWORD(aLParam); << 306 G4int y = (G4int) HIWORD(aLParam); << 307 G4int dx = x - This->fMousePressedX; << 308 G4int dy = y - This->fMousePressedY; << 309 This->fMousePressedX = x; << 310 This->fMousePressedY = y; << 311 << 312 if (aWParam == MK_LBUTTON) { // Rotat << 313 This->SetRotation(dx, dy); << 314 } << 315 << 316 if (aWParam == MK_RBUTTON) { // Shift << 317 This->SetShift(dx, dy); << 318 } << 319 << 320 This->SetView(); << 321 This->ClearView(); << 322 This->DrawView(); << 323 } << 324 << 325 return 0; << 326 } << 327 << 328 case WM_MOUSEWHEEL: { << 329 auto* This = (G4OpenGLWin32Viewer*) << 330 ::GetWindowLongPtr(aWindow, << 331 << 332 G4int delta = (short) HIWORD(aWParam); << 333 << 334 This->SetZoom(delta); << 335 << 336 This->SetView(); 221 This->SetView(); >> 222 glViewport(0,0,This->fWinSize_x,This->fWinSize_y); 337 This->ClearView(); 223 This->ClearView(); 338 This->DrawView(); 224 This->DrawView(); 339 return 0; << 225 // WARNING : the below empty the Windows message queue... >> 226 This->FinishView(); 340 } 227 } 341 << 228 } return 0; 342 default: << 229 default: 343 return DefWindowProc(aWindow, aMessage, << 230 return DefWindowProc(aWindow,aMessage,aWParam,aLParam); 344 } 231 } 345 // return DefWindowProc(aWindow,aMessage,aWPa << 232 */ >> 233 return DefWindowProc(aWindow,aMessage,aWParam,aLParam); 346 } 234 } 347 235 348 ////////////////////////////////////////////// 236 ////////////////////////////////////////////////////////////////////////////// 349 G4bool G4OpenGLWin32Viewer::SetWindowPixelForm << 237 bool G4OpenGLWin32Viewer::SetWindowPixelFormat( 350 HDC aHdc 238 HDC aHdc 351 ) 239 ) 352 ////////////////////////////////////////////// 240 ////////////////////////////////////////////////////////////////////////////// 353 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 241 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 354 { 242 { 355 // The ungessable... 243 // The ungessable... 356 244 357 PIXELFORMATDESCRIPTOR pfd; 245 PIXELFORMATDESCRIPTOR pfd; 358 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); 246 pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); 359 pfd.nVersion = 1; 247 pfd.nVersion = 1; 360 pfd.dwFlags = 248 pfd.dwFlags = 361 PFD_DRAW_TO_WINDOW | 249 PFD_DRAW_TO_WINDOW | 362 PFD_SUPPORT_OPENGL | 250 PFD_SUPPORT_OPENGL | 363 PFD_DOUBLEBUFFER | 251 PFD_DOUBLEBUFFER | 364 PFD_STEREO_DONTCARE; 252 PFD_STEREO_DONTCARE; 365 pfd.iPixelType = PFD_TYPE_RGBA; 253 pfd.iPixelType = PFD_TYPE_RGBA; 366 pfd.cColorBits = 32; 254 pfd.cColorBits = 32; 367 pfd.cRedBits = 8; 255 pfd.cRedBits = 8; 368 pfd.cRedShift = 16; 256 pfd.cRedShift = 16; 369 pfd.cGreenBits = 8; 257 pfd.cGreenBits = 8; 370 pfd.cGreenShift = 8; 258 pfd.cGreenShift = 8; 371 pfd.cBlueBits = 8; 259 pfd.cBlueBits = 8; 372 pfd.cBlueShift = 0; 260 pfd.cBlueShift = 0; 373 pfd.cAlphaBits = 0; 261 pfd.cAlphaBits = 0; 374 pfd.cAlphaShift = 0; 262 pfd.cAlphaShift = 0; 375 pfd.cAccumBits = 64; 263 pfd.cAccumBits = 64; 376 pfd.cAccumRedBits = 16; 264 pfd.cAccumRedBits = 16; 377 pfd.cAccumGreenBits = 16; 265 pfd.cAccumGreenBits = 16; 378 pfd.cAccumBlueBits = 16; 266 pfd.cAccumBlueBits = 16; 379 pfd.cAccumAlphaBits = 0; 267 pfd.cAccumAlphaBits = 0; 380 pfd.cDepthBits = 32; 268 pfd.cDepthBits = 32; 381 pfd.cStencilBits = 8; 269 pfd.cStencilBits = 8; 382 pfd.cAuxBuffers = 0; 270 pfd.cAuxBuffers = 0; 383 pfd.iLayerType = PFD_MAIN_PLANE; 271 pfd.iLayerType = PFD_MAIN_PLANE; 384 pfd.bReserved = 0; 272 pfd.bReserved = 0; 385 pfd.dwLayerMask = 0; 273 pfd.dwLayerMask = 0; 386 pfd.dwVisibleMask = 0; 274 pfd.dwVisibleMask = 0; 387 pfd.dwDamageMask = 0; 275 pfd.dwDamageMask = 0; 388 276 389 G4int pixelIndex = ::ChoosePixelFormat(aHdc, << 277 int pixelIndex = ::ChoosePixelFormat(aHdc,&pfd); 390 if (pixelIndex==0) { 278 if (pixelIndex==0) { 391 pixelIndex = 1; 279 pixelIndex = 1; 392 if (::DescribePixelFormat(aHdc, 280 if (::DescribePixelFormat(aHdc, 393 pixelIndex, 281 pixelIndex, 394 sizeof(PIXELFORMATDESCRIPTOR), 282 sizeof(PIXELFORMATDESCRIPTOR), 395 &pfd)==0) { 283 &pfd)==0) { 396 return false; 284 return false; 397 } 285 } 398 } 286 } 399 if (::SetPixelFormat(aHdc,pixelIndex,&pfd)== 287 if (::SetPixelFormat(aHdc,pixelIndex,&pfd)==FALSE) return false; 400 return true; 288 return true; 401 } 289 } 402 290 403 ////////////////////////////////////////////// << 404 void G4OpenGLWin32Viewer::TrackMouse( << 405 G4int x << 406 ,G4int y << 407 ) << 408 ////////////////////////////////////////////// << 409 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! << 410 { << 411 fMousePressed = true; << 412 fMousePressedX = x; << 413 fMousePressedY = y; << 414 } << 415 << 416 ////////////////////////////////////////////// << 417 void G4OpenGLWin32Viewer::ReleaseMouse( << 418 ) << 419 ////////////////////////////////////////////// << 420 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! << 421 { << 422 fMousePressed = false; << 423 fMousePressedX = 0; << 424 fMousePressedY = 0; << 425 } << 426 << 427 ////////////////////////////////////////////// << 428 void G4OpenGLWin32Viewer::SetShift( << 429 G4int dx << 430 ,G4int dy << 431 ) << 432 ////////////////////////////////////////////// << 433 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! << 434 { << 435 const G4double sceneRadius = GetSceneHandler << 436 ->GetExtent().Get << 437 const G4double scale = 300; // Roughly pixe << 438 const G4double dxScene = dx*sceneRadius/scal << 439 const G4double dyScene = dy*sceneRadius/scal << 440 fVP.IncrementPan(-dxScene,dyScene); << 441 } << 442 << 443 ////////////////////////////////////////////// << 444 void G4OpenGLWin32Viewer::SetRotation( << 445 G4int dx << 446 ,G4int dy << 447 ) << 448 ////////////////////////////////////////////// << 449 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! << 450 { << 451 // Simple ad-hoc algorithms (borrowed from G << 452 const G4Vector3D& x_prime = fVP.GetViewpoint << 453 .cross(fVP.GetUp << 454 const G4Vector3D& y_prime = x_prime.cross(fV << 455 const G4double scale = 200; // Roughly pixe << 456 G4Vector3D newViewpointDirection = fVP.GetVi << 457 newViewpointDirection += dx*x_prime/scale; << 458 newViewpointDirection += dy*y_prime/scale; << 459 fVP.SetViewpointDirection(newViewpointDirect << 460 << 461 if (fVP.GetRotationStyle() == G4ViewParamete << 462 G4Vector3D newUpVector = fVP.GetUpVector << 463 newUpVector += dx*x_prime/scale; << 464 newUpVector += dy*y_prime/scale; << 465 fVP.SetUpVector(newUpVector.unit()); << 466 } << 467 } << 468 << 469 ////////////////////////////////////////////// << 470 void G4OpenGLWin32Viewer::SetZoom( << 471 G4int delta << 472 ) << 473 ////////////////////////////////////////////// << 474 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! << 475 { << 476 if (fVP.GetFieldHalfAngle() == 0.) { // O << 477 const G4double scale = 500; // Empiri << 478 fVP.MultiplyZoomFactor(1. + delta/scal << 479 } else { // P << 480 const G4double scale = fVP.GetFieldHal << 481 fVP.SetDolly(fVP.GetDolly() + delta/sc << 482 } << 483 } << 484 291 >> 292 #endif 485 293