Clicking and dragging to translate an object

In my 3D perspective view, I’m drawing a (rotated) surface, and I want the user to be able to zoom in and out, and click and drag the surface to translate it (one-to-one movement with the mouse). The zoom is done by holding a key and using the mouse wheel, and this is simply translating down the z-axis (I specify my camera with gluLookAt, initially pointing down negative z-axis, and all rotations are done in local coordinate frame).

If I want to simply click and translate, shouldn’t it be as simple as: 1) store click x, y, z obtained by gluUnproject in the mouse down event, 2) add the delta x, y, z from the “click” in the mouse move event, and 3) add that to my cumulative glTranslate? Keep in mind that the scene can be zoomed or rotated, which is why I thought I needed to gluUnproject.

It seems like a simple concept, and I remember coding it for a (now lost) program, but I don’t have a ton of time to work on this smaller detail. Any help is appreciated!

when you mean “translate”, you mean in the xy plane, in screen space , in the xz plane ?

In general, the user should be able to rotate the model by clicking and dragging (done, using a trackball implementation), zoom by using the mouse wheel (done by glTranslate with some z-component), and click and drag to translate the model. The model, when translated, should appear the same scale and same rotation, but translated in screen space.

This is done in all sorts of graphics software, but my implementation did not work, and my brain is mush right now trying to find my theoretical mistake. :slight_smile: