Hi,
How would i rotate an object always that way i’m looking at it?
Example: dice
3
1265
4
^y
|
±>x
We are looking at 1 (so right of it is the 2, left the 5, behind 6, upside 3, downside 4)
And when i press my mouse move from left to right, i want to see the 5. When moving the mouse upside down i want the 3,…
That’s no problem this code can do it:
void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
{
if (m_mouse.left)
{
// get the difference between last press and now
QVector2D diff = QVector2D(e->localPos()) - m_mouse.position;
// update the new position
m_mouse.position = QVector2D(e->localPos());
// calculate the rotation axis and rotate
QVector3D rotationAxis = QVector3D(diff.y(), diff.x(), 0.0).normalized();
m_rotation *= QQuaternion::fromAxisAndAngle(rotationAxis * 0.75, diff.length());
// request an update
update();
}
}
But the problem is, when i rotate the model in y direction (upside down) 180° (you can see the 6 upside down) and then i move the mouse from left to right, it rotates in the opposite direction it should move.
Any help about how to fix that??