SWBF2-Classic-Msh-Viewer/QtMeshViewer/Source/OrbitCamera.cpp

70 lines
1.2 KiB
C++
Raw Permalink Normal View History

#include "..\Header\OrbitCamera.h"
#include <QVector2D>
#include <qmath.h>
#include <iostream>
/////////////////////////////////////////////////////////////////////////
// constructor/destructor
OrbitCamera::OrbitCamera()
{
resetView();
}
OrbitCamera::~OrbitCamera()
{
}
/////////////////////////////////////////////////////////////////////////
// functions
void OrbitCamera::rotateAction(QVector2D diff)
{
2017-02-03 14:54:45 +00:00
m_phi -= diff.x() * 0.01;
m_theta -= diff.y() * 0.01;
2017-02-05 11:34:24 +00:00
//m_theta = qMax(qMin(M_PI - 0.0001, m_theta), 0.0001);
}
void OrbitCamera::moveAction(QVector2D diff)
{
}
void OrbitCamera::wheelAction(double value)
{
m_roh -= m_zSpeed * value / 240;
m_roh = qMax(m_roh, 0.0);
}
void OrbitCamera::recalculateMatrix()
{
m_matrix = QMatrix4x4();
2017-02-05 11:34:24 +00:00
// different coordinate (spherical -> world) X->Z | Y->X | Z->Y
QVector3D tmpPosition(
qSin(m_theta) * qSin(m_phi),
qCos(m_theta),
qSin(m_theta) * qCos(m_phi)
);
2017-02-05 11:34:24 +00:00
QVector3D tmpRight(
qSin(m_phi - M_PI_2),
0,
qCos(m_phi - M_PI_2)
);
m_matrix.lookAt(m_roh * tmpPosition, QVector3D(0,0,0), QVector3D::crossProduct(tmpRight, tmpPosition));
}
void OrbitCamera::resetView()
{
m_roh = 4;
2017-02-05 11:34:24 +00:00
m_phi = 0;
2017-02-03 14:54:45 +00:00
m_theta = M_PI_2;
CameraInterface::resetView();
}