I don't know about the OpenGL specifics, but if I understand your question correctly I can help out with the mathematics:
I assume you have already selected the object, by clicking the object and thus "sending" a ray through your scene that hits your object in the anchorpoint p.
To understand the following:
Now you drag your mouse along vector t. Using the intercept theorem you can easily calculate the vector s by which p has to be translated to "keep it under the cursor":
|p| / |q| = |s| / |t|
|s| = ( |p| / |q| ) * |t|
s is parallel to t, so it is t normalized multiplicated by |s|:
s = t / |t| * |s|
s = t / |t| * ( |p| / |q| ) * |t|
s = t * ( |p| / |q| )
If you are panning, you are doing the exact same thing, just that you are not shifting p by s, but you have to translate your whole scene by -s.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…