glc_settargetmover.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_settargetmover.h"
00024 #include "glc_viewport.h"
00025 #include "glc_openglexception.h"
00026 
00027 // Default constructor
00028 GLC_SetTargetMover::GLC_SetTargetMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList)
00029 : GLC_Mover(pViewport, repsList)
00030 {
00031 
00032 
00033 }
00034 
00035 // Copy constructor
00036 GLC_SetTargetMover::GLC_SetTargetMover(const GLC_SetTargetMover& mover)
00037 : GLC_Mover(mover)
00038 {
00039 
00040 
00041 }
00042 
00043 GLC_SetTargetMover::~GLC_SetTargetMover()
00044 {
00045 
00046 }
00047 
00049 // Get Functions
00051 
00052 // Return a clone of the mover
00053 GLC_Mover* GLC_SetTargetMover::clone() const
00054 {
00055         return new GLC_SetTargetMover(*this);
00056 }
00057 
00059 // Set Functions
00061 
00062 // Initialized the mover
00063 void GLC_SetTargetMover::init(const GLC_UserInput& userInput)
00064 {
00065         // Z Buffer component of selected point between 0 and 1
00066         GLfloat Depth;
00067         // read selected point
00068         glReadPixels(userInput.x(), m_pViewport->viewVSize() - userInput.y() , 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &Depth);
00069 
00070         // Test if there is geometry under picking point
00071         if (!qFuzzyCompare(Depth, 1.0f))
00072         {       // Geometry find -> Update camera's target position
00073                 const GLC_Point3d target(m_pViewport->unProject(userInput.x(), userInput.y()));
00074                 m_pViewport->cameraHandle()->setTargetCam(target);
00075         }
00076         else
00077         {       // Geometry not find -> panning
00078 
00079                 const GLC_Point3d curPos(m_pViewport->mapPosMouse(userInput.x(), userInput.y()));
00080                 const GLC_Point3d prevPos(m_pViewport->mapPosMouse(m_pViewport->viewHSize() / 2, m_pViewport->viewVSize() / 2));
00081                 const GLC_Vector3d VectPan(curPos - prevPos);   // panning vector
00082                 // pan camera
00083                 m_pViewport->cameraHandle()->pan(VectPan);
00084         }
00085 }

SourceForge.net Logo

©2005-2011 Laurent Ribon