65 lines
1.2 KiB
C++
65 lines
1.2 KiB
C++
|
#include "..\Header\OrbitCamera.h"
|
||
|
#include <QVector2D>
|
||
|
#include <qmath.h>
|
||
|
#include <iostream>
|
||
|
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////
|
||
|
// constructor/destructor
|
||
|
|
||
|
OrbitCamera::OrbitCamera()
|
||
|
{
|
||
|
resetView();
|
||
|
}
|
||
|
|
||
|
OrbitCamera::~OrbitCamera()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
/////////////////////////////////////////////////////////////////////////
|
||
|
// functions
|
||
|
|
||
|
void OrbitCamera::rotateAction(QVector2D diff)
|
||
|
{
|
||
|
//m_phi += diff.x() * 0.01;
|
||
|
m_theta -= diff.y() * 0.01;
|
||
|
|
||
|
m_theta = qMax(qMin(M_PI_2, m_theta), -M_PI_2);
|
||
|
|
||
|
}
|
||
|
|
||
|
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();
|
||
|
|
||
|
QVector3D tmpPosition;
|
||
|
tmpPosition.setX(qSin(m_theta) * qCos(m_phi));
|
||
|
tmpPosition.setY(qSin(m_theta) * qSin(m_phi));
|
||
|
tmpPosition.setZ(qCos(m_theta));
|
||
|
|
||
|
std::cout << m_theta << ":" << tmpPosition.x() << "-" << tmpPosition.y() << "-" << tmpPosition.z() << std::endl;
|
||
|
|
||
|
m_matrix.lookAt(m_roh * tmpPosition, QVector3D(0, 0, 0), QVector3D(0, 1, 0));
|
||
|
}
|
||
|
|
||
|
void OrbitCamera::resetView()
|
||
|
{
|
||
|
m_roh = 4;
|
||
|
m_phi = - M_PI_2;
|
||
|
m_theta = 0;
|
||
|
CameraInterface::resetView();
|
||
|
}
|