parent
e963b7538e
commit
8c2ca44f20
|
@ -31,6 +31,12 @@ private:
|
||||||
QVector2D position;
|
QVector2D position;
|
||||||
} m_mouse;
|
} m_mouse;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
bool x = true;
|
||||||
|
bool y = true;
|
||||||
|
bool z = true;
|
||||||
|
} m_rotDirections;
|
||||||
|
|
||||||
QOpenGLShaderProgram m_program;
|
QOpenGLShaderProgram m_program;
|
||||||
GeometryEngine *m_dataEngine;
|
GeometryEngine *m_dataEngine;
|
||||||
|
|
||||||
|
|
|
@ -126,13 +126,9 @@ void GeometryEngine::loadTexture(const char* filePath, const char* fileName)
|
||||||
else
|
else
|
||||||
img = loadTga((std::string(filePath) + std::string(fileName)).c_str(), loadSuccess);
|
img = loadTga((std::string(filePath) + std::string(fileName)).c_str(), loadSuccess);
|
||||||
|
|
||||||
//TODO: emit if not successfull
|
|
||||||
if (!loadSuccess)
|
if (!loadSuccess)
|
||||||
{
|
emit sendMessage("WARNING: texture not found or corrupted: " + QString(fileName), 1);
|
||||||
QString msg = "WARNING: texture not found or corrupted: ";
|
|
||||||
msg += QString(fileName);
|
|
||||||
emit sendMessage(msg, 1);
|
|
||||||
}
|
|
||||||
// Load image to OglTexture
|
// Load image to OglTexture
|
||||||
QOpenGLTexture* new_texture = new QOpenGLTexture(img.mirrored());
|
QOpenGLTexture* new_texture = new QOpenGLTexture(img.mirrored());
|
||||||
|
|
||||||
|
@ -206,7 +202,6 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
|
||||||
|
|
||||||
for (auto& it : m_drawList)
|
for (auto& it : m_drawList)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_textures.isEmpty());
|
|
||||||
// bind the correct texture
|
// bind the correct texture
|
||||||
if (it.textureIndex < m_textures.size())
|
if (it.textureIndex < m_textures.size())
|
||||||
m_textures.at(it.textureIndex)->bind();
|
m_textures.at(it.textureIndex)->bind();
|
||||||
|
|
|
@ -66,8 +66,39 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
|
||||||
m_mouse.position = QVector2D(e->localPos());
|
m_mouse.position = QVector2D(e->localPos());
|
||||||
|
|
||||||
// calculate the rotation axis and rotate
|
// 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
|
// request an update
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -218,5 +249,16 @@ void OglViewerWidget::resetView()
|
||||||
|
|
||||||
void OglViewerWidget::changeDirection(int direction)
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue