Moving object in 3D space

I have developed a small opengl application that allows to pick an object in the viewport. I’d like to move such object in 3D space, dragging it around with the mouse.
In the first image (picked.jpg), I just picked the object at 0,0,-10; when I move it around, the object z-depth returned by glUnProject is going to the end of the far plane (see moved.jpg), while I’d like my object to keep the same z-depth.
Any idea how could I solve this?
Thanks

Check these two projects here:

Direct link: http://www.spacesimulator.net/wiki/images/SimplePicking.zip
Direct link: http://www.spacesimulator.net/wiki/images/SimplePickingSelectionBuffer.zip

which do something similar to what you are doing.

Thanks

Thanks, I’m going to check those!