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

SourceForge.net Logo

©2005 Laurent Ribon