PDA

View Full Version : Translate + Rotate problem.



Tivin
09-20-2009, 07:47 AM
Hi,

I want to rotate my object around the current center of view.

I have shifting functionality on clicked mouse move:


void GLWidget::mouseMoveEvent(QMouseEvent* event)
{
double dCoeffX = 1.0 / ... //some calculations;
double dCoeffY = 1.0 / ... //some calculations;

double dXDifference = m_posMouse.x() - event->x();
double dYDifference = m_posMouse.y() - event->y();

m_dOffsetX += dXDifference * dCoeffX;
m_dOffsetY += -dYDifference * dCoeffY;

m_posMouse = event->pos();
}


So, the following code rotates around the center of object:


glMatrixMode(GL_MODELVIEW);

glTranslated(m_dOffsetX, m_dOffsetY, 0);
glRotated(-m_iXAngle, 1.0, 0.0, 0.0);
glRotated(-m_iZAngle, 0.0, 0.0, 1.0);


This code rotates around the current view center:


glMatrixMode(GL_MODELVIEW);

glRotated(-m_iXAngle, 1.0, 0.0, 0.0);
glRotated(-m_iZAngle, 0.0, 0.0, 1.0);
glTranslated(m_dOffsetX, m_dOffsetY, 0);


But after that if I move clicked mouse (i.e. shifting) picture becomes broken:

Rotated before move:
http://www.offshoresoft.de/Kontakt/untitled.jpg

Rotated after move:
http://www.offshoresoft.de/Kontakt/untitled1.jpg

Who can help me ?
Thanks in advance..

Tivin
09-20-2009, 02:17 PM
The problem is solved, thanks.
Topic can be closed.

Khronos_webmaster
09-21-2009, 01:34 PM
Would you be able to post your solution here for others?

Thanks.