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  Version 2.0.0 Beta 1, packaged on April 2010.
00006 
00007  http://glc-lib.sourceforge.net
00008 
00009  GLC-lib is free software; you can redistribute it and/or modify
00010  it under the terms of the GNU General Public License as published by
00011  the Free Software Foundation; either version 2 of the License, or
00012  (at your option) any later version.
00013 
00014  GLC-lib is distributed in the hope that it will be useful,
00015  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  GNU General Public License for more details.
00018 
00019  You should have received a copy of the GNU General Public License
00020  along with GLC-lib; if not, write to the Free Software
00021  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00022 
00023  *****************************************************************************/
00025 
00026 #include "glc_pullmanipulator.h"
00027 #include "../maths/glc_line3d.h"
00028 #include "../maths/glc_geomtools.h"
00029 #include "../viewport/glc_viewport.h"
00030 
00031 #include <QtGlobal>
00032 
00033 GLC_PullManipulator::GLC_PullManipulator(GLC_Viewport* pViewport, const GLC_Vector3d& pullDirection)
00034 : GLC_AbstractManipulator(pViewport)
00035 , m_PullDirection(pullDirection)
00036 {
00037 
00038 }
00039 
00040 GLC_PullManipulator::GLC_PullManipulator(const GLC_PullManipulator& pullManipulator)
00041 : GLC_AbstractManipulator(pullManipulator)
00042 , m_PullDirection(pullManipulator.m_PullDirection)
00043 {
00044 
00045 }
00046 
00047 GLC_PullManipulator::~GLC_PullManipulator()
00048 {
00049 
00050 }
00051 
00052 GLC_AbstractManipulator* GLC_PullManipulator::clone() const
00053 {
00054         return new GLC_PullManipulator(*this);
00055 }
00056 
00057 void GLC_PullManipulator::setPullingDirection(const GLC_Vector3d& pullingDirection)
00058 {
00059         Q_ASSERT(!GLC_AbstractManipulator::isInManipulateState());
00060         m_PullDirection= pullingDirection;
00061 }
00062 
00063 GLC_Matrix4x4 GLC_PullManipulator::doManipulate(const GLC_Point3d& newPoint, const GLC_Vector3d& projectionDirection)
00064 {
00065         // Project the given point on the sliding plane with the given direction
00066         GLC_Point3d projectedPoint;
00067         GLC_Line3d projectionLine(newPoint, projectionDirection);
00068         glc::lineIntersectPlane(projectionLine, GLC_AbstractManipulator::m_SliddingPlane, &projectedPoint);
00069 
00070         // Construct the plane throw previous position and pull direction oriented with camera side vector
00071         GLC_Vector3d projNormal= (GLC_AbstractManipulator::m_pViewport->cameraHandle()->sideVector() ^ m_PullDirection).normalize();
00072         GLC_Plane projPlane(projNormal, GLC_AbstractManipulator::m_PreviousPosition);
00073 
00074         // Project the point on the previous computed plane
00075         glc::lineIntersectPlane(projectionLine, projPlane, &projectedPoint);
00076 
00077         // Project the point on the pulling direction
00078         projectedPoint= glc::project(projectedPoint, GLC_Line3d(GLC_AbstractManipulator::previousPosition(), m_PullDirection));
00079 
00080         // Compute the translation matrix
00081         GLC_Matrix4x4 translationMatrix(projectedPoint - GLC_AbstractManipulator::m_PreviousPosition);
00082 
00083         // Update previous position to this position
00084         GLC_AbstractManipulator::m_PreviousPosition= projectedPoint;
00085         return translationMatrix;
00086 }

SourceForge.net Logo

©2005 Laurent Ribon