glc_rotationmanipulator.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00056 GLC_Point3d projectedPoint;
00057 GLC_Line3d projectionLine1(GLC_AbstractManipulator::m_PreviousPosition, projectionDirection);
00058 GLC_Line3d projectionLine(newPoint, projectionDirection);
00059
00060
00061 const GLC_Point3d origine(m_RotationLine.startingPoint());
00062 GLC_Plane rotationPlane(m_RotationLine.direction(), origine);
00063
00064 glc::lineIntersectPlane(projectionLine1, rotationPlane, &(GLC_AbstractManipulator::m_PreviousPosition));
00065 glc::lineIntersectPlane(projectionLine, rotationPlane, &projectedPoint);
00066
00067
00068 GLC_Vector3d vector1((GLC_AbstractManipulator::m_PreviousPosition - origine).normalize());
00069 GLC_Vector3d vector2((projectedPoint - origine).normalize());
00070
00071
00072 GLC_AbstractManipulator::m_PreviousPosition= projectedPoint;
00073
00074
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 }