Index: /trunk/geant4/visualization/OpenGL/History
===================================================================
--- /trunk/geant4/visualization/OpenGL/History	(revision 803)
+++ /trunk/geant4/visualization/OpenGL/History	(revision 804)
@@ -20,4 +20,7 @@
 History file for visualization/OpenGL
 -------------------------------------
+
+28th Mai 2008  Laurent Garnier
+- Add mouse wheel zoom commands
 
 28th April 2008  Laurent Garnier
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 803)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLQtViewer.hh	(revision 804)
@@ -57,4 +57,5 @@
 class QMouseEvent;
 class QKeyEvent;
+class QWheelEvent;
 class QProcess;
 class QTime;
@@ -105,4 +106,5 @@
   void G4MouseMoveEvent(int, int, Qt::MouseButtons);
 #endif
+  void G4wheelEvent (QWheelEvent * event); 
   void G4keyPressEvent (QKeyEvent * event); 
   void rotateQtScene(float, float);
Index: /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh
===================================================================
--- /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh	(revision 803)
+++ /trunk/geant4/visualization/OpenGL/include/G4OpenGLStoredQtViewer.hh	(revision 804)
@@ -44,4 +44,5 @@
 
 class QMouseEvent;
+class QWheelEvent;
 class QContextMenuEvent;
 
@@ -64,4 +65,5 @@
 
 protected:
+  void wheelEvent(QWheelEvent *event);
   void mousePressEvent(QMouseEvent *event);
   void mouseMoveEvent(QMouseEvent *event);
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 803)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc	(revision 804)
@@ -37,4 +37,5 @@
 
 #define GEANT4_QT_DEBUG
+#define ROTATEGL
 
 #include "G4OpenGLQtViewer.hh"
@@ -93,5 +94,134 @@
   //   ::wglMakeCurrent(fHDC,fHGLRC);
   //  fWindow->makeCurrent();
-  G4OpenGLViewer::SetView ();
+  //  G4OpenGLViewer::SetView ();
+  
+  // Calculates view representation based on extent of object being
+  // viewed and (initial) viewpoint.  (Note: it can change later due
+  // to user interaction via visualization system's GUI.)
+  
+  // Lighting.
+  GLfloat lightPosition [4];
+  lightPosition [0] = fVP.GetActualLightpointDirection().x();
+  lightPosition [1] = fVP.GetActualLightpointDirection().y();
+  lightPosition [2] = fVP.GetActualLightpointDirection().z();
+  lightPosition [3] = 0.;
+  // Light position is "true" light direction, so must come after gluLookAt.
+  GLfloat ambient [] = { 0.2, 0.2, 0.2, 1.};
+  GLfloat diffuse [] = { 0.8, 0.8, 0.8, 1.};
+  glEnable (GL_LIGHT0);
+  glLightfv (GL_LIGHT0, GL_AMBIENT, ambient);
+  glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse);
+  
+  // Get radius of scene, etc.
+  // Note that this procedure properly takes into account zoom, dolly and pan.
+  const G4Point3D targetPoint
+    = fSceneHandler.GetScene()->GetStandardTargetPoint()
+    + fVP.GetCurrentTargetPoint ();
+  G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
+  if(radius<=0.) radius = 1.;
+  const G4double cameraDistance = fVP.GetCameraDistance (radius);
+  const G4Point3D cameraPosition =
+    targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
+  const GLdouble pnear   = fVP.GetNearDistance (cameraDistance, radius);
+  const GLdouble pfar    = fVP.GetFarDistance  (cameraDistance, pnear, radius);
+  const GLdouble right  = fVP.GetFrontHalfHeight (pnear, radius);
+  const GLdouble left   = -right;
+  const GLdouble bottom = left;
+  const GLdouble top    = right;
+  
+  glMatrixMode (GL_PROJECTION); // set up Frustum.
+  glLoadIdentity();
+
+  const G4Vector3D scale = fVP.GetScaleFactor();
+  glScaled(scale.x(),scale.y(),scale.z());
+  
+  if (fVP.GetFieldHalfAngle() == 0.) {
+    glOrtho (left, right, bottom, top, pnear, pfar);
+  }
+  else {
+    glFrustum (left, right, bottom, top, pnear, pfar);
+  }
+  
+  glMatrixMode (GL_MODELVIEW); // apply further transformations to scene.
+  glLoadIdentity();
+  
+  const G4Normal3D& upVector = fVP.GetUpVector ();  
+  G4Point3D gltarget;
+  if (cameraDistance > 1.e-6 * radius) {
+    gltarget = targetPoint;
+  }
+  else {
+    gltarget = targetPoint - radius * fVP.GetViewpointDirection().unit();
+  }
+
+  const G4Point3D& pCamera = cameraPosition;  // An alias for brevity.
+  gluLookAt (pCamera.x(),  pCamera.y(),  pCamera.z(),       // Viewpoint.
+	     gltarget.x(), gltarget.y(), gltarget.z(),      // Target point.
+	     upVector.x(), upVector.y(), upVector.z());     // Up vector.
+  
+  // Light position is "true" light direction, so must come after gluLookAt.
+  glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
+
+  // OpenGL no longer seems to reconstruct clipped edges, so, when the
+  // BooleanProcessor is up to it, abandon this and use generic
+  // clipping in G4OpenGLSceneHandler::CreateSectionPolyhedron.  Also,
+  // force kernel visit on change of clipping plane in
+  // G4OpenGLStoredViewer::CompareForKernelVisit.
+  if (fVP.IsSection () ) {  // pair of back to back clip planes.
+    const G4Plane3D& s = fVP.GetSectionPlane ();
+    double sArray[4];
+    sArray[0] = s.a();
+    sArray[1] = s.b();
+    sArray[2] = s.c();
+    sArray[3] = s.d() + radius * 1.e-05;
+    glClipPlane (GL_CLIP_PLANE0, sArray);
+    glEnable (GL_CLIP_PLANE0);
+    sArray[0] = -s.a();
+    sArray[1] = -s.b();
+    sArray[2] = -s.c();
+    sArray[3] = -s.d() + radius * 1.e-05;
+    glClipPlane (GL_CLIP_PLANE1, sArray);
+    glEnable (GL_CLIP_PLANE1);
+  } else {
+    glDisable (GL_CLIP_PLANE0);
+    glDisable (GL_CLIP_PLANE1);
+  }
+
+  const G4Planes& cutaways = fVP.GetCutawayPlanes();
+  size_t nPlanes = cutaways.size();
+  if (fVP.IsCutaway() &&
+      fVP.GetCutawayMode() == G4ViewParameters::cutawayIntersection &&
+      nPlanes > 0) {
+    double a[4];
+    a[0] = cutaways[0].a();
+    a[1] = cutaways[0].b();
+    a[2] = cutaways[0].c();
+    a[3] = cutaways[0].d();
+    glClipPlane (GL_CLIP_PLANE2, a);
+    glEnable (GL_CLIP_PLANE2);
+    if (nPlanes > 1) {
+      a[0] = cutaways[1].a();
+      a[1] = cutaways[1].b();
+      a[2] = cutaways[1].c();
+      a[3] = cutaways[1].d();
+      glClipPlane (GL_CLIP_PLANE3, a);
+      glEnable (GL_CLIP_PLANE3);
+    }
+    if (nPlanes > 2) {
+      a[0] = cutaways[2].a();
+      a[1] = cutaways[2].b();
+      a[2] = cutaways[2].c();
+      a[3] = cutaways[2].d();
+      glClipPlane (GL_CLIP_PLANE4, a);
+      glEnable (GL_CLIP_PLANE4);
+    }
+  } else {
+    glDisable (GL_CLIP_PLANE2);
+    glDisable (GL_CLIP_PLANE3);
+    glDisable (GL_CLIP_PLANE4);
+  }
+
+  // Background.
+  background = fVP.GetBackgroundColour ();
 }
 
@@ -103,10 +233,9 @@
   G4OpenGLViewer::ClearView ();
   // glLoadIdentity();
-  //   glRotatef(fRotationAngleX, 1.0, 0.0, 0.0);
-//    glRotatef(fRotationAngleY, 0.0, 1.0, 0.0);
-//    glRotatef(fRotationAngleZ, 0.0, 0.0, 1.0);
-//    fRotationAngleZ +=fDeltaRotationAngleZ;
-//    fRotationAngleY +=fDeltaRotationAngleY;
-//    fRotationAngleX +=fDeltaRotationAngleX;
+#ifdef ROTATEGL
+  glRotatef(fRotationAngleY, 1.0, 0.0, 0.0);
+  glRotatef(fRotationAngleX, 0.0, 1.0, 0.0);
+  glRotatef(fRotationAngleZ, 0.0, 0.0, 1.0);
+#endif
 }
 
@@ -1668,7 +1797,16 @@
   fHoldRotateEvent = true;
 
+#ifndef ROTATEGL
   rotateScene(dx,0,fDeltaRotation);
   rotateScene(0,dy,fDeltaRotation);
-
+#else
+  //  fDeltaRotationAngleX = -50*dx*M_PI/180; 
+  //  fDeltaRotationAngleY = 50*dy*M_PI/180; 
+  fDeltaRotationAngleX = -50*dx*3.14/180; 
+  fDeltaRotationAngleY = 50*dy*3.14/180; 
+  fRotationAngleZ +=fDeltaRotationAngleZ;
+  fRotationAngleY +=fDeltaRotationAngleY;
+  fRotationAngleX +=fDeltaRotationAngleX;
+#endif
   updateQWidget();
   
@@ -1986,4 +2124,14 @@
 
 
+void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * event) 
+{
+  fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(event->delta())/1200)); 
+  updateQWidget();
+
+#ifdef GEANT4_QT_DEBUG
+  printf("G4OpenGLQtViewer::wheel event  +++++++++++++++++++++ %f %d\n",fVP.GetZoomFactor(),event->delta());
+#endif
+}
+
 
 void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event) 
Index: /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc
===================================================================
--- /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 803)
+++ /trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredQtViewer.cc	(revision 804)
@@ -315,4 +315,9 @@
 }
 
+void G4OpenGLStoredQtViewer::wheelEvent (QWheelEvent * event) 
+{
+  G4wheelEvent(event);
+}
+
 /**
  * This function was build in order to make a zoom on double clic event.
