Commit 8c2ca44f authored by Anakin's avatar Anakin

added limited rotation,

2 directions do not work
parent e963b753
......@@ -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;
......
......@@ -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();
......
......@@ -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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment