glc_turntablemover.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  Copyright (C) 2009 Laurent Bauer
00006  Version 2.0.0 Beta 1, packaged on April 2010.
00007 
00008  http://glc-lib.sourceforge.net
00009 
00010  GLC-lib is free software; you can redistribute it and/or modify
00011  it under the terms of the GNU General Public License as published by
00012  the Free Software Foundation; either version 2 of the License, or
00013  (at your option) any later version.
00014 
00015  GLC-lib is distributed in the hope that it will be useful,
00016  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  GNU General Public License for more details.
00019 
00020  You should have received a copy of the GNU General Public License
00021  along with GLC-lib; if not, write to the Free Software
00022  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00023 
00024  *****************************************************************************/
00025 
00026 #include "glc_turntablemover.h"
00027 #include "glc_viewport.h"
00028 
00029 // Default constructor
00030 GLC_TurnTableMover::GLC_TurnTableMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList)
00031 : GLC_Mover(pViewport, repsList)
00032 , m_Sign(1.0)
00033 {
00034 
00035 }
00036 
00037 
00038 // Copy constructor
00039 GLC_TurnTableMover::GLC_TurnTableMover(const GLC_TurnTableMover& mover)
00040 : GLC_Mover(mover)
00041 , m_Sign(mover.m_Sign)
00042 {
00043 }
00044 
00045 
00046 GLC_TurnTableMover::~GLC_TurnTableMover()
00047 {
00048 }
00049 
00050 
00052 // Get Functions
00054 
00055 // Return a clone of the mover
00056 GLC_Mover* GLC_TurnTableMover::clone() const
00057 {
00058         return new GLC_TurnTableMover(*this);
00059 }
00060 
00061 
00063 // Set Functions
00065 
00066 // Initialized the mover
00067 void GLC_TurnTableMover::init(QMouseEvent * e)
00068 {
00069         GLC_Mover::m_PreviousVector.setVect(static_cast<double>(e->x()), static_cast<double>(e->y()),0.0);
00070         GLC_Camera* pCamera= GLC_Mover::m_pViewport->cameraHandle();
00071         // Calculate angle sign
00072         m_Sign= pCamera->defaultUpVector() * pCamera->upVector();
00073         if (m_Sign == 0)
00074         {
00075                 m_Sign= 1;
00076         }
00077         else
00078         {
00079                 m_Sign= m_Sign / fabs(m_Sign);
00080         }
00081 
00082         pCamera->setUpCam(pCamera->defaultUpVector() * m_Sign);
00083 }
00084 
00085 
00086 bool GLC_TurnTableMover::move(QMouseEvent * e)
00087 {
00088         GLC_Camera* pCamera= GLC_Mover::m_pViewport->cameraHandle();
00089         // Turn table rotation
00090         const double rotSpeed= 2.3;
00091         const double width= static_cast<double> ( GLC_Mover::m_pViewport->viewVSize() );
00092         const double height= static_cast<double> ( GLC_Mover::m_pViewport->viewHSize() );
00093 
00094         const double alpha = -((static_cast<double>(e->x()) - GLC_Mover::m_PreviousVector.x()) / width) * rotSpeed;
00095         const double beta = ((static_cast<double>(e->y()) - GLC_Mover::m_PreviousVector.y()) / height) * rotSpeed;
00096 
00097         // Rotation around the screen vertical axis
00098         pCamera->rotateAroundTarget(pCamera->defaultUpVector(), alpha * m_Sign);
00099 
00100         // Rotation around the screen horizontal axis
00101         GLC_Vector3d incidentVector= -pCamera->forward();
00102         GLC_Vector3d rightVector= incidentVector ^ pCamera->upVector();
00103         if (!rightVector.isNull())
00104         {
00105                 pCamera->rotateAroundTarget(rightVector, beta);
00106         }
00107 
00108         m_PreviousVector.setVect(static_cast<double>(e->x()), static_cast<double>(e->y()), 0.0);
00109 
00110         return true;
00111 }

SourceForge.net Logo

©2005 Laurent Ribon