Mathematics behind 3D point dragging

In several answers to questions related to dragging a point in 3D (for example: How can I select one out of several Graphics3D objects and change its coordinates in Mathematica?, or How can locators be added to the points on a 3D grid?), the instruction

mp := MousePosition["Graphics3DBoxIntercepts"];
(*...*)
"MouseDragged" :>
((pos1 = #[] + Projection[pos0 - #[], #[] - #[]]) &@mp)


is used. I have used this code without problems, but to advance in more complex situations, I need to know what the math behind this instruction is. Can someone give me an idea or a reference to some reading?. Thank you.

Code sample

DynamicModule[{init, cube, bb, restrict, generate},
init = {{0, 0, 0}, {2, 1, 0}};
bb = {{-3, 3}, {-3, 3}, {-3, 3}};
cube[pt_, scale_] :=
Translate[Scale[Cuboid[{-1/2, -1/2, -1/2}, {1/2, 1/2, 1/2}], scale], pt];
restrict[pt_] := MapThread[Min[Max[#1[], #2], #1[]] &, {bb, pt}];
generate[pos_, scale_] := Module[{mp, pos0, pos1, pos2},
mp := MousePosition["Graphics3DBoxIntercepts"];
pos1 = pos;
EventHandler[
Dynamic[{cube[pos1, scale]}, ImageSize -> Tiny],
{"MouseDown" :> (pos0 = LeastSquares[Transpose[mp], pos1].mp),
"MouseDragged" :>
((pos1 = #[] + Projection[pos0 - #[], #[] - #[]]) &@mp),
"MouseUp" :> (pos1 = restrict[pos1])}]];

Graphics3D[generate[#, 1] & /@ init, PlotRange -> bb, PlotRangePadding -> .5]
] 