glc_turntablemover.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "glc_turntablemover.h"
00027 #include "glc_viewport.h"
00028
00029
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
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
00054
00055
00056 GLC_Mover* GLC_TurnTableMover::clone() const
00057 {
00058 return new GLC_TurnTableMover(*this);
00059 }
00060
00061
00063
00065
00066
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
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
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
00098 pCamera->rotateAroundTarget(pCamera->defaultUpVector(), alpha * m_Sign);
00099
00100
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 }