Hi!
Now I got everything working except from the translation from window coordinates to image.
This is how i do it now:
Then in the mouse move method:glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef(this->size().width() / 2.0f, this->size().height() / 2.0f, 0.0f);
glTranslatef(imageOffset.x(), -imageOffset.y(), 0.0f);
glScalef(zoomFactor, zoomFactor, 0.0f);
glTranslatef(-imageWidth / 2.0f, -imageHeight / 2.0f, 0.0f);
This works fine when as long as I dont scale the image. I can move around the image in the window and it translates the coordinates.void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
QPoint pos = event->pos();
QMatrix q,t1,t2,s,t3;
t1.translate(this->size().width() / 2, this->size().height() / 2);
t2.translate(imageOffset.x(), imageOffset.y());
s.scale(zoomFactor, zoomFactor);
t3.translate(- imageWidth / 2, - imageHeight / 2);
q = t1*t2*s*t3;
QMatrix qinv = q.inverted();
QPoint im = qinv.map(pos);
qDebug() << im;
}
This is is supposed to be simple.
Bookmarks