Changeset 804 for trunk/geant4
- Timestamp:
- May 30, 2008, 10:31:53 AM (16 years ago)
- Location:
- trunk/geant4/visualization/OpenGL
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/History
r790 r804 20 20 History file for visualization/OpenGL 21 21 ------------------------------------- 22 23 28th Mai 2008 Laurent Garnier 24 - Add mouse wheel zoom commands 22 25 23 26 28th April 2008 Laurent Garnier -
trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
r803 r804 57 57 class QMouseEvent; 58 58 class QKeyEvent; 59 class QWheelEvent; 59 60 class QProcess; 60 61 class QTime; … … 105 106 void G4MouseMoveEvent(int, int, Qt::MouseButtons); 106 107 #endif 108 void G4wheelEvent (QWheelEvent * event); 107 109 void G4keyPressEvent (QKeyEvent * event); 108 110 void rotateQtScene(float, float); -
trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh
r704 r804 44 44 45 45 class QMouseEvent; 46 class QWheelEvent; 46 47 class QContextMenuEvent; 47 48 … … 64 65 65 66 protected: 67 void wheelEvent(QWheelEvent *event); 66 68 void mousePressEvent(QMouseEvent *event); 67 69 void mouseMoveEvent(QMouseEvent *event); -
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r803 r804 37 37 38 38 #define GEANT4_QT_DEBUG 39 #define ROTATEGL 39 40 40 41 #include "G4OpenGLQtViewer.hh" … … 93 94 // ::wglMakeCurrent(fHDC,fHGLRC); 94 95 // fWindow->makeCurrent(); 95 G4OpenGLViewer::SetView (); 96 // G4OpenGLViewer::SetView (); 97 98 // Calculates view representation based on extent of object being 99 // viewed and (initial) viewpoint. (Note: it can change later due 100 // to user interaction via visualization system's GUI.) 101 102 // Lighting. 103 GLfloat lightPosition [4]; 104 lightPosition [0] = fVP.GetActualLightpointDirection().x(); 105 lightPosition [1] = fVP.GetActualLightpointDirection().y(); 106 lightPosition [2] = fVP.GetActualLightpointDirection().z(); 107 lightPosition [3] = 0.; 108 // Light position is "true" light direction, so must come after gluLookAt. 109 GLfloat ambient [] = { 0.2, 0.2, 0.2, 1.}; 110 GLfloat diffuse [] = { 0.8, 0.8, 0.8, 1.}; 111 glEnable (GL_LIGHT0); 112 glLightfv (GL_LIGHT0, GL_AMBIENT, ambient); 113 glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse); 114 115 // Get radius of scene, etc. 116 // Note that this procedure properly takes into account zoom, dolly and pan. 117 const G4Point3D targetPoint 118 = fSceneHandler.GetScene()->GetStandardTargetPoint() 119 + fVP.GetCurrentTargetPoint (); 120 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); 121 if(radius<=0.) radius = 1.; 122 const G4double cameraDistance = fVP.GetCameraDistance (radius); 123 const G4Point3D cameraPosition = 124 targetPoint + cameraDistance * fVP.GetViewpointDirection().unit(); 125 const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius); 126 const GLdouble pfar = fVP.GetFarDistance (cameraDistance, pnear, radius); 127 const GLdouble right = fVP.GetFrontHalfHeight (pnear, radius); 128 const GLdouble left = -right; 129 const GLdouble bottom = left; 130 const GLdouble top = right; 131 132 glMatrixMode (GL_PROJECTION); // set up Frustum. 133 glLoadIdentity(); 134 135 const G4Vector3D scale = fVP.GetScaleFactor(); 136 glScaled(scale.x(),scale.y(),scale.z()); 137 138 if (fVP.GetFieldHalfAngle() == 0.) { 139 glOrtho (left, right, bottom, top, pnear, pfar); 140 } 141 else { 142 glFrustum (left, right, bottom, top, pnear, pfar); 143 } 144 145 glMatrixMode (GL_MODELVIEW); // apply further transformations to scene. 146 glLoadIdentity(); 147 148 const G4Normal3D& upVector = fVP.GetUpVector (); 149 G4Point3D gltarget; 150 if (cameraDistance > 1.e-6 * radius) { 151 gltarget = targetPoint; 152 } 153 else { 154 gltarget = targetPoint - radius * fVP.GetViewpointDirection().unit(); 155 } 156 157 const G4Point3D& pCamera = cameraPosition; // An alias for brevity. 158 gluLookAt (pCamera.x(), pCamera.y(), pCamera.z(), // Viewpoint. 159 gltarget.x(), gltarget.y(), gltarget.z(), // Target point. 160 upVector.x(), upVector.y(), upVector.z()); // Up vector. 161 162 // Light position is "true" light direction, so must come after gluLookAt. 163 glLightfv (GL_LIGHT0, GL_POSITION, lightPosition); 164 165 // OpenGL no longer seems to reconstruct clipped edges, so, when the 166 // BooleanProcessor is up to it, abandon this and use generic 167 // clipping in G4OpenGLSceneHandler::CreateSectionPolyhedron. Also, 168 // force kernel visit on change of clipping plane in 169 // G4OpenGLStoredViewer::CompareForKernelVisit. 170 if (fVP.IsSection () ) { // pair of back to back clip planes. 171 const G4Plane3D& s = fVP.GetSectionPlane (); 172 double sArray[4]; 173 sArray[0] = s.a(); 174 sArray[1] = s.b(); 175 sArray[2] = s.c(); 176 sArray[3] = s.d() + radius * 1.e-05; 177 glClipPlane (GL_CLIP_PLANE0, sArray); 178 glEnable (GL_CLIP_PLANE0); 179 sArray[0] = -s.a(); 180 sArray[1] = -s.b(); 181 sArray[2] = -s.c(); 182 sArray[3] = -s.d() + radius * 1.e-05; 183 glClipPlane (GL_CLIP_PLANE1, sArray); 184 glEnable (GL_CLIP_PLANE1); 185 } else { 186 glDisable (GL_CLIP_PLANE0); 187 glDisable (GL_CLIP_PLANE1); 188 } 189 190 const G4Planes& cutaways = fVP.GetCutawayPlanes(); 191 size_t nPlanes = cutaways.size(); 192 if (fVP.IsCutaway() && 193 fVP.GetCutawayMode() == G4ViewParameters::cutawayIntersection && 194 nPlanes > 0) { 195 double a[4]; 196 a[0] = cutaways[0].a(); 197 a[1] = cutaways[0].b(); 198 a[2] = cutaways[0].c(); 199 a[3] = cutaways[0].d(); 200 glClipPlane (GL_CLIP_PLANE2, a); 201 glEnable (GL_CLIP_PLANE2); 202 if (nPlanes > 1) { 203 a[0] = cutaways[1].a(); 204 a[1] = cutaways[1].b(); 205 a[2] = cutaways[1].c(); 206 a[3] = cutaways[1].d(); 207 glClipPlane (GL_CLIP_PLANE3, a); 208 glEnable (GL_CLIP_PLANE3); 209 } 210 if (nPlanes > 2) { 211 a[0] = cutaways[2].a(); 212 a[1] = cutaways[2].b(); 213 a[2] = cutaways[2].c(); 214 a[3] = cutaways[2].d(); 215 glClipPlane (GL_CLIP_PLANE4, a); 216 glEnable (GL_CLIP_PLANE4); 217 } 218 } else { 219 glDisable (GL_CLIP_PLANE2); 220 glDisable (GL_CLIP_PLANE3); 221 glDisable (GL_CLIP_PLANE4); 222 } 223 224 // Background. 225 background = fVP.GetBackgroundColour (); 96 226 } 97 227 … … 103 233 G4OpenGLViewer::ClearView (); 104 234 // glLoadIdentity(); 105 // glRotatef(fRotationAngleX, 1.0, 0.0, 0.0); 106 // glRotatef(fRotationAngleY, 0.0, 1.0, 0.0); 107 // glRotatef(fRotationAngleZ, 0.0, 0.0, 1.0); 108 // fRotationAngleZ +=fDeltaRotationAngleZ; 109 // fRotationAngleY +=fDeltaRotationAngleY; 110 // fRotationAngleX +=fDeltaRotationAngleX; 235 #ifdef ROTATEGL 236 glRotatef(fRotationAngleY, 1.0, 0.0, 0.0); 237 glRotatef(fRotationAngleX, 0.0, 1.0, 0.0); 238 glRotatef(fRotationAngleZ, 0.0, 0.0, 1.0); 239 #endif 111 240 } 112 241 … … 1668 1797 fHoldRotateEvent = true; 1669 1798 1799 #ifndef ROTATEGL 1670 1800 rotateScene(dx,0,fDeltaRotation); 1671 1801 rotateScene(0,dy,fDeltaRotation); 1672 1802 #else 1803 // fDeltaRotationAngleX = -50*dx*M_PI/180; 1804 // fDeltaRotationAngleY = 50*dy*M_PI/180; 1805 fDeltaRotationAngleX = -50*dx*3.14/180; 1806 fDeltaRotationAngleY = 50*dy*3.14/180; 1807 fRotationAngleZ +=fDeltaRotationAngleZ; 1808 fRotationAngleY +=fDeltaRotationAngleY; 1809 fRotationAngleX +=fDeltaRotationAngleX; 1810 #endif 1673 1811 updateQWidget(); 1674 1812 … … 1986 2124 1987 2125 2126 void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * event) 2127 { 2128 fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(event->delta())/1200)); 2129 updateQWidget(); 2130 2131 #ifdef GEANT4_QT_DEBUG 2132 printf("G4OpenGLQtViewer::wheel event +++++++++++++++++++++ %f %d\n",fVP.GetZoomFactor(),event->delta()); 2133 #endif 2134 } 2135 1988 2136 1989 2137 void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event) -
trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
r800 r804 315 315 } 316 316 317 void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event) 318 { 319 G4wheelEvent(event); 320 } 321 317 322 /** 318 323 * This function was build in order to make a zoom on double clic event.
Note: See TracChangeset
for help on using the changeset viewer.