Changeset 798 for trunk/geant4/visualization/OpenGL/src
- Timestamp:
- May 14, 2008, 6:44:55 PM (16 years ago)
- Location:
- trunk/geant4/visualization/OpenGL/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r797 r798 295 295 ,fDeltaSceneTranslation(0.01) 296 296 ,fDeltaDepth(0.01) 297 ,fDeltaZoom(0. 1)297 ,fDeltaZoom(0.05) 298 298 ,fDeltaMove(0.05) 299 299 ,fHoldKeyEvent(false) … … 309 309 ,fRecordingStep(WAIT) 310 310 ,fProcess(NULL) 311 ,fLaunchSpinDelay(100) 311 312 { 312 313 … … 314 315 G4Qt* interactorManager = G4Qt::getInstance (); 315 316 317 fLastPos3 = QPoint(-1,-1); 318 fLastPos2 = QPoint(-1,-1); 319 fLastPos1 = QPoint(-1,-1); 320 316 321 initMovieParameters(); 317 322 … … 1515 1520 { 1516 1521 fAutoMove = false; // stop automove 1517 fLastPos = p; 1522 fLastPos1 = p; 1523 fLastPos2 = fLastPos1; 1524 fLastPos3 = fLastPos2; 1518 1525 fLastEventTime->start(); 1519 1526 if (fMouseAction == STYLE2){ // pick … … 1526 1533 void G4OpenGLQtViewer::G4MouseReleaseEvent() 1527 1534 { 1535 #ifdef GEANT4_QT_DEBUG 1536 printf("G4OpenGLQtViewer::mouseRealease() %d,%d %d,%d %d,%d\n",fLastPos1.x(),fLastPos1.y(),fLastPos2.x(),fLastPos2.y(),fLastPos3.x(),fLastPos3.y()); 1537 #endif 1528 1538 fSpinningDelay = fLastEventTime->elapsed(); 1539 QPoint delta = (fLastPos3-fLastPos1); 1540 if ((delta.x() == 0) && (delta.y() == 0)) { 1529 1541 #ifdef GEANT4_QT_DEBUG 1530 printf("G4OpenGLQtViewer::G4MouseReleaseEvent delay %d\n",fSpinningDelay); 1531 #endif 1532 if ((fDeltaPosX == 0) && (fDeltaPosY == 0)) { 1542 printf("G4OpenGLQtViewer::mouseRealease() EXIT 1 \n"); 1543 #endif 1533 1544 return; 1534 1545 } 1535 if (fSpinningDelay < 100) {1546 if (fSpinningDelay < fLaunchSpinDelay ) { 1536 1547 fAutoMove = true; 1537 1538 1548 QTime lastMoveTime; 1539 1549 lastMoveTime.start(); … … 1541 1551 int cycles = 4; 1542 1552 while (fAutoMove) { 1543 if ( lastMoveTime.elapsed() > ( 100/ (cycles/2))) {1553 if ( lastMoveTime.elapsed() > (fLaunchSpinDelay / (cycles/2))) { 1544 1554 if (fMouseAction == STYLE1) { // rotate 1545 rotate Scene(fDeltaPosX,fDeltaPosY);1555 rotateQtScene(((float)delta.x())/cycles,((float)delta.y())/cycles); 1546 1556 } else if (fMouseAction == STYLE2) { // move 1547 moveScene(- fDeltaPosX,-fDeltaPosY,0,true);1557 moveScene(-((float)delta.x())/cycles,-((float)delta.y())/cycles,0,true); 1548 1558 } 1549 1559 lastMoveTime.start(); … … 1553 1563 cycles ++ ; 1554 1564 } 1555 fDeltaPosX = 0;1556 fDeltaPosY = 0;1557 1558 1565 } 1559 1566 } … … 1578 1585 } 1579 1586 1580 fDeltaPosX = fLastPos.x() - pos_x; 1581 fDeltaPosY = fLastPos.y() - pos_y; 1587 fLastPos3 = fLastPos2; 1588 fLastPos2 = fLastPos1; 1589 fLastPos1 = QPoint(pos_x, pos_y); 1582 1590 1583 1591 if (fMouseAction == STYLE1) { // rotate 1584 1592 if (mButtons & Qt::LeftButton) { 1585 rotate Scene(fDeltaPosX,fDeltaPosY);1593 rotateQtScene(fLastPos2.x()-fLastPos1.x(),fLastPos2.y()-fLastPos1.y()); 1586 1594 } 1587 1595 } else if (fMouseAction == STYLE2) { // move 1588 1596 if (mButtons & Qt::LeftButton) { 1589 moveScene( -fDeltaPosX,-fDeltaPosY,0,true);1597 moveScene(fLastPos1.x()-fLastPos2.x(),fLastPos1.y()-fLastPos2.y(),0,true); 1590 1598 } 1591 1599 } 1592 fLastPos = QPoint(pos_x, pos_y); 1600 1593 1601 fLastEventTime->start(); 1594 1602 } … … 1599 1607 @param dx delta mouse x position 1600 1608 @param dy delta mouse y position 1601 @param mouseMove : true if even comes from a mouse move, false if even comes from key action1602 */ 1603 1604 void G4OpenGLQtViewer::moveScene( int dx,int dy, int dz,bool mouseMove)1609 @param mouseMove : true if even comes from a mouse move, false if even comes from key action 1610 */ 1611 1612 void G4OpenGLQtViewer::moveScene(float dx,float dy, float dz,bool mouseMove) 1605 1613 { 1606 1614 if (fHoldMoveEvent) … … 1634 1642 */ 1635 1643 1636 void G4OpenGLQtViewer::rotate Scene(int dx, int dy)1644 void G4OpenGLQtViewer::rotateQtScene(float dx, float dy) 1637 1645 { 1638 #ifdef GEANT4_QT_DEBUG1639 printf("G4OpenGLQtViewer::rotateScene %d %d\n",dx,dy);1640 #endif1641 1642 1646 if (fHoldRotateEvent) 1643 1647 return; 1644 1648 fHoldRotateEvent = true; 1645 1649 1646 G4Vector3D vp;1647 G4Vector3D up;1648 1649 G4Vector3D xprime;1650 G4Vector3D yprime;1651 G4Vector3D zprime;1652 1653 G4double delta_alpha;1654 G4double delta_theta;1655 1656 G4Vector3D new_vp;1657 G4Vector3D new_up;1658 1659 G4double cosalpha;1660 G4double sinalpha;1661 1662 G4Vector3D a1;1663 G4Vector3D a2;1664 G4Vector3D delta;1665 G4Vector3D viewPoint;1666 1667 1668 //phi spin stuff here1669 1670 vp = fVP.GetViewpointDirection ().unit ();1671 up = fVP.GetUpVector ().unit ();1672 1673 yprime = (up.cross(vp)).unit();1674 zprime = (vp.cross(yprime)).unit();1675 1676 if (fVP.GetLightsMoveWithCamera()) {1677 delta_alpha = dy * fDeltaRotation;1678 delta_theta = -dx * fDeltaRotation;1679 } else {1680 delta_alpha = -dy * fDeltaRotation;1681 delta_theta = dx * fDeltaRotation;1682 }1683 1684 delta_alpha *= deg;1685 delta_theta *= deg;1686 1687 new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime;1688 1689 // to avoid z rotation flipping1690 // to allow more than 360° rotation1691 if (fVP.GetLightsMoveWithCamera()) {1692 new_up = (new_vp.cross(yprime)).unit();1693 if (new_vp.z()*vp.z() <0) {1694 new_up.set(new_up.x(),-new_up.y(),new_up.z());1695 }1696 } else {1697 new_up = up;1698 if (new_vp.z()*vp.z() <0) {1699 new_up.set(new_up.x(),-new_up.y(),new_up.z());1700 }1701 }1702 fVP.SetUpVector(new_up);1703 ////////////////1704 // Rotates by fixed azimuthal angle delta_theta.1705 1706 cosalpha = new_up.dot (new_vp.unit());1707 sinalpha = std::sqrt (1. - std::pow (cosalpha, 2));1708 yprime = (new_up.cross (new_vp.unit())).unit ();1709 xprime = yprime.cross (new_up);1710 // Projection of vp on plane perpendicular to up...1711 a1 = sinalpha * xprime;1712 // Required new projection...1713 a2 = sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime);1714 // Required Increment vector...1715 delta = a2 - a1;1716 // So new viewpoint is...1717 viewPoint = new_vp.unit() + delta;1718 1719 1650 #ifdef GEANT4_QT_DEBUG 1720 // printf("vp Vector : %f %f %f delta_alpha:%f delta_theta:%f cosalpha:%f sinalpha:%f\n",viewPoint.x(),viewPoint.y(),viewPoint.z(),delta_alpha,delta_theta,cosalpha,sinalpha); 1721 // printf("up : %f %f %f\n",up.x(),up.y(),up.z()); 1722 // printf("new up : %f %f %f\n",new_up.x(),new_up.y(),new_up.z()); 1723 // printf("vp : %f %f %f\n",vp.x(),vp.y(),vp.z()); 1724 // printf("new_vp : %f %f %f\n",new_vp.x(),new_vp.y(),new_vp.z()); 1725 #endif 1726 fVP.SetViewAndLights (viewPoint); 1651 printf("G4OpenGLQtViewer::rotateQtScene %f %f\n",dx,dy); 1652 #endif 1653 rotateScene(dx,dy,fDeltaRotation); 1727 1654 updateQWidget(); 1728 1655 1729 1656 fHoldRotateEvent = false; 1730 #ifdef GEANT4_QT_DEBUG 1731 printf("G4OpenGLQtViewer::Rotate END\n"); 1732 #endif 1657 } 1658 1659 /** 1660 @param dx delta mouse x position 1661 @param dy delta mouse y position 1662 */ 1663 1664 void G4OpenGLQtViewer::rotateQtCamera(float dx, float dy) 1665 { 1666 if (fHoldRotateEvent) 1667 return; 1668 fHoldRotateEvent = true; 1669 1670 rotateScene(dx,dy,fDeltaRotation); 1671 updateQWidget(); 1672 1673 fHoldRotateEvent = false; 1733 1674 } 1734 1675 … … 2051 1992 if ((event->key() == Qt::Key_Down) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi 2052 1993 #endif 2053 rotate Scene(0,-1);1994 rotateQtCamera(0,-1); 2054 1995 } 2055 1996 #if QT_VERSION < 0x040000 … … 2058 1999 else if ((event->key() == Qt::Key_Up) && (event->modifiers() & Qt::ShiftModifier)) { // rotate phi 2059 2000 #endif 2060 rotate Scene(0,1);2001 rotateQtCamera(0,1); 2061 2002 } 2062 2003 #if QT_VERSION < 0x040000 … … 2065 2006 if ((event->key() == Qt::Key_Left) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta 2066 2007 #endif 2067 rotate Scene(1,0);2008 rotateQtCamera(1,0); 2068 2009 } 2069 2010 #if QT_VERSION < 0x040000 … … 2072 2013 else if ((event->key() == Qt::Key_Right) && (event->modifiers() & Qt::ShiftModifier)) { // rotate theta 2073 2014 #endif 2074 rotate Scene(-1,0);2015 rotateQtCamera(-1,0); 2075 2016 } 2076 2017 -
trunk/geant4/visualization/OpenGL/src/G4OpenGLViewer.cc
r789 r798 877 877 } 878 878 879 void G4OpenGLViewer::rotateScene(G4double dx, G4double dy,G4double deltaRotation) 880 { 881 882 G4Vector3D vp; 883 G4Vector3D up; 884 885 G4Vector3D xprime; 886 G4Vector3D yprime; 887 G4Vector3D zprime; 888 889 G4double delta_alpha; 890 G4double delta_theta; 891 892 G4Vector3D new_vp; 893 G4Vector3D new_up; 894 895 G4double cosalpha; 896 G4double sinalpha; 897 898 G4Vector3D a1; 899 G4Vector3D a2; 900 G4Vector3D delta; 901 G4Vector3D viewPoint; 902 903 904 //phi spin stuff here 905 906 vp = fVP.GetViewpointDirection ().unit (); 907 up = fVP.GetUpVector ().unit (); 908 909 yprime = (up.cross(vp)).unit(); 910 zprime = (vp.cross(yprime)).unit(); 911 912 if (fVP.GetLightsMoveWithCamera()) { 913 delta_alpha = dy * deltaRotation; 914 delta_theta = -dx * deltaRotation; 915 } else { 916 delta_alpha = -dy * deltaRotation; 917 delta_theta = dx * deltaRotation; 918 } 919 920 delta_alpha *= deg; 921 delta_theta *= deg; 922 923 new_vp = std::cos(delta_alpha) * vp + std::sin(delta_alpha) * zprime; 924 925 // to avoid z rotation flipping 926 // to allow more than 360° rotation 927 if (fVP.GetLightsMoveWithCamera()) { 928 new_up = (new_vp.cross(yprime)).unit(); 929 if (new_vp.z()*vp.z() <0) { 930 new_up.set(new_up.x(),-new_up.y(),new_up.z()); 931 } 932 } else { 933 new_up = up; 934 if (new_vp.z()*vp.z() <0) { 935 new_up.set(new_up.x(),-new_up.y(),new_up.z()); 936 } 937 } 938 fVP.SetUpVector(new_up); 939 //////////////// 940 // Rotates by fixed azimuthal angle delta_theta. 941 942 cosalpha = new_up.dot (new_vp.unit()); 943 sinalpha = std::sqrt (1. - std::pow (cosalpha, 2)); 944 yprime = (new_up.cross (new_vp.unit())).unit (); 945 xprime = yprime.cross (new_up); 946 // Projection of vp on plane perpendicular to up... 947 a1 = sinalpha * xprime; 948 // Required new projection... 949 a2 = sinalpha * (std::cos (delta_theta) * xprime + std::sin (delta_theta) * yprime); 950 // Required Increment vector... 951 delta = a2 - a1; 952 // So new viewpoint is... 953 viewPoint = new_vp.unit() + delta; 954 955 fVP.SetViewAndLights (viewPoint); 956 } 957 879 958 #endif -
trunk/geant4/visualization/OpenGL/src/G4OpenGLXmRotationCallbacks.cc
r631 r798 64 64 //theta spin stuff here 65 65 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 66 67 pView->rotateScene((G4double)pView->rot_sens,0,1); 68 69 /* 66 70 G4double delta_theta; 67 71 … … 100 104 101 105 pView->fVP.SetViewAndLights (viewPoint); 106 */ 102 107 103 108 pView->SetView (); … … 135 140 G4OpenGLXmViewer* pView = (G4OpenGLXmViewer*) clientData; 136 141 142 pView->rotateScene(0,(G4double)pView->rot_sens,1); 143 144 /* 137 145 if (pView->fVP.GetLightsMoveWithCamera()) { 138 146 if (pView -> rotate_up) { … … 167 175 } 168 176 177 */ 169 178 pView->SetView (); 170 179 pView->ClearView ();
Note: See TracChangeset
for help on using the changeset viewer.