glc_trackballmover.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00026 #include "glc_trackballmover.h"
00027 #include "glc_viewport.h"
00028
00029
00030 GLC_TrackBallMover::GLC_TrackBallMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList)
00031 : GLC_Mover(pViewport, repsList)
00032 , m_Ratio(0.95)
00033 {
00034 GLC_Mover::m_MoverInfo.m_MatrixInfo.append(GLC_Matrix4x4());
00035 GLC_Mover::m_MoverInfo.m_VectorInfo.append(GLC_Vector3d());
00036 }
00037
00038
00039 GLC_TrackBallMover::GLC_TrackBallMover(const GLC_TrackBallMover& mover)
00040 : GLC_Mover(mover)
00041 , m_Ratio(mover.m_Ratio)
00042 {
00043
00044 }
00045
00046 GLC_TrackBallMover::~GLC_TrackBallMover()
00047 {
00048
00049 }
00050
00052
00054
00055
00056 GLC_Mover* GLC_TrackBallMover::clone() const
00057 {
00058 return new GLC_TrackBallMover(*this);
00059 }
00060
00062
00064
00065
00066 void GLC_TrackBallMover::init(QMouseEvent * e)
00067 {
00068 GLC_Mover::m_PreviousVector.setVect(mapForTracking(static_cast<double>(e->x()), static_cast<double>(e->y())));
00069
00070 const double Angle= acos(glc::Z_AXIS * GLC_Mover::m_PreviousVector);
00071 const GLC_Vector3d AxeRot(glc::Z_AXIS ^ GLC_Mover::m_PreviousVector);
00072
00073 GLC_Matrix4x4 Matrice(AxeRot, Angle);
00074
00075 GLC_Mover::m_MoverInfo.m_MatrixInfo.first()= Matrice;
00076 GLC_Mover::m_MoverInfo.m_VectorInfo.first()= GLC_Mover::m_PreviousVector;
00077
00078 initRepresentation();
00079 }
00080
00081
00082 bool GLC_TrackBallMover::move(QMouseEvent * e)
00083 {
00084 const GLC_Vector3d VectCurOrbit(mapForTracking(static_cast<double>(e->x()), static_cast<double>(e->y())));
00085
00086
00087 GLC_Mover::m_pViewport->cameraHandle()->orbit(GLC_Mover::m_PreviousVector, VectCurOrbit);
00088
00089
00090 const GLC_Matrix4x4 MatRot(GLC_Mover::m_PreviousVector, VectCurOrbit);
00091
00092 GLC_Mover::m_MoverInfo.m_MatrixInfo.first()= MatRot;
00093 updateRepresentation();
00094
00095
00096 GLC_Mover::m_PreviousVector = VectCurOrbit;
00097
00098 return true;
00099 }
00100
00102
00104
00105
00106 GLC_Vector3d GLC_TrackBallMover::mapForTracking( double x, double y) const
00107 {
00108 double AspectRatio;
00109 const double winHSize= static_cast<double>(GLC_Mover::m_pViewport->viewHSize());
00110 const double winVSize= static_cast<double>(GLC_Mover::m_pViewport->viewVSize());
00111
00112
00113 if (winHSize < winVSize)
00114 {
00115 AspectRatio= winVSize / winHSize;
00116 x= ( (x - winHSize / 2.0 ) / ( winHSize / 2.0) ) / m_Ratio;
00117 y= AspectRatio * ( ( winVSize / 2.0 - y) / ( winVSize / 2.0 ) ) / m_Ratio;
00118 }
00119 else
00120 {
00121 AspectRatio= winHSize / winVSize;
00122 x= AspectRatio * ( (x - winHSize / 2.0 ) / ( winHSize / 2.0) ) / m_Ratio;
00123 y= ( (winVSize / 2.0 - y) / (winVSize / 2.0 ) ) / m_Ratio;
00124 }
00125
00126
00127 GLC_Vector3d mousePos(x, y, 0.0);
00128 if (mousePos.length() > 1.0)
00129 {
00130 mousePos.setLength(1.0);
00131 }
00132 else
00133 {
00134 mousePos.setZ(sqrt(1.0 - mousePos.x() * mousePos.x() - mousePos.y() * mousePos.y()));
00135 }
00136
00137 return mousePos;
00138
00139 }