I want to make an object defined in the modeling space to translate in viewing space. The amount of translation is controlled by clicking and dragging the mouse (varying deltaX and deltaY). And here's the code that works well: (reference https://gist.github.com/ptbrowne/2048812)
glPushMatrix();
glLoadMatrixd(cam2wld[cameraIndex].matrix());
glTranslated(deltaX, deltaY, 0);
glMultMatrixd(wld2cam[cameraIndex].matrix());
glMultMatrixd(obj2wld.matrix());
glGetDoublev(GL_MODELVIEW_MATRIX, obj2wld.matrix());
glPopMatrix();
I also want to rotate the object with respect to the camera(screen)'s x-axis, which the amount of rotation is dependent on the mouse dragging again. However, by changing from
glTranslated(deltaX, deltaY, 0);
to
glRotated(deltaX + deltaY, 1, 0, 0);
The object is translated instead. Any idea how to solve the problem? Thanks.