glc_rotationmanipulator.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_rotationmanipulator.h"
00025 #include "../maths/glc_geomtools.h"
00026 
00027 GLC_RotationManipulator::GLC_RotationManipulator(GLC_Viewport* pViewport, const GLC_Line3d& rotationLine)
00028 : GLC_AbstractManipulator(pViewport)
00029 , m_RotationLine(rotationLine)
00030 {
00031 
00032 }
00033 
00034 GLC_RotationManipulator::GLC_RotationManipulator(const GLC_RotationManipulator& rotationmanipulator)
00035 : GLC_AbstractManipulator(rotationmanipulator)
00036 , m_RotationLine(rotationmanipulator.m_RotationLine)
00037 {
00038 
00039 }
00040 
00041 GLC_RotationManipulator::~GLC_RotationManipulator()
00042 {
00043 
00044 }
00045 
00046 GLC_AbstractManipulator* GLC_RotationManipulator::clone() const
00047 {
00048         return new GLC_RotationManipulator(*this);
00049 }
00050 
00051 GLC_Matrix4x4 GLC_RotationManipulator::doManipulate(const GLC_Point3d& newPoint, const GLC_Vector3d& projectionDirection)
00052 {
00053         // Project the given point on the sliding plane with the given direction
00054         GLC_Point3d projectedPoint;
00055         GLC_Line3d projectionLine1(GLC_AbstractManipulator::m_PreviousPosition, projectionDirection);
00056         GLC_Line3d projectionLine(newPoint, projectionDirection);
00057 
00058         // create the rotation plane
00059         const GLC_Point3d origine(m_RotationLine.startingPoint());
00060         GLC_Plane rotationPlane(m_RotationLine.direction(), origine);
00061         // Project the point on the previous computed plane
00062         glc::lineIntersectPlane(projectionLine1, rotationPlane, &(GLC_AbstractManipulator::m_PreviousPosition));
00063         glc::lineIntersectPlane(projectionLine, rotationPlane, &projectedPoint);
00064 
00065         // Compute the the to vector
00066         GLC_Vector3d vector1((GLC_AbstractManipulator::m_PreviousPosition - origine).normalize());
00067         GLC_Vector3d vector2((projectedPoint - origine).normalize());
00068 
00069         // Update previous position to this position
00070         GLC_AbstractManipulator::m_PreviousPosition= projectedPoint;
00071 
00072         // Return the rotation matrix
00073         const GLC_Matrix4x4 trans1(-origine);
00074         const GLC_Matrix4x4 trans2(origine);
00075         const GLC_Matrix4x4 rotation(vector1, vector2);
00076 
00077         return (trans2 * rotation * trans1);
00078 
00079 }

SourceForge.net Logo

©2005-2011 Laurent Ribon