added limited rotation,

2 directions do not work
This commit is contained in:
Anakin 2017-01-07 12:46:06 +01:00
parent e963b7538e
commit 8c2ca44f20
3 changed files with 52 additions and 9 deletions

View File

@ -31,6 +31,12 @@ private:
QVector2D position;
} m_mouse;
struct {
bool x = true;
bool y = true;
bool z = true;
} m_rotDirections;
QOpenGLShaderProgram m_program;
GeometryEngine *m_dataEngine;

View File

@ -126,13 +126,9 @@ void GeometryEngine::loadTexture(const char* filePath, const char* fileName)
else
img = loadTga((std::string(filePath) + std::string(fileName)).c_str(), loadSuccess);
//TODO: emit if not successfull
if (!loadSuccess)
{
QString msg = "WARNING: texture not found or corrupted: ";
msg += QString(fileName);
emit sendMessage(msg, 1);
}
emit sendMessage("WARNING: texture not found or corrupted: " + QString(fileName), 1);
// Load image to OglTexture
QOpenGLTexture* new_texture = new QOpenGLTexture(img.mirrored());
@ -206,7 +202,6 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
for (auto& it : m_drawList)
{
Q_ASSERT(!m_textures.isEmpty());
// bind the correct texture
if (it.textureIndex < m_textures.size())
m_textures.at(it.textureIndex)->bind();

View File

@ -66,8 +66,39 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
m_mouse.position = QVector2D(e->localPos());
// calculate the rotation axis and rotate
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(diff.y(), diff.x(), 0.0).normalized(), diff.length() * 0.5) * m_rotation;
if (m_rotDirections.x && m_rotDirections.y && m_rotDirections.z)
{
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(diff.y(), diff.x(), 0.0).normalized(), diff.length() * 0.5) * m_rotation;
}
else if (m_rotDirections.x && m_rotDirections.y && !m_rotDirections.z)
{
//float pitch, yaw, roll;
//m_rotation.getEulerAngles(&pitch, &yaw, &roll);
//pitch += diff.y() * 0.5;
//yaw += diff.x() * 0.5;
//std::cout << pitch << " - " << yaw << std::endl;
//m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll);
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0, 1.0, 0.0).normalized(), diff.x() * 0.5) + m_rotation;
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0).normalized(), diff.y() * 0.5) + m_rotation;
}
else if (m_rotDirections.x && !m_rotDirections.y && !m_rotDirections.z)
{
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0, 1.0, 0.0).normalized(), diff.x() * 0.5) * m_rotation;
}
else if (!m_rotDirections.x && m_rotDirections.y && !m_rotDirections.z)
{
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0).normalized(), diff.y() * 0.5) * m_rotation;
}
else if (!m_rotDirections.x && !m_rotDirections.y && m_rotDirections.z)
{
m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0, 0.0, 1.0).normalized(), diff.x() * 0.5) * m_rotation;
}
// request an update
update();
}
@ -218,5 +249,16 @@ void OglViewerWidget::resetView()
void OglViewerWidget::changeDirection(int direction)
{
switch (direction)
{
case 1:
m_rotDirections.x = !m_rotDirections.x;
break;
case 2:
m_rotDirections.y = !m_rotDirections.y;
break;
case 3:
m_rotDirections.z = !m_rotDirections.z;
break;
}
}