Ignore:
Timestamp:
May 30, 2008, 10:31:53 AM (16 years ago)
Author:
garnier
Message:

r846@wl-72126: garnier | 2008-05-29 12:20:22 +0200
prise en compte de la roulette de souris

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc

    r803 r804  
    3737
    3838#define GEANT4_QT_DEBUG
     39#define ROTATEGL
    3940
    4041#include "G4OpenGLQtViewer.hh"
     
    9394  //   ::wglMakeCurrent(fHDC,fHGLRC);
    9495  //  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 ();
    96226}
    97227
     
    103233  G4OpenGLViewer::ClearView ();
    104234  // 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
    111240}
    112241
     
    16681797  fHoldRotateEvent = true;
    16691798
     1799#ifndef ROTATEGL
    16701800  rotateScene(dx,0,fDeltaRotation);
    16711801  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
    16731811  updateQWidget();
    16741812 
     
    19862124
    19872125
     2126void 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
    19882136
    19892137void G4OpenGLQtViewer::G4keyPressEvent (QKeyEvent * event)
Note: See TracChangeset for help on using the changeset viewer.