void GLC_Arrow::setViewDir(const GLC_Vector3d& viewDir) { if (viewDir != m_ViewDir) { m_ViewDir= GLC_Vector3d(viewDir).normalize(); GLC_Geometry::clearWireAndBoundingBox(); } }
GLC_Arrow::GLC_Arrow(const GLC_Point3d& startPoint, const GLC_Point3d& endPoint, const GLC_Vector3d& viewDir) : GLC_Geometry("Arrow", true) , m_StartPoint(startPoint) , m_EndPoint(endPoint) , m_HeadLenght((m_EndPoint - m_StartPoint).length() / 10.0) , m_HeadAngle(glc::toRadian(30.0)) , m_ViewDir(GLC_Vector3d(viewDir).normalize()) { }
QPair<GLC_Vector3d, double> GLC_Matrix4x4::rotationVectorAndAngle() const { QPair<GLC_Vector3d, double> subject(GLC_Vector3d(), 0.0); if (GLC_Matrix4x4(*this).optimise().type() != GLC_Matrix4x4::Identity) { QQuaternion quaternion= this->quaternion(); quaternion.normalize(); const double cos_angle= quaternion.scalar(); const double angle= acos(cos_angle); double sin_angle= sqrt(1.0 - cos_angle * cos_angle); if (fabs(sin_angle) < 0.0005) sin_angle= 1.0; subject.first.setX(quaternion.x() / sin_angle); subject.first.setY(quaternion.y() / sin_angle); subject.first.setZ(quaternion.z() / sin_angle); subject.second= angle * 2.0; } return subject; }
// Move the camera bool GLC_TsrMover::move(const GLC_UserInput& userInput) { if (!(userInput.normalyzeXTouchCenter() < 0.0) && !(userInput.normalyzeYTouchCenter() < 0.0)) { m_PreviousVector= GLC_Point3d(userInput.normalyzeXTouchCenter(), userInput.normalyzeYTouchCenter(), 0.0); } else { qDebug() << "Pas cool"; if (!userInput.translation().isNull()) { m_PreviousVector= GLC_Vector3d(userInput.translation().getX(), userInput.translation().getY(), 0.0) + m_PreviousVector; } } const double x= m_PreviousVector.x(); const double y= m_PreviousVector.y(); //GLC_Point3d center2= m_pViewport->unProject(x * m_pViewport->viewHSize(), y * m_pViewport->viewVSize()); //qDebug() << "touch center= " << x << " , " << y; if (!qFuzzyCompare(userInput.scaleFactor(), 0)) { GLC_Point dummy(m_pViewport->cameraHandle()->target()); m_pViewport->setDistMinAndMax(dummy.boundingBox()); GLC_Point2d nPos= m_pViewport->mapNormalyzeToOpenGLScreen(x, y); GLC_Point3d nPos3D(nPos.getX(), nPos.getY(), 1.0); GLC_Point3d projected= m_pViewport->compositionMatrix().inverted() * nPos3D; m_pViewport->cameraHandle()->zoom(userInput.scaleFactor()); m_pViewport->setDistMinAndMax(dummy.boundingBox()); GLC_Point3d projected2= m_pViewport->compositionMatrix().inverted() * nPos3D; GLC_Vector3d delta= projected - projected2; m_pViewport->cameraHandle()->translate(delta); } if (!qFuzzyCompare(userInput.rotationAngle(), 0)) { GLC_Point dummy(m_pViewport->cameraHandle()->target()); m_pViewport->setDistMinAndMax(dummy.boundingBox()); GLC_Point2d nPos= m_pViewport->mapNormalyzeToOpenGLScreen(x, y); GLC_Point3d nPos3D(nPos.getX(), nPos.getY(), 1.0); GLC_Point3d center= m_pViewport->compositionMatrix().inverted() * nPos3D; GLC_Vector3d axis= m_pViewport->cameraHandle()->forward(); m_pViewport->cameraHandle()->rotateAround(axis, userInput.rotationAngle(), center); } if (!userInput.translation().isNull()) { double transX= userInput.translation().getX() * m_pViewport->viewHSize(); double transY= userInput.translation().getY() * m_pViewport->viewVSize(); GLC_Vector3d mappedTranslation(-transX, -transY, 0.0); // Compute the length of camera's field of view const double ChampsVision = m_pViewport->cameraHandle()->distEyeTarget() * m_pViewport->viewTangent(); // the side of camera's square is mapped on Vertical length of window // Ratio OpenGL/Pixel = dimend GL / dimens Pixel const double Ratio= ChampsVision / static_cast<double>(m_pViewport->viewVSize()); mappedTranslation= mappedTranslation * Ratio; m_pViewport->cameraHandle()->pan(mappedTranslation); } return true; }