glc_tsrmover.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
00024
00025 #include "glc_tsrmover.h"
00026 #include "glc_viewport.h"
00027
00028 #include "../geometry/glc_point.h"
00029
00030
00031 GLC_TsrMover::GLC_TsrMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList)
00032 : GLC_Mover(pViewport, repsList)
00033 {
00034
00035 }
00036
00037
00038 GLC_TsrMover::GLC_TsrMover(const GLC_TsrMover& tsrMover)
00039 : GLC_Mover(tsrMover)
00040 {
00041
00042 }
00043
00044
00045 GLC_TsrMover::~GLC_TsrMover()
00046 {
00047
00048 }
00049
00051
00053
00054
00055 GLC_Mover* GLC_TsrMover::clone() const
00056 {
00057 return new GLC_TsrMover(*this);
00058 }
00059
00060
00062
00064
00065
00066 void GLC_TsrMover::init(const GLC_UserInput& userInput)
00067 {
00068 m_PreviousVector= GLC_Point3d(userInput.normalyzeXTouchCenter(), userInput.normalyzeYTouchCenter(), 0.0);
00069 }
00070
00071
00072 bool GLC_TsrMover::move(const GLC_UserInput& userInput)
00073 {
00074 if (!(userInput.normalyzeXTouchCenter() < 0.0) && !(userInput.normalyzeYTouchCenter() < 0.0))
00075 {
00076 m_PreviousVector= GLC_Point3d(userInput.normalyzeXTouchCenter(), userInput.normalyzeYTouchCenter(), 0.0);
00077 }
00078 else
00079 {
00080 qDebug() << "Pas cool";
00081 if (!userInput.translation().isNull())
00082 {
00083 m_PreviousVector= GLC_Vector3d(userInput.translation().getX(), userInput.translation().getY(), 0.0) + m_PreviousVector;
00084 }
00085 }
00086
00087 const double x= m_PreviousVector.x();
00088 const double y= m_PreviousVector.y();
00089
00090
00091
00092
00093
00094 if (!qFuzzyCompare(userInput.scaleFactor(), 0))
00095 {
00096 GLC_Point dummy(m_pViewport->cameraHandle()->target());
00097 m_pViewport->setDistMinAndMax(dummy.boundingBox());
00098
00099 GLC_Point2d nPos= m_pViewport->mapNormalyzeToOpenGLScreen(x, y);
00100 GLC_Point3d nPos3D(nPos.getX(), nPos.getY(), 1.0);
00101 GLC_Point3d projected= m_pViewport->compositionMatrix().inverted() * nPos3D;
00102
00103 m_pViewport->cameraHandle()->zoom(userInput.scaleFactor());
00104
00105 m_pViewport->setDistMinAndMax(dummy.boundingBox());
00106 GLC_Point3d projected2= m_pViewport->compositionMatrix().inverted() * nPos3D;
00107 GLC_Vector3d delta= projected - projected2;
00108 m_pViewport->cameraHandle()->translate(delta);
00109 }
00110
00111 if (!qFuzzyCompare(userInput.rotationAngle(), 0))
00112 {
00113 GLC_Point dummy(m_pViewport->cameraHandle()->target());
00114 m_pViewport->setDistMinAndMax(dummy.boundingBox());
00115
00116 GLC_Point2d nPos= m_pViewport->mapNormalyzeToOpenGLScreen(x, y);
00117 GLC_Point3d nPos3D(nPos.getX(), nPos.getY(), 1.0);
00118 GLC_Point3d center= m_pViewport->compositionMatrix().inverted() * nPos3D;
00119
00120 GLC_Vector3d axis= m_pViewport->cameraHandle()->forward();
00121
00122 m_pViewport->cameraHandle()->rotateAround(axis, userInput.rotationAngle(), center);
00123 }
00124
00125 if (!userInput.translation().isNull())
00126 {
00127 double transX= userInput.translation().getX() * m_pViewport->viewHSize();
00128 double transY= userInput.translation().getY() * m_pViewport->viewVSize();
00129
00130 GLC_Vector3d mappedTranslation(-transX, -transY, 0.0);
00131
00132 const double ChampsVision = m_pViewport->cameraHandle()->distEyeTarget() * m_pViewport->viewTangent();
00133
00134
00135
00136 const double Ratio= ChampsVision / static_cast<double>(m_pViewport->viewVSize());
00137
00138 mappedTranslation= mappedTranslation * Ratio;
00139 m_pViewport->cameraHandle()->pan(mappedTranslation);
00140 }
00141
00142 return true;
00143 }
00144