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

SourceForge.net Logo

©2005 Laurent Ribon