Changeset 801 for trunk/geant4/visualization/OpenGL/src
- Timestamp:
- May 16, 2008, 5:46:02 PM (16 years ago)
- Location:
- trunk/geant4/visualization/OpenGL/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r800 r801 102 102 { 103 103 G4OpenGLViewer::ClearView (); 104 // 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; 111 111 } 112 112 … … 1605 1605 fLastPos2 = fLastPos1; 1606 1606 fLastPos1 = QPoint(pos_x, pos_y); 1607 1607 1608 int deltaX = fLastPos2.x()-fLastPos1.x(); 1608 1609 int deltaY = fLastPos2.y()-fLastPos1.y(); 1609 1610 1610 // try to get the x,y mouve into user friendly rotation1611 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_DEBUG1624 printf("G4OpenGLQtViewer::MouseMove %d,%d Rot:%f,%f new : %f %f %f\n",deltaX,deltaY,fRotationAngleX,fRotationAngleY,dx,dy,dz);1625 #endif1626 1611 if (fMouseAction == STYLE1) { // rotate 1627 1612 if (mButtons & Qt::LeftButton) { 1628 rotateQtScene( fLastPos2.x()-fLastPos1.x(),fLastPos2.y()-fLastPos1.y());1613 rotateQtScene(deltaX,deltaY); 1629 1614 } 1630 1615 } else if (fMouseAction == STYLE2) { // move 1631 1616 if (mButtons & Qt::LeftButton) { 1632 moveScene( fLastPos1.x()-fLastPos2.x(),fLastPos1.y()-fLastPos2.y(),0,true);1617 moveScene(-deltaX,-deltaY,0,true); 1633 1618 } 1634 1619 } … … 1682 1667 return; 1683 1668 fHoldRotateEvent = true; 1684 fDeltaRotationAngleX = dx; 1685 fDeltaRotationAngleY = dy;1669 1670 rotateSceneTest2(dx,dy,fDeltaRotation); 1686 1671 // rotateScene(dx,0,fDeltaRotation); 1687 1672 // rotateScene(0,dy,fDeltaRotation); … … 1703 1688 fHoldRotateEvent = true; 1704 1689 1690 rotateSceneTest2(dx,dy,fDeltaRotation); 1691 // rotateScene(dx,dy,fDeltaRotation); 1692 updateQWidget(); 1693 1694 fHoldRotateEvent = false; 1695 } 1696 1697 1698 void 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 1744 void G4OpenGLQtViewer::rotateSceneTest(float dx, float dy,float delta) 1745 { 1705 1746 fDeltaRotationAngleX = dx; 1706 1747 fDeltaRotationAngleY = dy; … … 1725 1766 fDeltaRotationAngleZ = dz2; 1726 1767 1727 // rotateScene(dx,dy,fDeltaRotation); 1728 updateQWidget(); 1729 1730 fHoldRotateEvent = false; 1731 } 1768 } 1769 1770 void 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 * 1812 currentdir 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 /* 1835 float[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 */ 1732 1852 1733 1853 /** This is the benning of a rescale function. It does nothing for the moment -
trunk/geant4/visualization/OpenGL/src/G4OpenGLViewer.cc
r800 r801 927 927 // to avoid z rotation flipping 928 928 // to allow more than 360° rotation 929 #ifdef GEANT4_QT_DEBUG 930 const G4Point3D targetPoint 931 = fSceneHandler.GetScene()->GetStandardTargetPoint() 932 + fVP.GetCurrentTargetPoint (); 933 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius(); 934 if(radius<=0.) radius = 1.; 935 const G4double cameraDistance = fVP.GetCameraDistance (radius); 936 const G4Point3D cameraPosition = 937 targetPoint + cameraDistance * fVP.GetViewpointDirection().unit(); 938 939 940 printf("G4OpenGLViewer:: Tp: %f %f %f Vpd:%f %f %f - Up:%f %f %f Cp:%f %f %f\n", 941 targetPoint[0],targetPoint[1],targetPoint[2], 942 vp.x(),vp.y(),vp.z(), 943 up.x(),up.y(),up.z(), 944 cameraPosition[0],cameraPosition[1],cameraPosition[2]); 945 #endif 946 929 947 if (fVP.GetLightsMoveWithCamera()) { 930 948 new_up = (new_vp.cross(yprime)).unit(); … … 933 951 } 934 952 } else { 935 #ifdef GEANT4_QT_DEBUG936 // printf("G4OpenGLViewer:: %f %f %f - %f %f %f \n",up.x(),up.y(),up.z(),new_vp.x(),new_vp.y(),new_vp.z());937 #endif938 953 new_up = up; 939 954 if (new_vp.z()*vp.z() <0) { … … 945 960 } 946 961 } 962 new_up.set(new_up.x(),-new_up.y(),new_up.z()); 947 963 fVP.SetUpVector(new_up); 948 964 ////////////////
Note: See TracChangeset
for help on using the changeset viewer.