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 *****************************************************************************/ 00024 00025 #include "glc_abstractmanipulator.h" 00026 #include "../viewport/glc_viewport.h" 00027 #include "../maths/glc_geomtools.h" 00028 00029 #include <QtGlobal> 00030 00031 GLC_AbstractManipulator::GLC_AbstractManipulator(GLC_Viewport* pViewport) 00032 : m_pViewport(pViewport) 00033 , m_SliddingPlane() 00034 , m_PreviousPosition() 00035 , m_IsInManipulateState(false) 00036 { 00037 Q_ASSERT(NULL != m_pViewport); 00038 } 00039 00040 GLC_AbstractManipulator::GLC_AbstractManipulator(const GLC_AbstractManipulator& abstractManipulator) 00041 : m_pViewport(abstractManipulator.m_pViewport) 00042 , m_SliddingPlane(abstractManipulator.m_SliddingPlane) 00043 , m_PreviousPosition(abstractManipulator.m_PreviousPosition) 00044 , m_IsInManipulateState(abstractManipulator.m_IsInManipulateState) 00045 { 00046 00047 } 00048 00049 GLC_AbstractManipulator::~GLC_AbstractManipulator() 00050 { 00051 } 00052 00053 void GLC_AbstractManipulator::enterManipulateState(const GLC_Point3d& startPoint) 00054 { 00055 m_SliddingPlane= GLC_Plane(m_pViewport->cameraHandle()->forward().normalize(), startPoint); 00056 00057 m_PreviousPosition = startPoint; 00058 m_IsInManipulateState= true; 00059 } 00060 00061 GLC_Matrix4x4 GLC_AbstractManipulator::manipulate(const GLC_Point3d& newPoint) 00062 { 00063 Q_ASSERT(m_IsInManipulateState); 00064 00065 // Select the projection direction 00066 GLC_Vector3d projectionDirection; 00067 if (m_pViewport->useOrtho()) 00068 { 00069 projectionDirection= m_pViewport->cameraHandle()->forward().normalize(); 00070 } 00071 else 00072 { 00073 projectionDirection= (newPoint - m_pViewport->cameraHandle()->eye()); 00074 } 00075 00076 // Use concrete class to compute matrix 00077 GLC_Matrix4x4 transformation(doManipulate(newPoint, projectionDirection)); 00078 00079 return transformation; 00080 }