glc_pullmanipulator.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003  This file is part of the GLC-lib library.
00004  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
00005  http://glc-lib.sourceforge.net
00006 
00007  GLC-lib is free software; you can redistribute it and/or modify
00008  it under the terms of the GNU Lesser General Public License as published by
00009  the Free Software Foundation; either version 3 of the License, or
00010  (at your option) any later version.
00011 
00012  GLC-lib is distributed in the hope that it will be useful,
00013  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  GNU Lesser General Public License for more details.
00016 
00017  You should have received a copy of the GNU Lesser General Public License
00018  along with GLC-lib; if not, write to the Free Software
00019  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021  *****************************************************************************/
00023 
00024 #include "glc_pullmanipulator.h"
00025 #include "../maths/glc_line3d.h"
00026 #include "../maths/glc_geomtools.h"
00027 #include "../viewport/glc_viewport.h"
00028 
00029 #include <QtGlobal>
00030 
00031 GLC_PullManipulator::GLC_PullManipulator(GLC_Viewport* pViewport, const GLC_Vector3d& pullDirection)
00032 : GLC_AbstractManipulator(pViewport)
00033 , m_PullDirection(pullDirection)
00034 {
00035 
00036 }
00037 
00038 GLC_PullManipulator::GLC_PullManipulator(const GLC_PullManipulator& pullManipulator)
00039 : GLC_AbstractManipulator(pullManipulator)
00040 , m_PullDirection(pullManipulator.m_PullDirection)
00041 {
00042 
00043 }
00044 
00045 GLC_PullManipulator::~GLC_PullManipulator()
00046 {
00047 
00048 }
00049 
00050 GLC_AbstractManipulator* GLC_PullManipulator::clone() const
00051 {
00052         return new GLC_PullManipulator(*this);
00053 }
00054 
00055 void GLC_PullManipulator::setPullingDirection(const GLC_Vector3d& pullingDirection)
00056 {
00057         Q_ASSERT(!GLC_AbstractManipulator::isInManipulateState());
00058         m_PullDirection= pullingDirection;
00059 }
00060 
00061 GLC_Matrix4x4 GLC_PullManipulator::doManipulate(const GLC_Point3d& newPoint, const GLC_Vector3d& projectionDirection)
00062 {
00063         // Project the given point on the sliding plane with the given direction
00064         GLC_Point3d projectedPoint;
00065         GLC_Line3d projectionLine(newPoint, projectionDirection);
00066         glc::lineIntersectPlane(projectionLine, GLC_AbstractManipulator::m_SliddingPlane, &projectedPoint);
00067 
00068         // Project the point on the pulling direction
00069         projectedPoint= glc::project(projectedPoint, GLC_Line3d(GLC_AbstractManipulator::previousPosition(), m_PullDirection));
00070 
00071         // Compute the translation matrix
00072         GLC_Matrix4x4 translationMatrix(projectedPoint - GLC_AbstractManipulator::m_PreviousPosition);
00073 
00074         // Update previous position to this position
00075         GLC_AbstractManipulator::m_PreviousPosition= projectedPoint;
00076         return translationMatrix;
00077 }

SourceForge.net Logo

©2005-2011 Laurent Ribon