Ignore:
Timestamp:
May 16, 2008, 5:46:02 PM (16 years ago)
Author:
garnier
Message:

r840@wl-72126: garnier | 2008-05-16 17:45:55 +0200
en test avec de nouveaux calculs...

File:
1 edited

Legend:

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

    r800 r801  
    102102{
    103103  G4OpenGLViewer::ClearView ();
    104   //  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;
     104  // 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;
    111111}
    112112
     
    16051605  fLastPos2 = fLastPos1;
    16061606  fLastPos1 = QPoint(pos_x, pos_y);
     1607
    16071608  int deltaX = fLastPos2.x()-fLastPos1.x();
    16081609  int deltaY = fLastPos2.y()-fLastPos1.y();
    16091610
    1610   // try to get the x,y mouve into user friendly rotation
    1611 
    1612   float cox = std::cos ((fRotationAngleX*M_PI)/180);
    1613   float coy = std::cos ((fRotationAngleY*M_PI)/180);
    1614   float coz = 1;
    1615   float six = std::sin ((fRotationAngleX*M_PI)/180);
    1616   float siy = std::sin ((fRotationAngleY*M_PI)/180);
    1617   float siz = 0;
    1618 
    1619   float dx = coy*(siz*deltaY+coz*deltaX);
    1620   float dy = six*(siy*(siz*deltaY+coz*deltaX))+cox*(coz*deltaY-siz*deltaX);
    1621   float dz = cox*(siy*(siz*deltaY+coz*deltaX))-six*(coz*deltaY-siz*deltaX);
    1622  
    1623 #ifdef GEANT4_QT_DEBUG
    1624   printf("G4OpenGLQtViewer::MouseMove %d,%d Rot:%f,%f new : %f %f %f\n",deltaX,deltaY,fRotationAngleX,fRotationAngleY,dx,dy,dz);
    1625 #endif
    16261611  if (fMouseAction == STYLE1) {  // rotate
    16271612    if (mButtons & Qt::LeftButton) {
    1628       rotateQtScene(fLastPos2.x()-fLastPos1.x(),fLastPos2.y()-fLastPos1.y());
     1613      rotateQtScene(deltaX,deltaY);
    16291614    }
    16301615  } else if (fMouseAction == STYLE2) {  // move
    16311616    if (mButtons & Qt::LeftButton) {
    1632       moveScene(fLastPos1.x()-fLastPos2.x(),fLastPos1.y()-fLastPos2.y(),0,true);
     1617      moveScene(-deltaX,-deltaY,0,true);
    16331618    }
    16341619  }
     
    16821667    return;
    16831668  fHoldRotateEvent = true;
    1684   fDeltaRotationAngleX = dx;
    1685   fDeltaRotationAngleY = dy;
     1669
     1670  rotateSceneTest2(dx,dy,fDeltaRotation);
    16861671  //  rotateScene(dx,0,fDeltaRotation);
    16871672  //  rotateScene(0,dy,fDeltaRotation);
     
    17031688  fHoldRotateEvent = true;
    17041689
     1690  rotateSceneTest2(dx,dy,fDeltaRotation);
     1691  //  rotateScene(dx,dy,fDeltaRotation);
     1692  updateQWidget();
     1693 
     1694  fHoldRotateEvent = false;
     1695}
     1696
     1697
     1698void G4OpenGLQtViewer::rotateSceneTest2(float dx, float dy,float deltaRot)
     1699{
     1700  fDeltaRotationAngleX = dx;
     1701  fDeltaRotationAngleY = dy;
     1702  //  rotateScene(dx,dy,fDeltaRotation);
     1703
     1704  const G4Point3D targetPoint
     1705    = fSceneHandler.GetScene()->GetStandardTargetPoint()
     1706    + fVP.GetCurrentTargetPoint ();
     1707  G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
     1708  if(radius<=0.) radius = 1.;
     1709  const G4double cameraDistance = fVP.GetCameraDistance (radius);
     1710  const G4Point3D cameraPosition =
     1711    targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
     1712  G4Vector3D up = fVP.GetUpVector ().unit ();
     1713  G4Vector3D new_dx ;
     1714  G4Vector3D new_cameraPosition ;
     1715  G4Vector3D new_up ;
     1716  G4Vector3D delta ;
     1717
     1718  if ((up[1]==1) &&(up[0]==0) && (up[2]==0)) {
     1719    up[1] = cameraPosition[2];
     1720  }
     1721  new_dx[2] = (cameraPosition[0]*up[1]-cameraPosition[1]*up[0])/100; // EN TEST 
     1722  new_dx[0] = (cameraPosition[1]*up[2]-cameraPosition[2]*up[1])/100;  // EN TEST
     1723  new_dx[1] = (cameraPosition[2]*up[0]-cameraPosition[0]*up[2])/100;  // EN TEST
     1724
     1725  delta = new_dx*dx*deltaRot + up*dy*deltaRot;
     1726  new_cameraPosition = cameraPosition + delta;
     1727 
     1728  new_up[2] = new_cameraPosition[0]*(-delta[1])-new_cameraPosition[1]*(-delta[0]);
     1729  new_up[0] = new_cameraPosition[1]*(-delta[2])-new_cameraPosition[2]*(-delta[1]);
     1730  new_up[1] = new_cameraPosition[2]*(-delta[0])-new_cameraPosition[0]*(-delta[2]);
     1731
     1732
     1733#ifdef GEANT4_QT_DEBUG
     1734  printf("G4OpenGLQtViewer::Rotate2 Tp %f,%f %f up:%f %f %f dx:%f %f %f\n",
     1735         targetPoint[0],targetPoint[1],targetPoint[2],up[0],up[1],up[2],new_dx[0],new_dx[1],new_dx[2]);
     1736  printf("G4OpenGLQtViewer::Rotate2 Cp %f,%f %f new_up:%f %f %f delta:%f %f %f\n",
     1737         new_cameraPosition[0],new_cameraPosition[1],new_cameraPosition[2],new_up[0],new_up[1],new_up[2],delta[0],delta[1],delta[2]);
     1738#endif
     1739
     1740  fVP.SetUpVector(new_up);
     1741  fVP.SetViewAndLights (new_cameraPosition);
     1742}
     1743
     1744void G4OpenGLQtViewer::rotateSceneTest(float dx, float dy,float delta)
     1745{
    17051746  fDeltaRotationAngleX = dx;
    17061747  fDeltaRotationAngleY = dy;
     
    17251766  fDeltaRotationAngleZ = dz2;
    17261767
    1727   //  rotateScene(dx,dy,fDeltaRotation);
    1728   updateQWidget();
    1729  
    1730   fHoldRotateEvent = false;
    1731 }
     1768}
     1769
     1770void G4OpenGLQtViewer::rotateSceneInventor(float dx, float dy,float delta)
     1771{
     1772  // __________________________
     1773  // From Inventor
     1774  // --------------------------
     1775  //SoGuiExaminerViewerP::rotateCamera(SoCamera * cam,
     1776  //                                   const SbVec3f & aroundaxis,
     1777  //                                   const float delta)
     1778
     1779  // position of camera
     1780  /*
     1781  const G4Point3D targetPoint
     1782    = fSceneHandler.GetScene()->GetStandardTargetPoint()
     1783    + fVP.GetCurrentTargetPoint ();
     1784  G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
     1785  if(radius<=0.) radius = 1.;
     1786  const G4double cameraDistance = fVP.GetCameraDistance (radius);
     1787  const G4Point3D cameraPosition =
     1788    targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
     1789
     1790  //
     1791
     1792  G4Point3D currentdir = fVP.GetViewpointDirection().unit();
     1793
     1794  const G4Point3D focalpoint = cameraPosition +
     1795    cameraDistance * currentdir;
     1796
     1797  // set new orientation
     1798  float rotation[4];
     1799  float quatRotationX[4];
     1800
     1801  // from SbRotation::setValue(axis,radians)
     1802  this->quatRotationX[3] = (float)cos(radians/2);
     1803  const float sineval = (float)sin(radians/2);
     1804  G4Point3D a = axis;
     1805  // we test for a null vector above
     1806  (void) a.normalize();
     1807  this->quatRotationX[0] = a[0] * sineval;
     1808  this->quatRotationX[1] = a[1] * sineval;
     1809  this->quatRotationX[2] = a[2] * sineval;
     1810 
     1811  // from SbRotation operator *
     1812currentdir
     1813  float currentdir[0], currentdir[1], currentdir[2], currentdir[3];
     1814  q.getValue(currentdir[0], currentdir[1], currentdir[2], currentdir[3]);
     1815
     1816  this->setValue(currentdir[3]*quatRotationX[0] + currentdir[0]*quatRotationX[3] + currentdir[1]*quatRotationX[2] - currentdir[2]*quatRotationX[1],
     1817                 currentdir[3]*quatRotationX[1] - currentdir[0]*quatRotationX[2] + currentdir[1]*quatRotationX[3] + currentdir[2]*quatRotationX[0],
     1818                 currentdir[3]*quatRotationX[2] + currentdir[0]*quatRotationX[1] - currentdir[1]*quatRotationX[0] + currentdir[2]*quatRotationX[3],
     1819                 currentdir[3]*quatRotationX[3] - currentdir[0]*quatRotationX[0] - currentdir[1]*quatRotationX[1] - currentdir[2]*quatRotationX[2]);
     1820
     1821
     1822  //  cam->orientation = SbRotation(aroundaxis, delta) * currentorientation;
     1823
     1824  SbVec3f newdir;
     1825  cam->orientation.getValue().multVec(DEFAULTDIRECTION, newdir);
     1826  cam->position = focalpoint - cam->focalDistance.getValue() * newdir;
     1827
     1828  // __________________________
     1829  // END From Inventor
     1830  // --------------------------
     1831  */
     1832}
     1833
     1834/*
     1835float[4] G4OpenGLQtViewer::makeRotationMatrix(const G4Point3D axis, const float radians)
     1836{
     1837  float res[4];
     1838  // From <http://www.automation.hut.fi/~jaro/thesis/hyper/node9.html>.
     1839
     1840  res[3] = (float)cos(radians/2);
     1841
     1842  const float sineval = (float)sin(radians/2);
     1843  SbVec3f a = axis;
     1844  // we test for a null vector above
     1845  (void) a.normalize();
     1846  res[0] = a[0] * sineval;
     1847  res[1] = a[1] * sineval;
     1848  res[2] = a[2] * sineval;
     1849
     1850}
     1851  */
    17321852
    17331853/** This is the benning of a rescale function. It does nothing for the moment
Note: See TracChangeset for help on using the changeset viewer.