Case a:
glLoadIdentity();
glTranslatef(0,0,-mZoom);
glRotatef(mRotation.x,1.0,0.0,0.0);
glRotatef(mRotation.y,0.0,1.0,0.0);
glTranslatef(-mPosition.x,-mPosition.y,-mPosition.z);
With case a, it works to a certain degree. What goes wrong is when i try to pan left/right after rotating it feels like the scene itself is panning. For e.g if i rotate around the Y axis by 180 degrees the panning is completely reversed. However, the camera rotates exactly as i wanted.
Case b:
glLoadIdentity();
glTranslatef(0,0,-mZoom);
glTranslatef(-mPosition.x,-mPosition.y,-mPosition.z);
glRotatef(mRotation.x,1.0,0.0,0.0);
glRotatef(mRotation.y,0.0,1.0,0.0);
With Case b: Now the panning works 100% correct but the rotating no longer rotates around the point i want it too.
What do i have to do to get it right? There is something i am just not understanding correctly.
If it helps this is the mouse press event. It's Qt but should be readable to most. The emit signals are just for the gui to display the position/rotations.
void RenderWidget::mouseMoveEvent(QMouseEvent *e)
{
const QPointF delta = e->posF() - mLastPos;
if (e->buttons() & Qt::LeftButton)
{
mRotation +=Vec3(delta.y(), delta.x(), 0) * 0.3f;
emit cameraRotationXChanged(mRotation.x);
emit cameraRotationYChanged(mRotation.y);
}
else if (e->buttons() & Qt::RightButton)
{
mPosition.x -= delta.x()/100.0f;
mPosition.y += delta.y()/100.0f;
emit cameraPositionXChanged(mPosition.x);
emit cameraPositionYChanged(mPosition.y);
}
mLastPos = e->posF();
}