Changeset 1259


Ignore:
Timestamp:
May 26, 2010, 2:17:04 PM (14 years ago)
Author:
garnier
Message:

best auto rotation

File:
1 edited

Legend:

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

    r1254 r1259  
    2525//
    2626//
    27 // $Id: G4OpenGLQtViewer.cc,v 1.49 2010/05/20 07:09:33 lgarnier Exp $
     27// $Id: G4OpenGLQtViewer.cc,v 1.50 2010/05/20 08:13:37 allison Exp $
    2828// GEANT4 tag $Name:  $
    2929//
     
    114114  printf("G4OpenGLQtViewer::CreateMainWindow :: ++++++++++++++ add new TAB %s  W:%d H:%d SizeHinX:%d SizeHintY:%d\n",name.toStdString().c_str(),getWinWidth(),getWinHeight(),fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
    115115#endif
    116   G4Qt* interactorManager = G4Qt::getInstance ();
     116  //G4Qt* interactorManager = G4Qt::getInstance ();
    117117
    118118  ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
     
    208208  ,fWindow(0)
    209209  ,fRecordFrameNumber(0)
    210   ,fRotationAngleX(0)
    211   ,fRotationAngleY(0)
    212   ,fDeltaRotationAngleX(0)
    213   ,fDeltaRotationAngleY(0)
    214210  ,fContextMenu(0)
    215211  ,fMouseAction(STYLE1)
     
    231227  ,fRecordingStep(WAIT)
    232228  ,fProcess(NULL)
     229  ,fNbMaxFramesPerSec(100)
     230  ,fNbMaxAnglePerSec(360)
    233231  ,fLaunchSpinDelay(100)
    234232{
     
    14781476    lastMoveTime.start();
    14791477    // try to addapt speed move/rotate looking to drawing speed
    1480     int cycles = 4;
     1478    float correctionFactor = 5;
    14811479    while (fAutoMove) {
    1482       //      if ( lastMoveTime.elapsed() > (fSpinningDelay / (cycles/2))) {
     1480      if ( lastMoveTime.elapsed () >= (int)(1000/fNbMaxFramesPerSec)) {
     1481        float lTime = 1000/((float)lastMoveTime.elapsed ());
     1482        if (((((float)delta.x())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
     1483            ((((float)delta.x())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
     1484          correctionFactor = (float)delta.x()*(lTime/fNbMaxAnglePerSec);
     1485          if (delta.x() <0 ) {
     1486            correctionFactor = -correctionFactor;
     1487          }
     1488        }
     1489      if (((((float)delta.y())/correctionFactor)*lTime > fNbMaxAnglePerSec) ||
     1490          ((((float)delta.y())/correctionFactor)*lTime < -fNbMaxAnglePerSec) ) {
     1491          correctionFactor = (float)delta.y()*(lTime/fNbMaxAnglePerSec);
     1492          if (delta.y() <0 ) {
     1493            correctionFactor = -correctionFactor;
     1494          }
     1495        }
     1496
    14831497        if (fMouseAction == STYLE1) {  // rotate
    1484           rotateQtScene(((float)delta.x())/cycles,((float)delta.y())/cycles);
     1498          rotateQtScene(((float)delta.x())/correctionFactor,((float)delta.y())/correctionFactor);
    14851499        } else if (fMouseAction == STYLE2) {  // move
    1486           moveScene(-((float)delta.x())/cycles,-((float)delta.y())/cycles,0,true);
     1500          moveScene(-((float)delta.x())/correctionFactor,-((float)delta.y())/correctionFactor,0,true);
    14871501        }
     1502#ifdef G4DEBUG_VIS_OGL
     1503        printf("G4OpenGLQtViewer::G4MouseReleaseEvent Fps:%f x:%d y:%d cycle:%f\n",(float)1000/lastMoveTime.elapsed(),delta.x(),delta.y(),correctionFactor);
     1504#endif
    14881505        lastMoveTime.start();
    1489         cycles = 1 ;
     1506      }
    14901507      ((QApplication*)G4Qt::getInstance ())->processEvents();
    1491       cycles ++ ;
    14921508    }
    14931509  }
     
    26942710    fGLWindow = new QDialog();
    26952711#ifdef G4DEBUG_VIS_OGL
    2696     printf("G4OpenGLQtViewer::GetParentWidget fGLWindow:%d \n",fGLWindow);
     2712    printf("G4OpenGLQtViewer::GetParentWidget fGLWindow\n");
    26972713#endif
    26982714  }
Note: See TracChangeset for help on using the changeset viewer.