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 #include "glc_turntablemover.h"
00025 #include "glc_viewport.h"
00026
00027
00028 GLC_TurnTableMover::GLC_TurnTableMover(GLC_Viewport* pViewport, const QList<GLC_RepMover*>& repsList)
00029 : GLC_Mover(pViewport, repsList)
00030 , m_Sign(1.0)
00031 {
00032
00033 }
00034
00035
00036
00037 GLC_TurnTableMover::GLC_TurnTableMover(const GLC_TurnTableMover& mover)
00038 : GLC_Mover(mover)
00039 , m_Sign(mover.m_Sign)
00040 {
00041 }
00042
00043
00044 GLC_TurnTableMover::~GLC_TurnTableMover()
00045 {
00046 }
00047
00048
00050
00052
00053
00054 GLC_Mover* GLC_TurnTableMover::clone() const
00055 {
00056 return new GLC_TurnTableMover(*this);
00057 }
00058
00059
00061
00063
00064
00065 void GLC_TurnTableMover::init(const GLC_UserInput& userInput)
00066 {
00067 GLC_Mover::m_PreviousVector.setVect(static_cast<double>(userInput.x()), static_cast<double>(userInput.y()),0.0);
00068 GLC_Camera* pCamera= GLC_Mover::m_pViewport->cameraHandle();
00069
00070 m_Sign= pCamera->defaultUpVector() * pCamera->upVector();
00071 if (m_Sign == 0)
00072 {
00073 m_Sign= 1;
00074 }
00075 else
00076 {
00077 m_Sign= m_Sign / fabs(m_Sign);
00078 }
00079
00080 pCamera->setUpCam(pCamera->defaultUpVector() * m_Sign);
00081 }
00082
00083
00084 bool GLC_TurnTableMover::move(const GLC_UserInput& userInput)
00085 {
00086 GLC_Camera* pCamera= GLC_Mover::m_pViewport->cameraHandle();
00087
00088 const double rotSpeed= 2.3;
00089 const double width= static_cast<double> ( GLC_Mover::m_pViewport->viewVSize() );
00090 const double height= static_cast<double> ( GLC_Mover::m_pViewport->viewHSize() );
00091
00092 const double alpha = -((static_cast<double>(userInput.x()) - GLC_Mover::m_PreviousVector.x()) / width) * rotSpeed;
00093 const double beta = ((static_cast<double>(userInput.y()) - GLC_Mover::m_PreviousVector.y()) / height) * rotSpeed;
00094
00095
00096 pCamera->rotateAroundTarget(pCamera->defaultUpVector(), alpha * m_Sign);
00097
00098
00099 GLC_Vector3d incidentVector= -pCamera->forward();
00100 GLC_Vector3d rightVector= incidentVector ^ pCamera->upVector();
00101 if (!rightVector.isNull())
00102 {
00103 pCamera->rotateAroundTarget(rightVector, beta);
00104 }
00105
00106 m_PreviousVector.setVect(static_cast<double>(userInput.x()), static_cast<double>(userInput.y()), 0.0);
00107
00108 return true;
00109 }