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

SourceForge.net Logo

©2005-2011 Laurent Ribon