GLC_lib  2.5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
glc_rotationmanipulator.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 
3  This file is part of the GLC-lib library.
4  Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net)
5  http://glc-lib.sourceforge.net
6 
7  GLC-lib is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation; either version 3 of the License, or
10  (at your option) any later version.
11 
12  GLC-lib is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with GLC-lib; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 
21  *****************************************************************************/
23 
25 #include "../maths/glc_geomtools.h"
26 
28 : GLC_AbstractManipulator(pViewport)
29 , m_RotationLine(rotationLine)
30 {
31 
32 }
33 
35 : GLC_AbstractManipulator(rotationmanipulator)
36 , m_RotationLine(rotationmanipulator.m_RotationLine)
37 {
38 
39 }
40 
42 {
43 
44 }
45 
47 {
48  return new GLC_RotationManipulator(*this);
49 }
50 
52 {
53  // Project the given point on the sliding plane with the given direction
54  GLC_Point3d projectedPoint;
55  GLC_Line3d projectionLine1(GLC_AbstractManipulator::m_PreviousPosition, projectionDirection);
56  GLC_Line3d projectionLine(newPoint, projectionDirection);
57 
58  // create the rotation plane
59  const GLC_Point3d origine(m_RotationLine.startingPoint());
60  GLC_Plane rotationPlane(m_RotationLine.direction(), origine);
61  // Project the point on the previous computed plane
62  glc::lineIntersectPlane(projectionLine1, rotationPlane, &(GLC_AbstractManipulator::m_PreviousPosition));
63  glc::lineIntersectPlane(projectionLine, rotationPlane, &projectedPoint);
64 
65  // Compute the the to vector
67  GLC_Vector3d vector2((projectedPoint - origine).normalize());
68 
69  // Update previous position to this position
71 
72  // Return the rotation matrix
73  const GLC_Matrix4x4 trans1(-origine);
74  const GLC_Matrix4x4 trans2(origine);
75  const GLC_Matrix4x4 rotation(vector1, vector2);
76 
77  return (trans2 * rotation * trans1);
78 
79 }

©2005-2013 Laurent Ribon